fix: issues
This commit is contained in:
@@ -15,6 +15,7 @@ type ListFilter struct {
|
||||
|
||||
type ListItem struct {
|
||||
ID int64 `json:"-"`
|
||||
Poster string `json:"poster"`
|
||||
Hash string `json:"hash"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
|
||||
@@ -83,6 +83,7 @@ func (svc *Service) GetMediaByID(ctx context.Context, tenantId, userId, id int64
|
||||
func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListItem {
|
||||
return &ListItem{
|
||||
ID: m.ID,
|
||||
Poster: fmt.Sprintf("/static/%s/poster.jpg", m.Hash),
|
||||
Hash: m.Hash,
|
||||
Title: m.Title,
|
||||
Description: m.Description,
|
||||
@@ -96,7 +97,7 @@ func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListI
|
||||
}
|
||||
|
||||
// List
|
||||
func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *ListFilter) ([]ListItem, error) {
|
||||
func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *ListFilter) ([]*ListItem, error) {
|
||||
log := svc.log.WithField("method", "List")
|
||||
|
||||
boughtIDs, err := svc.GetUserBoughtMedias(ctx, tenantId, userId)
|
||||
@@ -144,21 +145,8 @@ func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *Li
|
||||
return nil, errors.Wrap(err, "query medias")
|
||||
}
|
||||
|
||||
items := lo.Map(dest, func(m model.Medias, _ int) ListItem {
|
||||
item := ListItem{
|
||||
ID: m.ID,
|
||||
Hash: m.Hash,
|
||||
Title: m.Title,
|
||||
Description: m.Description,
|
||||
Duration: m.Duration,
|
||||
Price: m.Price,
|
||||
Discount: m.Discount,
|
||||
Resources: m.Resources,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
Bought: lo.Contains(boughtIDs, m.ID),
|
||||
}
|
||||
return item
|
||||
items := lo.Map(dest, func(m model.Medias, _ int) *ListItem {
|
||||
return svc.ModelToListItem(ctx, &m)
|
||||
})
|
||||
|
||||
return items, nil
|
||||
|
||||
Reference in New Issue
Block a user