拆分商品模块服务和处理器职责

This commit is contained in:
yml2213
2026-06-10 14:50:25 +08:00
parent 78cb681bec
commit 14d9601ef2
14 changed files with 1408 additions and 1323 deletions
@@ -0,0 +1,117 @@
package listing
import (
"hfb_sys/backend/pkg/response"
"github.com/gin-gonic/gin"
)
func (h *Handler) Create(c *gin.Context) {
ownerID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
var req CreateRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "发布信息不完整")
return
}
item, err := h.service.Create(c.Request.Context(), ownerID, req)
if err != nil {
writeListingError(c, err)
return
}
response.Created(c, item)
}
func (h *Handler) Update(c *gin.Context) {
ownerID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
id, ok := parseID(c)
if !ok {
return
}
var req UpdateRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "发布信息不完整")
return
}
item, err := h.service.Update(c.Request.Context(), ownerID, id, req)
if err != nil {
writeListingError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) SubmitReview(c *gin.Context) {
ownerID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
id, ok := parseID(c)
if !ok {
return
}
item, err := h.service.SubmitReview(c.Request.Context(), ownerID, id)
if err != nil {
writeListingError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) Offline(c *gin.Context) {
ownerID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
id, ok := parseID(c)
if !ok {
return
}
item, err := h.service.Offline(c.Request.Context(), ownerID, id)
if err != nil {
writeListingError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) ListMine(c *gin.Context) {
ownerID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
items, err := h.service.ListMine(c.Request.Context(), ownerID)
if err != nil {
writeListingError(c, err)
return
}
response.OK(c, gin.H{"items": items})
}
func (h *Handler) FindMine(c *gin.Context) {
ownerID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
id, ok := parseID(c)
if !ok {
return
}
item, err := h.service.FindMine(c.Request.Context(), ownerID, id)
if err != nil {
writeListingError(c, err)
return
}
response.OK(c, item)
}