update license

This commit is contained in:
aditya.siregar 2024-07-30 00:55:20 +07:00
parent 5b286fd44c
commit 2d1c450f65
7 changed files with 44 additions and 10 deletions

View File

@ -6,6 +6,20 @@ import (
)
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()"`
PartnerID int64 `gorm:"type:bigint;not null"`
Name string `gorm:"type:varchar(255);not null"`

View File

@ -125,7 +125,7 @@ func (h *Handler) GetAll(c *gin.Context) {
return
}
licenseResponses := response.FromEntityList(licenses)
licenseResponses := response.FromEntityListAll(licenses)
c.JSON(http.StatusOK, response.BaseResponse{
Success: true,

View File

@ -35,10 +35,6 @@ func (r *License) FromEntity(e *entity.License) {
}
r.SerialNumber = e.SerialNumber
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 {
@ -48,3 +44,27 @@ func FromEntityList(entities []*entity.License) []License {
}
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
}

View File

@ -49,8 +49,8 @@ func (r *LicenseRepository) FindByID(ctx context.Context, id string) (*entity.Li
return license, nil
}
func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.License, int64, error) {
var licenses []*entity.License
func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statusFilter string) ([]*entity.LicenseGetAll, int64, error) {
var licenses []*entity.LicenseGetAll
var total int64
// Define the main query with status calculation

View File

@ -196,5 +196,5 @@ type License interface {
Create(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)
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)
}

View File

@ -61,7 +61,7 @@ func (s *LicenseService) GetByID(ctx context.Context, id string) (*entity.Licens
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)
if err != nil {
logger.ContextLogger(ctx).Error("error when getting all licenses", zap.Error(err))

View File

@ -134,5 +134,5 @@ type License interface {
Create(ctx mycontext.Context, 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)
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)
}