41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.noroutes.net/NoRoutes/vibetunes/internal/auth"
|
|
"git.noroutes.net/NoRoutes/vibetunes/internal/database"
|
|
)
|
|
|
|
func (h *Web) handleBookmarks(w http.ResponseWriter, r *http.Request) {
|
|
user := auth.UserFromContext(r.Context())
|
|
bookmarks, err := database.ListBookmarks(h.DB, user.ID)
|
|
if err != nil {
|
|
http.Error(w, "internal error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
type bookmarkView struct {
|
|
Bookmark *database.Bookmark
|
|
Song SongRow
|
|
}
|
|
var views []bookmarkView
|
|
for _, b := range bookmarks {
|
|
song, err := database.GetSong(h.DB, b.SongID)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
views = append(views, bookmarkView{Bookmark: b, Song: toSongRow(h.DB, song, albumOf(h.DB, song), user.ID)})
|
|
}
|
|
h.page(w, r, "bookmarks", "bookmarks", "Bookmarks", views)
|
|
}
|
|
|
|
func (h *Web) handleBookmarkDelete(w http.ResponseWriter, r *http.Request) {
|
|
user := auth.UserFromContext(r.Context())
|
|
songID := r.PathValue("songID")
|
|
if err := database.DeleteBookmark(h.DB, user.ID, songID); err != nil {
|
|
http.Error(w, "internal error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
http.Redirect(w, r, "/bookmarks", http.StatusFound)
|
|
}
|