feat: 添加用户记账连击(streak)功能,包括服务、处理器、模型和仓库层。

This commit is contained in:
2026-01-28 10:32:05 +08:00
parent e811256d99
commit 0d21b9444e
4 changed files with 81 additions and 0 deletions

View File

@@ -66,8 +66,27 @@ func (h *StreakHandler) RecalculateStreak(c *gin.Context) {
api.Success(c, streakInfo)
}
// GetContributionData handles GET /api/v1/user/streak/contribution
// Returns daily contribution data for heat map
func (h *StreakHandler) GetContributionData(c *gin.Context) {
userID, exists := c.Get("user_id")
if !exists {
api.Unauthorized(c, "User not authenticated")
return
}
contributionData, err := h.streakService.GetContributionData(userID.(uint))
if err != nil {
api.InternalError(c, "Failed to get contribution data: "+err.Error())
return
}
api.Success(c, contributionData)
}
// RegisterRoutes registers streak-related routes
func (h *StreakHandler) RegisterRoutes(rg *gin.RouterGroup) {
rg.GET("/user/streak", h.GetStreak)
rg.POST("/user/streak/recalculate", h.RecalculateStreak)
rg.GET("/user/streak/contribution", h.GetContributionData)
}