74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"wx_service/internal/middleware"
|
|
"wx_service/internal/model"
|
|
service "wx_service/internal/quitcheckin/service"
|
|
)
|
|
|
|
// GetReminderSettings GET /api/v2/supervisor/reminders/settings
|
|
// owner 读取自己的提醒设置。
|
|
func (h *Handler) GetReminderSettings(c *gin.Context) {
|
|
user := middleware.MustCurrentUser(c)
|
|
|
|
res, err := h.service.GetReminderSettings(c.Request.Context(), int(user.ID))
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取提醒设置失败,请稍后重试"))
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.Success(res))
|
|
}
|
|
|
|
type updateReminderSettingsRequest struct {
|
|
Enabled *bool `json:"enabled"`
|
|
NotifyTime *string `json:"notify_time"`
|
|
MaxPerDay *int `json:"max_per_day"`
|
|
}
|
|
|
|
// UpdateReminderSettings PUT /api/v2/supervisor/reminders/settings
|
|
func (h *Handler) UpdateReminderSettings(c *gin.Context) {
|
|
user := middleware.MustCurrentUser(c)
|
|
|
|
var req updateReminderSettingsRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "请求参数错误"))
|
|
return
|
|
}
|
|
|
|
// basic trim
|
|
if req.NotifyTime != nil {
|
|
v := strings.TrimSpace(*req.NotifyTime)
|
|
req.NotifyTime = &v
|
|
}
|
|
|
|
res, err := h.service.UpdateReminderSettings(c.Request.Context(), int(user.ID), service.UpdateReminderSettingsRequest{
|
|
Enabled: req.Enabled,
|
|
NotifyTime: req.NotifyTime,
|
|
MaxPerDay: req.MaxPerDay,
|
|
}, time.Now())
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "保存提醒设置失败"))
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.Success(res))
|
|
}
|
|
|
|
// RunReminders POST /api/v2/supervisor/reminders/run
|
|
// supervisor 手动触发提醒(开发/测试用):只会给“当前用户作为监督人”的绑定关系写 reminder_log。
|
|
func (h *Handler) RunReminders(c *gin.Context) {
|
|
user := middleware.MustCurrentUser(c)
|
|
|
|
res, err := h.service.RunMissedCheckinRemindersForSupervisor(c.Request.Context(), int(user.ID), time.Now())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "触发提醒失败,请稍后重试"))
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.Success(res))
|
|
}
|