Version: 0.1.4.dev.260208

feat: 📆 新增查看用户整周日程接口
This commit is contained in:
LoveLosita
2026-02-08 20:22:49 +08:00
parent 79b6be5f40
commit 6d857d16c2
7 changed files with 203 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http"
"strconv"
"time"
"github.com/LoveLosita/smartflow/backend/respond"
@@ -42,3 +43,30 @@ func (s *ScheduleAPI) GetUserTodaySchedule(c *gin.Context) {
//3.返回日程安排数据给前端
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, todaySchedules))
}
func (s *ScheduleAPI) GetUserWeeklySchedule(c *gin.Context) {
// 1. 从请求上下文中获取用户ID
userID := c.GetInt("user_id")
// 2. 从查询参数中获取 week 参数
week, err := strconv.Atoi(c.Query("week"))
if err != nil {
c.JSON(http.StatusBadRequest, respond.WrongParamType)
return
}
//3.调用服务层方法获取用户当周的日程安排
ctx, cancel := context.WithTimeout(c.Request.Context(), 1*time.Second)
defer cancel() // 记得释放资源
weeklySchedules, err := s.scheduleService.GetUserWeeklySchedule(ctx, userID, week)
if err != nil {
switch {
case errors.Is(err, respond.WrongUserID), errors.Is(err, respond.WeekOutOfRange):
c.JSON(http.StatusBadRequest, err)
return
default:
c.JSON(http.StatusInternalServerError, respond.InternalError(err))
return
}
}
//4.返回日程安排数据给前端
c.JSON(http.StatusOK, respond.RespWithData(respond.Ok, weeklySchedules))
}