return full bookmark object from getbookmarks

fixes #328
This commit is contained in:
sentriz
2023-09-13 01:45:40 +01:00
parent 2a7a455ce2
commit 3553348877
3 changed files with 29 additions and 22 deletions

View File

@@ -44,3 +44,6 @@ issues:
- text: "at least one file in a package should have a package comment" - text: "at least one file in a package should have a package comment"
linters: linters:
- stylecheck - stylecheck
- text: "should rewrite switch"
linters:
- gocritic

View File

@@ -22,28 +22,37 @@ func (c *Controller) ServeGetBookmarks(r *http.Request) *spec.Response {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
return spec.NewResponse() return spec.NewResponse()
} }
sub := spec.NewResponse() sub := spec.NewResponse()
sub.Bookmarks = &spec.Bookmarks{ sub.Bookmarks = &spec.Bookmarks{
List: []*spec.Bookmark{}, List: []*spec.Bookmark{},
} }
for _, bookmark := range bookmarks { for _, bookmark := range bookmarks {
specid := &specid.ID{ respBookmark := &spec.Bookmark{
Type: specid.IDT(bookmark.EntryIDType),
Value: bookmark.EntryID,
}
entry := spec.BookmarkEntry{
ID: specid,
Type: bookmark.EntryIDType,
}
sub.Bookmarks.List = append(sub.Bookmarks.List, &spec.Bookmark{
Username: user.Name, Username: user.Name,
Position: bookmark.Position, Position: bookmark.Position,
Comment: bookmark.Comment, Comment: bookmark.Comment,
Created: bookmark.CreatedAt, Created: bookmark.CreatedAt,
Changed: bookmark.UpdatedAt, Changed: bookmark.UpdatedAt,
Entry: entry, }
})
switch specid.IDT(bookmark.EntryIDType) {
case specid.Track:
var track db.Track
err := c.DB.
Preload("Album").
Find(&track, "id=?", bookmark.EntryID).
Error
if err != nil {
return spec.NewError(10, "finding entry: %v", err)
}
respBookmark.Entry = spec.NewTrackByTags(&track, track.Album)
}
sub.Bookmarks.List = append(sub.Bookmarks.List, respBookmark)
} }
return sub return sub
} }

View File

@@ -377,17 +377,12 @@ type Bookmarks struct {
} }
type Bookmark struct { type Bookmark struct {
Entry BookmarkEntry `xml:"entry,omitempty" json:"entry,omitempty"` Entry *TrackChild `xml:"entry,omitempty" json:"entry,omitempty"`
Username string `xml:"username,attr" json:"username"` Username string `xml:"username,attr" json:"username"`
Position int `xml:"position,attr" json:"position"` Position int `xml:"position,attr" json:"position"`
Comment string `xml:"comment,attr" json:"comment"` Comment string `xml:"comment,attr" json:"comment"`
Created time.Time `xml:"created,attr" json:"created"` Created time.Time `xml:"created,attr" json:"created"`
Changed time.Time `xml:"changed,attr" json:"changed"` Changed time.Time `xml:"changed,attr" json:"changed"`
}
type BookmarkEntry struct {
ID *specid.ID `xml:"id,attr" json:"id"`
Type string `xml:"type,attr" json:"type"`
} }
type Starred struct { type Starred struct {