Add User Partner and Product
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Site struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
||||
Name string `gorm:"type:varchar(255);not null;column:name"`
|
||||
PartnerID int64 `gorm:"type:int;column:partner_id"`
|
||||
Image string `gorm:"type:varchar;column:image"`
|
||||
Address string `gorm:"type:varchar;column:address"`
|
||||
LocationLink string `gorm:"type:varchar;column:location_link"`
|
||||
Description string `gorm:"type:varchar;column:description"`
|
||||
Highlight string `gorm:"type:varchar;column:highlight"`
|
||||
ContactPerson string `gorm:"type:varchar;column:contact_person"`
|
||||
TnC string `gorm:"type:varchar;column:tnc"`
|
||||
AdditionalInfo string `gorm:"type:varchar;column:additional_info"`
|
||||
Status string `gorm:"type:varchar;column:status"`
|
||||
IsSeasonTicket bool `gorm:"type:bool;column:is_season_ticket"`
|
||||
IsDiscountActive bool `gorm:"type:bool;column:is_discount_active"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at"`
|
||||
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
||||
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
||||
Products []Product `gorm:"foreignKey:SiteID;constraint:OnDelete:CASCADE;"`
|
||||
}
|
||||
|
||||
type SiteSearch struct {
|
||||
Search string
|
||||
Name string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type SiteList []*SiteDB
|
||||
|
||||
type SiteDB struct {
|
||||
Site
|
||||
}
|
||||
|
||||
func (s *Site) ToSiteDB() *SiteDB {
|
||||
return &SiteDB{
|
||||
Site: *s,
|
||||
}
|
||||
}
|
||||
|
||||
func (SiteDB) TableName() string {
|
||||
return "sites"
|
||||
}
|
||||
|
||||
func (e *SiteDB) ToSite() *Site {
|
||||
return &Site{
|
||||
ID: e.ID,
|
||||
Name: e.Name,
|
||||
PartnerID: e.PartnerID,
|
||||
Image: e.Image,
|
||||
Address: e.Address,
|
||||
LocationLink: e.LocationLink,
|
||||
Description: e.Description,
|
||||
Highlight: e.Highlight,
|
||||
ContactPerson: e.ContactPerson,
|
||||
TnC: e.TnC,
|
||||
AdditionalInfo: e.AdditionalInfo,
|
||||
Status: e.Status,
|
||||
IsSeasonTicket: e.IsSeasonTicket,
|
||||
IsDiscountActive: e.IsDiscountActive,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
DeletedAt: e.DeletedAt,
|
||||
CreatedBy: e.CreatedBy,
|
||||
UpdatedBy: e.UpdatedBy,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SiteList) ToSiteList() []*Site {
|
||||
var sites []*Site
|
||||
for _, site := range *s {
|
||||
sites = append(sites, site.ToSite())
|
||||
}
|
||||
return sites
|
||||
}
|
||||
|
||||
func (o *SiteDB) ToUpdatedSite(updatedBy int64, req Site) {
|
||||
o.UpdatedBy = updatedBy
|
||||
|
||||
if req.Name != "" {
|
||||
o.Name = req.Name
|
||||
}
|
||||
|
||||
if req.PartnerID != 0 {
|
||||
o.PartnerID = req.PartnerID
|
||||
}
|
||||
|
||||
if req.Image != "" {
|
||||
o.Image = req.Image
|
||||
}
|
||||
|
||||
if req.Address != "" {
|
||||
o.Address = req.Address
|
||||
}
|
||||
|
||||
if req.LocationLink != "" {
|
||||
o.LocationLink = req.LocationLink
|
||||
}
|
||||
|
||||
if req.Description != "" {
|
||||
o.Description = req.Description
|
||||
}
|
||||
|
||||
if req.Highlight != "" {
|
||||
o.Highlight = req.Highlight
|
||||
}
|
||||
|
||||
if req.ContactPerson != "" {
|
||||
o.ContactPerson = req.ContactPerson
|
||||
}
|
||||
|
||||
if req.TnC != "" {
|
||||
o.TnC = req.TnC
|
||||
}
|
||||
|
||||
if req.AdditionalInfo != "" {
|
||||
o.AdditionalInfo = req.AdditionalInfo
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
o.Status = req.Status
|
||||
}
|
||||
|
||||
if req.IsSeasonTicket {
|
||||
o.IsSeasonTicket = req.IsSeasonTicket
|
||||
}
|
||||
|
||||
if req.IsDiscountActive {
|
||||
o.IsDiscountActive = req.IsDiscountActive
|
||||
}
|
||||
}
|
||||
|
||||
func (o *SiteDB) SetDeleted(updatedBy int64) {
|
||||
currentTime := time.Now()
|
||||
o.DeletedAt = ¤tTime
|
||||
o.UpdatedBy = updatedBy
|
||||
}
|
||||
Reference in New Issue
Block a user