Use new rest lib (Update receives all columns that need to be updated)

This commit is contained in:
Deluan
2021-11-01 13:55:47 -04:00
parent b2acec0a09
commit 778f474d26
14 changed files with 46 additions and 26 deletions
+10 -4
View File
@@ -376,13 +376,19 @@ func (r *playlistRepository) Save(entity interface{}) (string, error) {
return pls.ID, err
}
func (r *playlistRepository) Update(entity interface{}, cols ...string) error {
pls := entity.(*model.Playlist)
func (r *playlistRepository) Update(id string, entity interface{}, cols ...string) error {
current, err := r.Get(id)
if err != nil {
return err
}
usr := loggedUser(r.ctx)
if !usr.IsAdmin && pls.OwnerID != usr.ID {
if !usr.IsAdmin && current.OwnerID != usr.ID {
return rest.ErrPermissionDenied
}
err := r.Put(pls)
pls := entity.(*model.Playlist)
pls.ID = id
pls.UpdatedAt = time.Now()
_, err = r.put(id, pls, append(cols, "updatedAt")...)
if err == model.ErrNotFound {
return rest.ErrNotFound
}