init project
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"furtuna-be/internal/constants/product"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Product struct {
|
||||
ID int64
|
||||
Name string
|
||||
Type product.ProductType
|
||||
Price float64
|
||||
Status product.ProductStatus
|
||||
Description string
|
||||
Image string
|
||||
BranchID int64
|
||||
StockQty int64
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
CreatedBy int64
|
||||
UpdatedBy int64
|
||||
}
|
||||
|
||||
type ProductSearch struct {
|
||||
Search string
|
||||
Name string
|
||||
Type product.ProductType
|
||||
BranchID int64
|
||||
Available product.ProductStock
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
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,
|
||||
Image: e.Image,
|
||||
BranchID: e.BranchID,
|
||||
StockQty: e.StockQty,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
DeletedAt: e.DeletedAt,
|
||||
CreatedBy: e.CreatedBy,
|
||||
UpdatedBy: e.UpdatedBy,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if req.Image != "" {
|
||||
o.Image = req.Image
|
||||
}
|
||||
|
||||
if req.StockQty > 0 {
|
||||
o.StockQty = req.StockQty
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ProductDB) SetDeleted(updatedby int64) {
|
||||
currentTime := time.Now()
|
||||
o.DeletedAt = ¤tTime
|
||||
o.UpdatedBy = updatedby
|
||||
}
|
||||
Reference in New Issue
Block a user