功能更新
This commit is contained in:
74
internal/controller/profile.go
Normal file
74
internal/controller/profile.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"nl-pms-api/internal/commonservice"
|
||||
"nl-pms-api/internal/service"
|
||||
)
|
||||
|
||||
// ProfileController 用户资料。
|
||||
type ProfileController struct {
|
||||
Svc *service.ProfileService
|
||||
AvatarHist *service.AvatarHistoryService
|
||||
}
|
||||
|
||||
func (h *ProfileController) Get(c *gin.Context) {
|
||||
out, err := h.Svc.Get(commonservice.UserID(c))
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, out)
|
||||
}
|
||||
|
||||
func (h *ProfileController) Put(c *gin.Context) {
|
||||
var req service.ProfileDTO
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
out, err := h.Svc.Put(commonservice.UserID(c), req)
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, out)
|
||||
}
|
||||
|
||||
// ListAvatars GET /profile/avatars
|
||||
func (h *ProfileController) ListAvatars(c *gin.Context) {
|
||||
out, err := h.AvatarHist.List(commonservice.UserID(c))
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": out})
|
||||
}
|
||||
|
||||
// PushAvatar POST /profile/avatars body: {mode,value}
|
||||
func (h *ProfileController) PushAvatar(c *gin.Context) {
|
||||
var req struct {
|
||||
Mode string `json:"mode"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
if !bindJSON(c, &req) {
|
||||
return
|
||||
}
|
||||
out, err := h.AvatarHist.Push(commonservice.UserID(c), req.Mode, req.Value)
|
||||
if err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": out})
|
||||
}
|
||||
|
||||
// DeleteAvatar DELETE /profile/avatars/:id
|
||||
func (h *ProfileController) DeleteAvatar(c *gin.Context) {
|
||||
if err := h.AvatarHist.Delete(commonservice.UserID(c), commonservice.ParseID(c.Param("id"))); err != nil {
|
||||
writeErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||
}
|
||||
Reference in New Issue
Block a user