118 lines
2.8 KiB
Go
118 lines
2.8 KiB
Go
package entity
|
|
|
|
import (
|
|
"furtuna-be/internal/constants/product"
|
|
"time"
|
|
)
|
|
|
|
type Product struct {
|
|
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
|
PartnerID int64 `gorm:"type:int;column:partner_id"`
|
|
SiteID int64 `gorm:"type:int;column:site_id"`
|
|
Name string `gorm:"type:varchar(255);not null;column:name"`
|
|
Type string `gorm:"type:varchar;column:type"`
|
|
Price float64 `gorm:"type:decimal;column:price"`
|
|
IsWeekendTicket bool `gorm:"type:bool;column:is_weekend_ticket"`
|
|
IsSeasonTicket bool `gorm:"type:bool;column:is_season_ticket"`
|
|
Status string `gorm:"type:varchar;column:status"`
|
|
Description string `gorm:"type:varchar(255);not null;column:description"`
|
|
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"`
|
|
}
|
|
|
|
func (Product) TableName() string {
|
|
return "products"
|
|
}
|
|
|
|
type ProductSearch struct {
|
|
Search string
|
|
Name string
|
|
Type product.ProductType
|
|
BranchID int64
|
|
Available product.ProductStock
|
|
Limit int
|
|
Offset int
|
|
}
|
|
|
|
type ProductPOS struct {
|
|
PartnerID int64
|
|
SiteID int64
|
|
}
|
|
|
|
type ProductList []*ProductDB
|
|
|
|
type ProductDB struct {
|
|
Product
|
|
}
|
|
|
|
func (b *Product) ToProductDB() *ProductDB {
|
|
return &ProductDB{
|
|
Product: *b,
|
|
}
|
|
}
|
|
|
|
func (ProductDB) TableName() string {
|
|
return "products"
|
|
}
|
|
|
|
func (e *ProductDB) ToProduct() *Product {
|
|
return &Product{
|
|
ID: e.ID,
|
|
Name: e.Name,
|
|
Type: e.Type,
|
|
Price: e.Price,
|
|
Status: e.Status,
|
|
Description: e.Description,
|
|
PartnerID: e.PartnerID,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
DeletedAt: e.DeletedAt,
|
|
CreatedBy: e.CreatedBy,
|
|
UpdatedBy: e.UpdatedBy,
|
|
SiteID: e.SiteID,
|
|
IsSeasonTicket: e.IsSeasonTicket,
|
|
IsWeekendTicket: e.IsWeekendTicket,
|
|
}
|
|
}
|
|
|
|
func (b *ProductList) ToProductList() []*Product {
|
|
var Products []*Product
|
|
for _, product := range *b {
|
|
Products = append(Products, product.ToProduct())
|
|
}
|
|
return Products
|
|
}
|
|
|
|
func (o *ProductDB) ToUpdatedProduct(updatedby int64, req Product) {
|
|
o.UpdatedBy = updatedby
|
|
|
|
if req.Name != "" {
|
|
o.Name = req.Name
|
|
}
|
|
|
|
if req.Type != "" {
|
|
o.Type = req.Type
|
|
}
|
|
|
|
if req.Price > 0 {
|
|
o.Price = req.Price
|
|
}
|
|
|
|
if req.Status != "" {
|
|
o.Status = req.Status
|
|
}
|
|
|
|
if req.Description != "" {
|
|
o.Description = req.Description
|
|
}
|
|
}
|
|
|
|
func (o *ProductDB) SetDeleted(updatedby int64) {
|
|
currentTime := time.Now()
|
|
o.DeletedAt = ¤tTime
|
|
o.UpdatedBy = updatedby
|
|
}
|