🎨 优化查询当日提醒接口

This commit is contained in:
loser 2024-05-09 18:06:45 +08:00
parent 39191484e5
commit 61c0aaa35a

View File

@ -10,6 +10,7 @@ import (
"miniapp/model/common/request"
r "miniapp/model/common/response"
"strconv"
"time"
)
type TodosApi struct{}
@ -79,5 +80,27 @@ func (t TodosApi) GetTodayTodos(ctx *gin.Context) {
return
}
r.OkWithData(list, ctx)
todos := make([]common.UserTodo, 0)
hour := time.Now().Hour()
for i := range list {
//将remind_time截取前两位 转为int
rt, _ := strconv.Atoi(list[i].RemindTime[:2])
rt2 := 24
if i+1 == len(list) {
rt2, _ = strconv.Atoi(list[len(list)-1].RemindTime[:2])
} else {
rt2, _ = strconv.Atoi(list[i+1].RemindTime[:2])
}
if hour >= rt && hour <= rt2 {
todos = append(todos, list[i])
}
}
//删除todos第一个元素
if len(todos) > 0 {
todos = todos[1:]
}
r.OkWithData(todos, ctx)
}