update license
This commit is contained in:
parent
5b286fd44c
commit
2d1c450f65
@ -6,6 +6,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type License struct {
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LicenseGetAll struct {
|
||||||
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
|
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
|
||||||
PartnerID int64 `gorm:"type:bigint;not null"`
|
PartnerID int64 `gorm:"type:bigint;not null"`
|
||||||
Name string `gorm:"type:varchar(255);not null"`
|
Name string `gorm:"type:varchar(255);not null"`
|
||||||
|
|||||||
@ -125,7 +125,7 @@ func (h *Handler) GetAll(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
licenseResponses := response.FromEntityList(licenses)
|
licenseResponses := response.FromEntityListAll(licenses)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, response.BaseResponse{
|
c.JSON(http.StatusOK, response.BaseResponse{
|
||||||
Success: true,
|
Success: true,
|
||||||
|
|||||||
@ -35,10 +35,6 @@ func (r *License) FromEntity(e *entity.License) {
|
|||||||
}
|
}
|
||||||
r.SerialNumber = e.SerialNumber
|
r.SerialNumber = e.SerialNumber
|
||||||
r.PartnerID = e.PartnerID
|
r.PartnerID = e.PartnerID
|
||||||
r.CreatedBy = e.CreatedByName
|
|
||||||
r.UpdatedBy = e.UpdatedBy
|
|
||||||
r.PartnerName = e.PartnerName
|
|
||||||
r.Status = e.LicenseStatus
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromEntityList(entities []*entity.License) []License {
|
func FromEntityList(entities []*entity.License) []License {
|
||||||
@ -48,3 +44,27 @@ func FromEntityList(entities []*entity.License) []License {
|
|||||||
}
|
}
|
||||||
return licenses
|
return licenses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FromEntityListAll(entities []*entity.LicenseGetAll) []License {
|
||||||
|
licenses := make([]License, len(entities))
|
||||||
|
for i, e := range entities {
|
||||||
|
licenses[i].FromEntityGetAll(e)
|
||||||
|
}
|
||||||
|
return licenses
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *License) FromEntityGetAll(e *entity.LicenseGetAll) {
|
||||||
|
r.ID = e.ID.String()
|
||||||
|
r.Name = e.Name
|
||||||
|
r.StartDate = e.StartDate.Format("2006-01-02")
|
||||||
|
r.EndDate = e.EndDate.Format("2006-01-02")
|
||||||
|
if e.RenewalDate != nil {
|
||||||
|
r.RenewalDate = e.RenewalDate.Format("2006-01-02")
|
||||||
|
}
|
||||||
|
r.SerialNumber = e.SerialNumber
|
||||||
|
r.PartnerID = e.PartnerID
|
||||||
|
r.CreatedBy = e.CreatedByName
|
||||||
|
r.UpdatedBy = e.UpdatedBy
|
||||||
|
r.PartnerName = e.PartnerName
|
||||||
|
r.Status = e.LicenseStatus
|
||||||
|
}
|
||||||
|
|||||||
@ -49,8 +49,8 @@ func (r *LicenseRepository) FindByID(ctx context.Context, id string) (*entity.Li
|
|||||||
return license, nil
|
return license, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.License, int64, error) {
|
func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.LicenseGetAll, int64, error) {
|
||||||
var licenses []*entity.License
|
var licenses []*entity.LicenseGetAll
|
||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
// Define the main query with status calculation
|
// Define the main query with status calculation
|
||||||
|
|||||||
@ -196,5 +196,5 @@ type License interface {
|
|||||||
Create(ctx context.Context, license *entity.LicenseDB) (*entity.LicenseDB, error)
|
Create(ctx context.Context, license *entity.LicenseDB) (*entity.LicenseDB, error)
|
||||||
Update(ctx context.Context, license *entity.LicenseDB) (*entity.LicenseDB, error)
|
Update(ctx context.Context, license *entity.LicenseDB) (*entity.LicenseDB, error)
|
||||||
FindByID(ctx context.Context, id string) (*entity.LicenseDB, error)
|
FindByID(ctx context.Context, id string) (*entity.LicenseDB, error)
|
||||||
GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.License, int64, error)
|
GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.LicenseGetAll, int64, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ func (s *LicenseService) GetByID(ctx context.Context, id string) (*entity.Licens
|
|||||||
return licenseDB.ToLicense(), nil
|
return licenseDB.ToLicense(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LicenseService) GetAll(ctx context.Context, limit, offset int, status string) ([]*entity.License, int64, error) {
|
func (s *LicenseService) GetAll(ctx context.Context, limit, offset int, status string) ([]*entity.LicenseGetAll, int64, error) {
|
||||||
licenses, total, err := s.repo.GetAll(ctx, limit, offset, status)
|
licenses, total, err := s.repo.GetAll(ctx, limit, offset, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ContextLogger(ctx).Error("error when getting all licenses", zap.Error(err))
|
logger.ContextLogger(ctx).Error("error when getting all licenses", zap.Error(err))
|
||||||
|
|||||||
@ -134,5 +134,5 @@ type License interface {
|
|||||||
Create(ctx mycontext.Context, licenseReq *entity.License) (*entity.License, error)
|
Create(ctx mycontext.Context, licenseReq *entity.License) (*entity.License, error)
|
||||||
Update(ctx mycontext.Context, id string, licenseReq *entity.License) (*entity.License, error)
|
Update(ctx mycontext.Context, id string, licenseReq *entity.License) (*entity.License, error)
|
||||||
GetByID(ctx context.Context, id string) (*entity.License, error)
|
GetByID(ctx context.Context, id string) (*entity.License, error)
|
||||||
GetAll(ctx context.Context, limit, offset int, status string) ([]*entity.License, int64, error)
|
GetAll(ctx context.Context, limit, offset int, status string) ([]*entity.LicenseGetAll, int64, error)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user