Files
iu 50dff63ece feat: rename service to galo, add halo branding and release build
- rename Go module, binary, systemd unit, PG_DATABASE default, frontend package and docs from shared-album to galo
- add theme-aware halo emblem and favicon (new ui-branding capability)
- add make build-release (versioned, stripped, static binary) and run the binary from the repo root
2026-10-11 11:36:56 +03:00

88 lines
2.1 KiB
Go

package albums
import (
"net/http"
"github.com/gin-gonic/gin"
"galo/internal/auth"
"galo/internal/httpx"
)
type Handler struct {
svc *Service
}
func NewHandler(svc *Service) *Handler { return &Handler{svc: svc} }
func (h *Handler) List(c *gin.Context) {
list, err := h.svc.List(c.Request.Context(), auth.UserID(c))
if err != nil {
httpx.RespondError(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"albums": list})
}
type albumRequest struct {
Title string `json:"title" binding:"required"`
Description string `json:"description"`
}
func (h *Handler) Create(c *gin.Context) {
var req albumRequest
if err := c.ShouldBindJSON(&req); err != nil {
httpx.RespondError(c, httpx.BadRequest("invalid_request", "title is required"))
return
}
a, err := h.svc.Create(c.Request.Context(), auth.UserID(c), CreateInput(req))
if err != nil {
httpx.RespondError(c, err)
return
}
c.JSON(http.StatusCreated, gin.H{"album": a})
}
func (h *Handler) Get(c *gin.Context) {
a, role, err := h.svc.Get(c.Request.Context(), c.Param("id"), auth.UserID(c))
if err != nil {
httpx.RespondError(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"album": a, "role": role})
}
type updateRequest struct {
Title *string `json:"title"`
Description *string `json:"description"`
CoverPhotoID *string `json:"cover_photo_id"`
ClearCover bool `json:"clear_cover"`
}
func (h *Handler) Update(c *gin.Context) {
var req updateRequest
if err := c.ShouldBindJSON(&req); err != nil {
httpx.RespondError(c, httpx.BadRequest("invalid_request", "invalid body"))
return
}
a, err := h.svc.Update(c.Request.Context(), c.Param("id"), auth.UserID(c), UpdateInput{
Title: req.Title,
Description: req.Description,
CoverPhotoID: req.CoverPhotoID,
ClearCover: req.ClearCover,
})
if err != nil {
httpx.RespondError(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"album": a})
}
func (h *Handler) Delete(c *gin.Context) {
if err := h.svc.Delete(c.Request.Context(), c.Param("id"), auth.UserID(c)); err != nil {
httpx.RespondError(c, err)
return
}
c.Status(http.StatusNoContent)
}