mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
1e291df647
Store pinned library IDs on the user record and expose GET/PUT /me/pinned-libraries endpoints. The web client now loads and saves pins through the API, migrates legacy localStorage data once, and applies pinned ordering on both the libraries and home pages. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/truewhile/MeBox/internal/middleware"
|
|
"github.com/truewhile/MeBox/internal/service"
|
|
)
|
|
|
|
type pinnedLibrariesReq struct {
|
|
LibraryIDs []string `json:"library_ids"`
|
|
}
|
|
|
|
func getPinnedLibrariesHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
uid, _ := c.Get(middleware.CtxUserID)
|
|
ids, err := svc.Profile.GetPinnedLibraryIDs(c.Request.Context(), uid.(string))
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
if ids == nil {
|
|
ids = []string{}
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"library_ids": ids})
|
|
}
|
|
}
|
|
|
|
func setPinnedLibrariesHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
var req pinnedLibrariesReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
uid, _ := c.Get(middleware.CtxUserID)
|
|
ids, err := svc.Profile.SetPinnedLibraryIDs(c.Request.Context(), uid.(string), req.LibraryIDs)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
if ids == nil {
|
|
ids = []string{}
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"library_ids": ids})
|
|
}
|
|
}
|