From 924ada0dab510cca79936d05513aa71bb18f3854 Mon Sep 17 00:00:00 2001 From: Deluan <deluan@navidrome.org> Date: Fri, 31 Jul 2020 15:47:34 -0400 Subject: [PATCH] Add bookmark API repsonse --- ...ses Bookmarks with data should match .JSON | 1 + ...nses Bookmarks with data should match .XML | 1 + ... Bookmarks without data should match .JSON | 1 + ...s Bookmarks without data should match .XML | 1 + server/subsonic/responses/responses.go | 14 ++++++++ server/subsonic/responses/responses_test.go | 34 +++++++++++++++++++ 6 files changed, 52 insertions(+) create mode 100644 server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .JSON create mode 100644 server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .XML create mode 100644 server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .JSON create mode 100644 server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .XML diff --git a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .JSON b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .JSON new file mode 100644 index 000000000..ae9fc6fa2 --- /dev/null +++ b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","bookmarks":{"bookmark":[{"entry":[{"id":"1","isDir":false,"title":"title","isVideo":false}],"position":123,"username":"user2","comment":"a comment","created":"0001-01-01T00:00:00Z","changed":"0001-01-01T00:00:00Z"}]}} diff --git a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .XML b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .XML new file mode 100644 index 000000000..cda506634 --- /dev/null +++ b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks with data should match .XML @@ -0,0 +1 @@ +<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><bookmarks><bookmark position="123" username="user2" comment="a comment" created="0001-01-01T00:00:00Z" changed="0001-01-01T00:00:00Z"><entry id="1" isDir="false" title="title" isVideo="false"></entry></bookmark></bookmarks></subsonic-response> diff --git a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .JSON b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .JSON new file mode 100644 index 000000000..06316950a --- /dev/null +++ b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","bookmarks":{}} diff --git a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .XML b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .XML new file mode 100644 index 000000000..746ee55b3 --- /dev/null +++ b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Bookmarks without data should match .XML @@ -0,0 +1 @@ +<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0"><bookmarks></bookmarks></subsonic-response> diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.go index eb529ea14..447da51a6 100644 --- a/server/subsonic/responses/responses.go +++ b/server/subsonic/responses/responses.go @@ -40,6 +40,7 @@ type Subsonic struct { ArtistInfo2 *ArtistInfo2 `xml:"artistInfo2,omitempty" json:"artistInfo2,omitempty"` PlayQueue *PlayQueue `xml:"playQueue,omitempty" json:"playQueue,omitempty"` + Bookmarks *Bookmarks `xml:"bookmarks,omitempty" json:"bookmarks,omitempty"` } type JsonWrapper struct { @@ -304,3 +305,16 @@ type PlayQueue struct { Changed *time.Time `xml:"changed,attr,omitempty" json:"changed,omitempty"` ChangedBy string `xml:"changedBy,attr" json:"changedBy"` } + +type Bookmark struct { + Entry []Child `xml:"entry,omitempty" json:"entry,omitempty"` + Position int64 `xml:"position,attr,omitempty" json:"position,omitempty"` + Username string `xml:"username,attr" json:"username"` + Comment string `xml:"comment,attr" json:"comment"` + Created time.Time `xml:"created,attr" json:"created"` + Changed time.Time `xml:"changed,attr" json:"changed"` +} + +type Bookmarks struct { + Bookmark []Bookmark `xml:"bookmark,omitempty" json:"bookmark,omitempty"` +} diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.go index fc07331d1..729d73d7c 100644 --- a/server/subsonic/responses/responses_test.go +++ b/server/subsonic/responses/responses_test.go @@ -356,7 +356,41 @@ var _ = Describe("Responses", func() { child := make([]Child, 1) child[0] = Child{Id: "1", Title: "title", IsDir: false} response.PlayQueue.Entry = child + }) + It("should match .XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match .JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + }) + Describe("Bookmarks", func() { + BeforeEach(func() { + response.Bookmarks = &Bookmarks{} + }) + + Context("without data", func() { + It("should match .XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match .JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + + Context("with data", func() { + BeforeEach(func() { + bmk := Bookmark{ + Position: 123, + Username: "user2", + Comment: "a comment", + Created: time.Time{}, + Changed: time.Time{}, + } + bmk.Entry = []Child{{Id: "1", Title: "title", IsDir: false}} + response.Bookmarks.Bookmark = []Bookmark{bmk} }) It("should match .XML", func() { Expect(xml.Marshal(response)).To(MatchSnapshot())