Add motivation quote feature to smoking tracking API

- Introduced a new database model `SmokeMotivationQuote` for storing motivational quotes.
- Added a new API endpoint `GET /api/v1/smoke/motivation` to retrieve motivation quotes for users.
- Updated the main.go file to include the new model in the auto-migration process.
- Enhanced smoke_routes.go to register the new motivation route with the smoke handler.
This commit is contained in:
nepiedg
2026-01-25 09:53:18 +00:00
parent c9ebfd5873
commit 3154365ab2
5 changed files with 179 additions and 0 deletions
@@ -0,0 +1,33 @@
package handler
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"wx_service/internal/middleware"
"wx_service/internal/model"
)
func (h *SmokeHandler) Motivation(c *gin.Context) {
user, ok := middleware.CurrentUser(c)
if !ok {
c.JSON(http.StatusUnauthorized, model.Error(http.StatusUnauthorized, "未登录或登录已过期"))
return
}
profile, err := h.smokeProfileService.Get(c.Request.Context(), int(user.ID))
if err != nil {
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取基础信息失败,请稍后重试"))
return
}
result, err := h.smokeLogService.Motivation(c.Request.Context(), int(user.ID), time.Now().In(time.Local), profile)
if err != nil {
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "生成激励语失败,请稍后重试"))
return
}
c.JSON(http.StatusOK, model.Success(result))
}