Skip to content

Commit

Permalink
feat(person): display total number of credits
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Dec 23, 2023
1 parent 69a7920 commit ed13767
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
15 changes: 14 additions & 1 deletion handlers/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,18 @@ func HandleGetPersonByID(c *fiber.Ctx) error {
return err
}

return utils.TemplRender(c, views.Person(person))
fields := []int{
len(person.Cast),
len(person.Director),
len(person.Writer),
len(person.Producer),
len(person.Composer),
}

totalCredits := 0
for _, field := range fields {
totalCredits += field
}

return utils.TemplRender(c, views.Person(person, totalCredits))
}
6 changes: 5 additions & 1 deletion views/person.templ
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"believer/movies/types"
"believer/movies/components"
"fmt"
"strconv"
)

templ Credit(title string, data types.Movies) {
Expand All @@ -28,12 +29,15 @@ templ Credit(title string, data types.Movies) {
}
}

templ Person(person types.Person) {
templ Person(person types.Person, totalCredits int) {
@Layout(person.Name) {
<div
class="mx-auto flex max-w-xl flex-col gap-8 px-5 py-8"
>
@components.H1(person.Name)
<div>
{ strconv.Itoa(totalCredits) } credits
</div>
@Credit("Cast", person.Cast)
@Credit("Director", person.Director)
@Credit("Writer", person.Writer)
Expand Down
25 changes: 24 additions & 1 deletion views/person_templ.go

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

0 comments on commit ed13767

Please sign in to comment.