Version: 0.2.0.dev.260210

feat: 🗑️ 新增删除单个课程与解除安排日程接口

- 逻辑复杂,初版接口写完后才发现需求需要传切片
- 针对需求修改,通过大 for 循环和事务处理来解决问题 🔄

refactor: 🔧 移除部分冗余的用户 ID 验证逻辑

- sv/schedule.go 中,进来的 ID 已通过 redis 黑名单与 JWT 保护验证
- 去除重复的数据库查验,优化了代码流程 🛠️

refactor: 🔄 重构 API 层业务错误判断逻辑

- 抛弃了原有的手动比对方式,封装进 `respond` 包,简化判断流程
- 未来不再手动遍历数据链路,提升了开发效率 🧹

undo: ⚠️ 修复任务块添加到日程的接口问题(待修复)

- 接口允许直接修改已经安排的任务时间,且重复执行时未被禁止
- 此逻辑存在问题,计划在下个版本修复 🔧

undo: ⚠️ 重测接口的幂等性与其他特性

- 当前接口幂等性等特性尚未专门测试,后续计划重测所有接口
- 测试不充分,待进一步完善 🔄

undo: ⚠️ 修复刷新 token 接口错误处理问题

- 当前接口将 token 本身的错误以 500 错误返回,需修复此问题 🛠️
This commit is contained in:
LoveLosita
2026-02-10 19:51:05 +08:00
parent 6d857d16c2
commit d07234e183
13 changed files with 334 additions and 109 deletions

View File

@@ -2,7 +2,6 @@ package api
import (
"context"
"errors"
"net/http"
"strconv"
"time"
@@ -11,7 +10,6 @@ import (
"github.com/LoveLosita/smartflow/backend/respond"
"github.com/LoveLosita/smartflow/backend/service"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type TaskClassHandler struct {
@@ -43,11 +41,8 @@ func (api *TaskClassHandler) UserAddTaskClass(c *gin.Context) {
defer cancel() // 记得释放资源
err = api.svc.AddOrUpdateTaskClass(ctx, &req, userIDInterface, create, 0)
if err != nil {
if errors.Is(err, respond.WrongParamType) {
c.JSON(http.StatusBadRequest, respond.WrongParamType)
return
}
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
respond.DealWithError(c, err)
return
}
c.JSON(http.StatusOK, respond.Ok)
}
@@ -59,7 +54,7 @@ func (api *TaskClassHandler) UserGetTaskClassInfos(c *gin.Context) {
defer cancel() // 记得释放资源
resp, err := api.svc.GetUserTaskClassInfos(ctx, userIDInterface)
if err != nil {
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
respond.DealWithError(c, err)
return
}
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, resp))
@@ -83,11 +78,7 @@ func (api *TaskClassHandler) UserGetCompleteTaskClass(c *gin.Context) {
defer cancel() // 记得释放资源
resp, err := api.svc.GetUserCompleteTaskClass(ctx, userIDInterface, intTaskClassID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
c.JSON(http.StatusNotFound, respond.UserTaskClassNotFound)
return
}
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
respond.DealWithError(c, err)
return
}
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, resp))
@@ -109,11 +100,8 @@ func (api *TaskClassHandler) UserUpdateTaskClass(c *gin.Context) {
defer cancel() // 记得释放资源
err = api.svc.AddOrUpdateTaskClass(ctx, &req, userIDInterface, update, intTaskClassID)
if err != nil {
if errors.Is(err, respond.WrongParamType) || errors.Is(err, respond.UserTaskClassForbidden) {
c.JSON(http.StatusBadRequest, err)
return
}
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
respond.DealWithError(c, err)
return
}
c.JSON(http.StatusOK, respond.Ok)
}
@@ -138,13 +126,7 @@ func (api *TaskClassHandler) UserAddTaskClassItemIntoSchedule(c *gin.Context) {
defer cancel() // 记得释放资源
err = api.svc.AddTaskClassItemIntoSchedule(ctx, &req, userIDInterface, intTaskID)
if err != nil {
if errors.Is(err, respond.TaskClassItemNotBelongToUser) || errors.Is(err, respond.CourseNotBelongToUser) ||
errors.Is(err, respond.CourseAlreadyEmbeddedByOtherTaskBlock) || errors.Is(err, respond.CourseTimeNotMatch) ||
errors.Is(err, respond.ScheduleConflict) || errors.Is(err, respond.WrongCourseID) {
c.JSON(http.StatusBadRequest, err)
return
}
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
respond.DealWithError(c, err)
return
}
c.JSON(http.StatusOK, respond.Ok)