04769dec78
Desktop Client Build / Resolve Build Metadata (push) Successful in 26s
Frontend CI / Frontend (push) Successful in 2m47s
Backend CI / Backend (push) Failing after 10m1s
Desktop Client Build / Build Desktop Client (push) Successful in 23m3s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 29s
111 lines
2.9 KiB
Go
111 lines
2.9 KiB
Go
package transport
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/bootstrap"
|
|
"github.com/geo-platform/tenant-api/internal/shared/response"
|
|
"github.com/geo-platform/tenant-api/internal/tenant/app"
|
|
)
|
|
|
|
type MediaHandler struct {
|
|
svc *app.MediaService
|
|
}
|
|
|
|
func NewMediaHandler(a *bootstrap.App) *MediaHandler {
|
|
return &MediaHandler{
|
|
svc: app.NewMediaService(a.DB),
|
|
}
|
|
}
|
|
|
|
func (h *MediaHandler) ListPlatforms(c *gin.Context) {
|
|
data, err := h.svc.ListPlatforms(c.Request.Context())
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *MediaHandler) ListAllPublishRecords(c *gin.Context) {
|
|
req := app.ListPublishRecordsRequest{
|
|
Page: 1,
|
|
PageSize: 10,
|
|
Title: strings.TrimSpace(c.Query("title")),
|
|
}
|
|
|
|
if rawPage := c.Query("page"); rawPage != "" {
|
|
parsed, err := strconv.Atoi(rawPage)
|
|
if err != nil || parsed <= 0 {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", "page must be a positive integer"))
|
|
return
|
|
}
|
|
req.Page = parsed
|
|
}
|
|
|
|
rawPageSize := c.Query("page_size")
|
|
if rawPageSize == "" {
|
|
rawPageSize = c.Query("limit")
|
|
}
|
|
if rawPageSize != "" {
|
|
parsed, err := strconv.Atoi(rawPageSize)
|
|
if err != nil || parsed <= 0 {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", "page_size must be a positive integer"))
|
|
return
|
|
}
|
|
req.PageSize = parsed
|
|
}
|
|
|
|
data, err := h.svc.ListPublishRecords(c.Request.Context(), req)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *MediaHandler) ListPublishRecords(c *gin.Context) {
|
|
articleID, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "article id must be a number"))
|
|
return
|
|
}
|
|
data, err := h.svc.ListArticlePublishRecords(c.Request.Context(), articleID)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *MediaHandler) DeletePublishRecord(c *gin.Context) {
|
|
recordID, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
|
if err != nil || recordID <= 0 {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_publish_record_id", "publish record id must be a positive number"))
|
|
return
|
|
}
|
|
data, err := h.svc.DeletePublishRecord(c.Request.Context(), recordID)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *MediaHandler) DeleteDesktopPublishRecord(c *gin.Context) {
|
|
recordID, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
|
if err != nil || recordID <= 0 {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_publish_record_id", "publish record id must be a positive number"))
|
|
return
|
|
}
|
|
data, err := h.svc.DeleteDesktopPublishRecord(c.Request.Context(), MustDesktopClient(c.Request.Context()), recordID)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|