Add License
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user