aditya.siregar f645f23fd4 Add License
2024-07-29 22:30:29 +07:00

82 lines
1.9 KiB
Go

package entity
import (
"github.com/google/uuid"
"time"
)
type License struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
PartnerID int64 `gorm:"type:bigint;not null"`
Name string `gorm:"type:varchar(255);not null"`
StartDate time.Time `gorm:"type:date;not null"`
EndDate time.Time `gorm:"type:date;not null"`
RenewalDate *time.Time `gorm:"type:date"`
SerialNumber string `gorm:"type:varchar(255);unique;not null"`
CreatedBy int64 `gorm:"type:bigint;not null"`
UpdatedBy int64 `gorm:"type:bigint;not null"`
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
PartnerName string `gorm:"type:varchar(255);not null"`
LicenseStatus string `gorm:"type:string(255);not null"`
CreatedByName string `gorm:"type:string(255);not null"`
}
func (License) TableName() string {
return "licenses"
}
type LicenseDB struct {
License
}
func (l *License) ToLicenseDB() *LicenseDB {
return &LicenseDB{
License: *l,
}
}
func (LicenseDB) TableName() string {
return "licenses"
}
func (e *LicenseDB) ToLicense() *License {
return &License{
ID: e.ID,
PartnerID: e.PartnerID,
Name: e.Name,
StartDate: e.StartDate,
EndDate: e.EndDate,
RenewalDate: e.RenewalDate,
SerialNumber: e.SerialNumber,
CreatedBy: e.CreatedBy,
UpdatedBy: e.UpdatedBy,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
}
}
func (o *LicenseDB) ToUpdatedLicense(updatedBy int64, req License) {
o.UpdatedBy = updatedBy
if req.Name != "" {
o.Name = req.Name
}
if !req.StartDate.IsZero() {
o.StartDate = req.StartDate
}
if !req.EndDate.IsZero() {
o.EndDate = req.EndDate
}
if req.RenewalDate != nil {
o.RenewalDate = req.RenewalDate
}
if req.SerialNumber != "" {
o.SerialNumber = req.SerialNumber
}
}