Fix album lists, to use annotations
This commit is contained in:
@@ -75,6 +75,19 @@ func (r *albumRepository) GetAll(options ...model.QueryOptions) (model.Albums, e
|
||||
return r.toAlbums(all), nil
|
||||
}
|
||||
|
||||
func (r *albumRepository) GetMap(ids []string) (map[string]model.Album, error) {
|
||||
var all []album
|
||||
_, err := r.newQuery().Filter("id__in", ids).All(&all)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make(map[string]model.Album)
|
||||
for _, a := range all {
|
||||
res[a.ID] = model.Album(a)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// TODO Keep order when paginating
|
||||
func (r *albumRepository) GetRandom(options ...model.QueryOptions) (model.Albums, error) {
|
||||
sq := r.newRawQuery(options...)
|
||||
|
||||
@@ -75,6 +75,24 @@ func (r *annotationRepository) GetMap(userID, itemType string, itemID []string)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *annotationRepository) GetAll(userID, itemType string, options ...model.QueryOptions) ([]model.Annotation, error) {
|
||||
if userID == "" {
|
||||
return nil, model.ErrInvalidAuth
|
||||
}
|
||||
q := r.newQuery(options...).Filter("user_id", userID).Filter("item_type", itemType)
|
||||
var res []annotation
|
||||
_, err := q.All(&res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
all := make([]model.Annotation, len(res))
|
||||
for i, a := range res {
|
||||
all[i] = model.Annotation(a)
|
||||
}
|
||||
return all, err
|
||||
}
|
||||
|
||||
func (r *annotationRepository) new(userID, itemType string, itemID string) *annotation {
|
||||
id, _ := uuid.NewRandom()
|
||||
return &annotation{
|
||||
|
||||
@@ -26,6 +26,9 @@ func (r *sqlRepository) newQuery(options ...model.QueryOptions) orm.QuerySeter {
|
||||
q = q.OrderBy(opts.Sort)
|
||||
}
|
||||
}
|
||||
for field, value := range opts.Filters {
|
||||
q = q.Filter(field, value)
|
||||
}
|
||||
}
|
||||
return q
|
||||
}
|
||||
@@ -46,9 +49,6 @@ func (r *sqlRepository) newRawQuery(options ...model.QueryOptions) squirrel.Sele
|
||||
sq = sq.OrderBy(options[0].Sort)
|
||||
}
|
||||
}
|
||||
for field, value := range options[0].Filters {
|
||||
sq = sq.Where(squirrel.Like{field: value.(string) + "%"})
|
||||
}
|
||||
}
|
||||
return sq
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user