Skip to content

Commit

Permalink
Add updatedAt to Bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 31, 2020
1 parent 924ada0 commit 34e843a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions model/playqueue.go
Expand Up @@ -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
5 changes: 5 additions & 0 deletions persistence/playqueue_repository.go
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions persistence/playqueue_repository_test.go
Expand Up @@ -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())

Expand All @@ -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())
Expand Down

0 comments on commit 34e843a

Please sign in to comment.