Version:0.0.5.dev.260204

feat: 🏗️ 完成任务分类创建与列表查询接口并通过测试

- 历经复杂嵌套逻辑处理 🌀
- 实现创建任务分类接口 
- 实现获取任务分类列表接口 📋
- 接口测试全部通过 🧪

perf: 🚀 下个版本将为任务分类列表接口加入 Redis 缓存以提升查询速度 
This commit is contained in:
LoveLosita
2026-02-04 19:26:22 +08:00
parent f554d9bd06
commit af8e8bd804
8 changed files with 384 additions and 6 deletions

51
backend/api/task-class.go Normal file
View File

@@ -0,0 +1,51 @@
package api
import (
"errors"
"net/http"
"github.com/LoveLosita/smartflow/backend/model"
"github.com/LoveLosita/smartflow/backend/respond"
"github.com/LoveLosita/smartflow/backend/service"
"github.com/gin-gonic/gin"
)
type TaskClassHandler struct {
svc *service.TaskClassService
}
// NewTaskClassHandler组装 Handler 的“工厂”
func NewTaskClassHandler(svc *service.TaskClassService) *TaskClassHandler {
return &TaskClassHandler{
svc: svc, // 把传进来的 Service 揣进口袋里
}
}
func (api *TaskClassHandler) UserAddTaskClass(c *gin.Context) {
var req model.UserAddTaskClassRequest
err := c.ShouldBindJSON(&req)
if err != nil {
c.JSON(http.StatusBadRequest, respond.WrongParamType)
return
}
userIDInterface := c.GetInt("user_id")
err = api.svc.AddTaskClass(&req, userIDInterface)
if err != nil {
if errors.Is(err, respond.WrongParamType) {
c.JSON(http.StatusBadRequest, respond.WrongParamType)
return
}
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
}
c.JSON(http.StatusOK, respond.Ok)
}
func (api *TaskClassHandler) UserGetTaskClassInfos(c *gin.Context) {
userIDInterface := c.GetInt("user_id")
resp, err := api.svc.GetUserTaskClassInfos(userIDInterface)
if err != nil {
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
return
}
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, resp))
}