feat(admin): 管理端在线监控 + 好友关系管理后端
- admin/service/online_service.go: 在线用户列表/计数 - admin/controller/online_controller.go: GET /admin/online/users|count - admin/service/contact_manage_service.go: 好友关系分页查询/管理员删除 - admin/controller/contact_manage_controller.go: GET|DELETE /admin/contacts - 更新 admin router/provider/wire 集成新控制器 Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/echochat/backend/app/admin/service"
|
||||
"github.com/echochat/backend/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ContactManageController struct {
|
||||
contactManageService *service.ContactManageService
|
||||
}
|
||||
|
||||
func NewContactManageController(contactManageService *service.ContactManageService) *ContactManageController {
|
||||
return &ContactManageController{contactManageService: contactManageService}
|
||||
}
|
||||
|
||||
// GetAllContacts GET /api/v1/admin/contacts
|
||||
func (ctl *ContactManageController) GetAllContacts(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
||||
|
||||
contacts, total, err := ctl.contactManageService.GetAllFriendships(ctx, page, pageSize)
|
||||
if err != nil {
|
||||
utils.ResponseError(c, "获取好友关系列表失败")
|
||||
return
|
||||
}
|
||||
utils.ResponseOK(c, gin.H{
|
||||
"list": contacts,
|
||||
"total": total,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteContact DELETE /api/v1/admin/contacts/:id
|
||||
func (ctl *ContactManageController) DeleteContact(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
utils.ResponseBadRequest(c, "ID 格式错误")
|
||||
return
|
||||
}
|
||||
|
||||
if err := ctl.contactManageService.DeleteFriendship(ctx, id); err != nil {
|
||||
utils.ResponseError(c, "删除好友关系失败")
|
||||
return
|
||||
}
|
||||
utils.ResponseOK(c, nil)
|
||||
}
|
||||
37
backend/go-service/app/admin/controller/online_controller.go
Normal file
37
backend/go-service/app/admin/controller/online_controller.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/echochat/backend/app/admin/service"
|
||||
"github.com/echochat/backend/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type OnlineController struct {
|
||||
onlineManageService *service.OnlineManageService
|
||||
}
|
||||
|
||||
func NewOnlineController(onlineManageService *service.OnlineManageService) *OnlineController {
|
||||
return &OnlineController{onlineManageService: onlineManageService}
|
||||
}
|
||||
|
||||
// GetOnlineUsers GET /api/v1/admin/online/users
|
||||
func (ctl *OnlineController) GetOnlineUsers(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
userIDs, err := ctl.onlineManageService.GetOnlineUsers(ctx)
|
||||
if err != nil {
|
||||
utils.ResponseError(c, "获取在线用户列表失败")
|
||||
return
|
||||
}
|
||||
utils.ResponseOK(c, userIDs)
|
||||
}
|
||||
|
||||
// GetOnlineCount GET /api/v1/admin/online/count
|
||||
func (ctl *OnlineController) GetOnlineCount(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
count, err := ctl.onlineManageService.GetOnlineCount(ctx)
|
||||
if err != nil {
|
||||
utils.ResponseError(c, "获取在线用户数失败")
|
||||
return
|
||||
}
|
||||
utils.ResponseOK(c, gin.H{"count": count})
|
||||
}
|
||||
Reference in New Issue
Block a user