156 lines
2.9 KiB
Go
156 lines
2.9 KiB
Go
package friendhandler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
friendlogic "spark-server/internal/module/friend/logic"
|
|
"spark-server/internal/transport/http/respond"
|
|
)
|
|
|
|
func (h *Handler) Get(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
friendID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
view, err := h.friends.Get(c.Request.Context(), uid, friendID)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, view)
|
|
}
|
|
|
|
func (h *Handler) Delete(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
friendID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
if err := h.friends.Delete(c.Request.Context(), uid, friendID); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, gin.H{})
|
|
}
|
|
|
|
func (h *Handler) Pin(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
friendID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
if err := h.friends.Pin(c.Request.Context(), uid, friendID); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, gin.H{})
|
|
}
|
|
|
|
func (h *Handler) Unpin(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
friendID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
if err := h.friends.Unpin(c.Request.Context(), uid, friendID); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, gin.H{})
|
|
}
|
|
|
|
func (h *Handler) Remark(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
friendID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
var in friendlogic.RemarkInput
|
|
if err := respond.BindJSON(c, &in); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
if err := h.friends.SetRemark(c.Request.Context(), uid, friendID, in); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, gin.H{})
|
|
}
|
|
|
|
func (h *Handler) Block(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
targetID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
if err := h.friends.Block(c.Request.Context(), uid, targetID); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, gin.H{})
|
|
}
|
|
|
|
func (h *Handler) Unblock(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
targetID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
if err := h.friends.Unblock(c.Request.Context(), uid, targetID); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, gin.H{})
|
|
}
|
|
|
|
func (h *Handler) Report(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
targetID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
var in friendlogic.ReportInput
|
|
if err := respond.BindJSON(c, &in); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
if err := h.friends.Report(c.Request.Context(), uid, targetID, in); err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, gin.H{})
|
|
}
|