fix: detail site
This commit is contained in:
parent
600d42d529
commit
265dd9b6e8
@ -78,6 +78,7 @@ func (e *SiteDB) ToSite() *Site {
|
|||||||
DeletedAt: e.DeletedAt,
|
DeletedAt: e.DeletedAt,
|
||||||
CreatedBy: e.CreatedBy,
|
CreatedBy: e.CreatedBy,
|
||||||
UpdatedBy: e.UpdatedBy,
|
UpdatedBy: e.UpdatedBy,
|
||||||
|
Products: e.Products,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -286,6 +286,7 @@ func (h *Handler) toSiteResponse(resp *entity.Site) response.Site {
|
|||||||
IsDiscountActive: resp.IsDiscountActive,
|
IsDiscountActive: resp.IsDiscountActive,
|
||||||
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
||||||
UpdatedAt: resp.UpdatedAt.Format(time.RFC3339),
|
UpdatedAt: resp.UpdatedAt.Format(time.RFC3339),
|
||||||
|
Products: h.toProductResponseList(resp.Products),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@ type Site struct {
|
|||||||
IsDiscountActive bool `json:"is_discount_active"`
|
IsDiscountActive bool `json:"is_discount_active"`
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
UpdatedAt string `json:"updated_at"`
|
UpdatedAt string `json:"updated_at"`
|
||||||
|
Products []Product `json:"products"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SiteName struct {
|
type SiteName struct {
|
||||||
|
|||||||
@ -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) {
|
func (r *SiteRepository) GetByID(ctx context.Context, id int64) (*entity.SiteDB, error) {
|
||||||
site := new(entity.SiteDB)
|
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))
|
logger.ContextLogger(ctx).Error("error when getting site by ID", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return site, nil
|
return site, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user