Skip to content

Commit

Permalink
feat(stats): display wilhelm screams
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Sep 15, 2024
1 parent ef302ed commit 0b3ef2f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
10 changes: 10 additions & 0 deletions db/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,13 @@ WHERE
user_id = $1
AND movie_id = $2;

-- name: wilhelm-screams
SELECT
count(*)
FROM
seen s
INNER JOIN movie m ON m.id = s.movie_id
WHERE
user_id = $1
AND m.wilhelm = TRUE;

9 changes: 9 additions & 0 deletions handlers/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func HandleGetStats(c *fiber.Ctx) error {
var stats types.Stats
var movies []components.ListItem
var shortestAndLongest types.Movies
var wilhelms []int

userId := c.Locals("UserId").(string)
now := time.Now()
Expand Down Expand Up @@ -104,6 +105,13 @@ func HandleGetStats(c *fiber.Ctx) error {
return err
}

err = db.Dot.Select(db.Client, &wilhelms, "wilhelm-screams", userId)

if err != nil {
log.Fatalf("Error getting wilhelm scream: %v", err)
return err
}

var bestOfTheYear types.Movie
err = db.Dot.Get(db.Client, &bestOfTheYear, "stats-best-of-the-year", userId)

Expand Down Expand Up @@ -138,6 +146,7 @@ func HandleGetStats(c *fiber.Ctx) error {
YearRatings: yearRatings,
Years: availableYears(),
ShortestAndLongestMovie: shortestAndLongest,
WilhelmScreams: wilhelms[0],
}))
}

Expand Down
9 changes: 9 additions & 0 deletions views/stats.templ
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type StatsProps struct {
ShortestAndLongestMovie types.Movies
Stats types.Stats
WatchedByYear []types.Bar
WilhelmScreams int
Year string
YearRatings []types.Bar
Years []int
Expand Down Expand Up @@ -65,6 +66,14 @@ templ Stats(props StatsProps) {
}) {
{ props.FormattedTotalRuntime }
}
if props.WilhelmScreams > 0 {
@components.DescriptionListItem(components.DescriptionListItemProps{
Detail: "Wilhelm screams",
IsTabular: true,
}) {
{ strconv.Itoa(props.WilhelmScreams) }
}
}
@components.DescriptionListItem(components.DescriptionListItemProps{
Detail: "Top IMDb rating",
}) {
Expand Down
39 changes: 38 additions & 1 deletion views/stats_templ.go

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

0 comments on commit 0b3ef2f

Please sign in to comment.