diff --git a/internal/entity/sites.go b/internal/entity/sites.go index 2fd3c8b..7314679 100644 --- a/internal/entity/sites.go +++ b/internal/entity/sites.go @@ -78,6 +78,7 @@ func (e *SiteDB) ToSite() *Site { DeletedAt: e.DeletedAt, CreatedBy: e.CreatedBy, UpdatedBy: e.UpdatedBy, + Products: e.Products, } } diff --git a/internal/handlers/http/sites/sites.go b/internal/handlers/http/sites/sites.go index aa9f740..53e1c86 100644 --- a/internal/handlers/http/sites/sites.go +++ b/internal/handlers/http/sites/sites.go @@ -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), } } diff --git a/internal/handlers/response/site.go b/internal/handlers/response/site.go index aac6816..6c12b77 100644 --- a/internal/handlers/response/site.go +++ b/internal/handlers/response/site.go @@ -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 { diff --git a/internal/repository/sites/sites.go b/internal/repository/sites/sites.go index 22d6bc8..6aeb24d 100644 --- a/internal/repository/sites/sites.go +++ b/internal/repository/sites/sites.go @@ -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 }