Add updatedAt to Bookmarks

This commit is contained in:
Deluan 2020-07-31 15:52:41 -04:00 committed by Deluan Quintão
parent 924ada0dab
commit 34e843a4b3
3 changed files with 11 additions and 0 deletions

View File

@ -31,6 +31,7 @@ type Bookmark struct {
Comment string `json:"comment"`
Position int64 `json:"position"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type Bookmarks []Bookmark

View File

@ -89,6 +89,10 @@ func (r *playQueueRepository) AddBookmark(userId, id, comment string, position i
return err
}
if !prev.CreatedAt.IsZero() {
bm.CreatedAt = prev.CreatedAt
}
_, err = r.put(prev.ID, bm)
if err != nil {
log.Error(r.ctx, "Error saving bookmark", "user", u.UserName, err, "mediaFileId", id, err)
@ -112,6 +116,7 @@ func (r *playQueueRepository) GetBookmarks(userId string) (model.Bookmarks, erro
bms[i].Comment = pqs[i].Comment
bms[i].Position = int64(pqs[i].Position)
bms[i].CreatedAt = pqs[i].CreatedAt
bms[i].UpdatedAt = pqs[i].UpdatedAt
}
return bms, nil
}

View File

@ -70,6 +70,9 @@ var _ = Describe("PlayQueueRepository", func() {
Expect(bms[0].Comment).To(Equal("this is a comment"))
Expect(bms[0].Position).To(Equal(int64(123)))
created := bms[0].CreatedAt
updated := bms[0].UpdatedAt
By("Overriding the bookmark")
Expect(repo.AddBookmark("user5", songAntenna.ID, "another comment", 333)).To(BeNil())
@ -79,6 +82,8 @@ var _ = Describe("PlayQueueRepository", func() {
Expect(bms[0].ID).To(Equal(songAntenna.ID))
Expect(bms[0].Comment).To(Equal("another comment"))
Expect(bms[0].Position).To(Equal(int64(333)))
Expect(bms[0].CreatedAt).To(Equal(created))
Expect(bms[0].UpdatedAt).To(BeTemporally(">", updated))
By("Saving another bookmark")
Expect(repo.AddBookmark("user5", songComeTogether.ID, "one more comment", 444)).To(BeNil())