From 34e843a4b32da7f7f08773eab94584e15c03d22d Mon Sep 17 00:00:00 2001 From: Deluan Date: Fri, 31 Jul 2020 15:52:41 -0400 Subject: [PATCH] Add updatedAt to Bookmarks --- model/playqueue.go | 1 + persistence/playqueue_repository.go | 5 +++++ persistence/playqueue_repository_test.go | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/model/playqueue.go b/model/playqueue.go index 97cda7e9d1a..d0cab95ac31 100644 --- a/model/playqueue.go +++ b/model/playqueue.go @@ -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 diff --git a/persistence/playqueue_repository.go b/persistence/playqueue_repository.go index 99ce51b835e..a0f437e4785 100644 --- a/persistence/playqueue_repository.go +++ b/persistence/playqueue_repository.go @@ -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 } diff --git a/persistence/playqueue_repository_test.go b/persistence/playqueue_repository_test.go index 308f38999b6..b4fcfe93934 100644 --- a/persistence/playqueue_repository_test.go +++ b/persistence/playqueue_repository_test.go @@ -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())