- 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
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package social
|
|
|
|
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) AddLike(c *gin.Context) {
|
|
if err := h.svc.AddLike(c.Request.Context(), c.Param("id"), auth.UserID(c)); err != nil {
|
|
httpx.RespondError(c, err)
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
|
|
func (h *Handler) RemoveLike(c *gin.Context) {
|
|
if err := h.svc.RemoveLike(c.Request.Context(), c.Param("id"), auth.UserID(c)); err != nil {
|
|
httpx.RespondError(c, err)
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
|
|
func (h *Handler) ListComments(c *gin.Context) {
|
|
list, err := h.svc.ListComments(c.Request.Context(), c.Param("id"), auth.UserID(c))
|
|
if err != nil {
|
|
httpx.RespondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"comments": list})
|
|
}
|
|
|
|
type commentRequest struct {
|
|
Text string `json:"text" binding:"required"`
|
|
}
|
|
|
|
func (h *Handler) AddComment(c *gin.Context) {
|
|
var req commentRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
httpx.RespondError(c, httpx.BadRequest("invalid_request", "text is required"))
|
|
return
|
|
}
|
|
comment, err := h.svc.AddComment(c.Request.Context(), c.Param("id"), auth.UserID(c), req.Text)
|
|
if err != nil {
|
|
httpx.RespondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusCreated, gin.H{"comment": comment})
|
|
}
|
|
|
|
func (h *Handler) DeleteComment(c *gin.Context) {
|
|
if err := h.svc.DeleteComment(c.Request.Context(), c.Param("id"), auth.UserID(c)); err != nil {
|
|
httpx.RespondError(c, err)
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|