84 lines
1.3 KiB
Go
84 lines
1.3 KiB
Go
package entity
|
|
|
|
import (
|
|
"furtuna-be/internal/constants/branch"
|
|
"time"
|
|
)
|
|
|
|
type Branch struct {
|
|
ID int64
|
|
Name string
|
|
Status branch.BranchStatus
|
|
Location string
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
DeletedAt *time.Time
|
|
CreatedBy int64
|
|
UpdatedBy int64
|
|
}
|
|
|
|
type BranchSearch struct {
|
|
Search string
|
|
Name string
|
|
Limit int
|
|
Offset int
|
|
}
|
|
|
|
type BranchList []*BranchDB
|
|
|
|
type BranchDB struct {
|
|
Branch
|
|
}
|
|
|
|
func (b *Branch) ToBranchDB() *BranchDB {
|
|
return &BranchDB{
|
|
Branch: *b,
|
|
}
|
|
}
|
|
|
|
func (BranchDB) TableName() string {
|
|
return "branches"
|
|
}
|
|
|
|
func (e *BranchDB) ToBranch() *Branch {
|
|
return &Branch{
|
|
ID: e.ID,
|
|
Name: e.Name,
|
|
Status: e.Status,
|
|
Location: e.Location,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
CreatedBy: e.CreatedBy,
|
|
}
|
|
}
|
|
|
|
func (b *BranchList) ToBranchList() []*Branch {
|
|
var branches []*Branch
|
|
for _, branch := range *b {
|
|
branches = append(branches, branch.ToBranch())
|
|
}
|
|
return branches
|
|
}
|
|
|
|
func (o *BranchDB) ToUpdatedBranch(updatedby int64, req Branch) {
|
|
o.UpdatedBy = updatedby
|
|
|
|
if req.Name != "" {
|
|
o.Name = req.Name
|
|
}
|
|
|
|
if req.Status != "" {
|
|
o.Status = req.Status
|
|
}
|
|
|
|
if req.Location != "" {
|
|
o.Location = req.Location
|
|
}
|
|
}
|
|
|
|
func (o *BranchDB) SetDeleted(updatedby int64) {
|
|
currentTime := time.Now()
|
|
o.DeletedAt = ¤tTime
|
|
o.UpdatedBy = updatedby
|
|
}
|