Skip to content
Open

Stats #1022

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"axios": "^1.9.0",
"blurhash": "^2.0.5",
"chart.js": "^4.5.1",
"papaparse": "^5.4.1"
}
}
22 changes: 22 additions & 0 deletions server/feature/profile/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/sbondCo/Watcharr/database/entity"
"github.com/sbondCo/Watcharr/feature/auth/authmiddleware"
"github.com/sbondCo/Watcharr/router"
)
Expand All @@ -25,6 +26,8 @@ func (r *Router) AddRoutes() {

// Get user profile details
profile.GET("", r.GetProfile)
// Get user stats
profile.GET("/stats", r.GetStats)
}

// Get user profile details
Expand All @@ -37,3 +40,22 @@ func (r *Router) GetProfile(c *gin.Context) {
}
c.JSON(http.StatusOK, response)
}

// Get user stats
func (r *Router) GetStats(c *gin.Context) {
userId := c.MustGet("userId").(uint)
contentType := c.DefaultQuery("type", "movie")
var ct entity.ContentType
switch contentType {
case "tv":
ct = entity.SHOW
default:
ct = entity.MOVIE
Comment on lines +50 to +53

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "type" query parameter falls back to MOVIE for any unrecognized value, which can hide client bugs and make the endpoint behavior ambiguous. Consider validating the query strictly (only allow "movie"/"tv") and returning a 400 with a clear error for invalid values.

Suggested change
case "tv":
ct = entity.SHOW
default:
ct = entity.MOVIE
case "movie":
ct = entity.MOVIE
case "tv":
ct = entity.SHOW
default:
c.JSON(http.StatusBadRequest, router.ErrorResponse{Error: "invalid type parameter, must be 'movie' or 'tv'"})
return

Copilot uses AI. Check for mistakes.
}
response, err := r.service.getStats(userId, ct)
if err != nil {
c.JSON(http.StatusInternalServerError, router.ErrorResponse{Error: err.Error()})
return
}
c.JSON(http.StatusOK, response)
}
Loading