fix: detail site

This commit is contained in:
ferdiansyah783 2024-08-03 22:57:07 +07:00
parent 600d42d529
commit 265dd9b6e8
4 changed files with 5 additions and 1 deletions

View File

@ -78,6 +78,7 @@ func (e *SiteDB) ToSite() *Site {
DeletedAt: e.DeletedAt,
CreatedBy: e.CreatedBy,
UpdatedBy: e.UpdatedBy,
Products: e.Products,
}
}

View File

@ -286,6 +286,7 @@ func (h *Handler) toSiteResponse(resp *entity.Site) response.Site {
IsDiscountActive: resp.IsDiscountActive,
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
UpdatedAt: resp.UpdatedAt.Format(time.RFC3339),
Products: h.toProductResponseList(resp.Products),
}
}

View File

@ -17,6 +17,7 @@ type Site struct {
IsDiscountActive bool `json:"is_discount_active"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Products []Product `json:"products"`
}
type SiteName struct {

View File

@ -79,10 +79,11 @@ func (r *SiteRepository) Update(ctx context.Context, site *entity.SiteDB) (*enti
func (r *SiteRepository) GetByID(ctx context.Context, id int64) (*entity.SiteDB, error) {
site := new(entity.SiteDB)
if err := r.db.First(site, id).Error; err != nil {
if err := r.db.Debug().Preload("Products").First(site, id).Error; err != nil {
logger.ContextLogger(ctx).Error("error when getting site by ID", zap.Error(err))
return nil, err
}
return site, nil
}