Skip to content

Commit

Permalink
chore: clean up routing
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Sep 12, 2024
1 parent dd52a91 commit 308f5c7
Show file tree
Hide file tree
Showing 22 changed files with 70 additions and 60 deletions.
2 changes: 1 addition & 1 deletion components/list.templ
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ templ OrderedList(data []ListItem, listType string) {
data-position={ strconv.Itoa(i + 1) }
>
if listType == "movie" {
@Link(LinkProps{Href: fmt.Sprintf("/movies/%s", item.ID)}) {
@Link(LinkProps{Href: fmt.Sprintf("/movie/%s", item.ID)}) {
{ item.Name }
}
} else if listType == "person" {
Expand Down
2 changes: 1 addition & 1 deletion components/list_templ.go

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

12 changes: 7 additions & 5 deletions components/movieExists.templ
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package components

import "believer/movies/types"
import "fmt"
import (
"believer/movies/types"
"fmt"
)

templ MovieExists(movie types.Movie) {
<strong>{ movie.Title }</strong> exists in your library. Would you like to
<a
href="#"
hx-post={ fmt.Sprintf("/movies/%d/seen", movie.ID) }
class="border-b border-dashed border-neutral-500 dark:border-neutral-400"
href="#"
hx-post={ fmt.Sprintf("/movie/%d/seen", movie.ID) }
class="border-b border-dashed border-neutral-500 dark:border-neutral-400"
>add a new watch</a>
?
}
12 changes: 7 additions & 5 deletions components/movieExists_templ.go

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

8 changes: 4 additions & 4 deletions components/watched.templ
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package components

import (
"time"
"fmt"
"time"
)

templ Watched(watchedAt []time.Time, isAdmin bool, id string) {
Expand All @@ -15,9 +15,9 @@ templ Watched(watchedAt []time.Time, isAdmin bool, id string) {
if isAdmin {
<li>
<a
href="#"
hx-post={ fmt.Sprintf("/movies/%s/seen", id) }
class="truncate border-b border-dashed border-neutral-500 focus:outline-none focus-visible:rounded-sm focus-visible:outline-dashed focus-visible:outline-offset-2 focus-visible:outline-neutral-400 dark:border-neutral-400 dark:focus-visible:outline-neutral-600"
href="#"
hx-post={ fmt.Sprintf("/movie/%s/seen", id) }
class="truncate border-b border-dashed border-neutral-500 focus:outline-none focus-visible:rounded-sm focus-visible:outline-dashed focus-visible:outline-offset-2 focus-visible:outline-neutral-400 dark:border-neutral-400 dark:focus-visible:outline-neutral-600"
>
Add new watch
</a>
Expand Down
4 changes: 2 additions & 2 deletions components/watched_templ.go

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

4 changes: 2 additions & 2 deletions handlers/movies.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func HandlePostMovieNew(c *fiber.Ctx) error {
return err
}

c.Set("HX-Redirect", fmt.Sprintf("/movies/%d?back=true", movieId))
c.Set("HX-Redirect", fmt.Sprintf("/movie/%d?back=true", movieId))

return c.SendStatus(fiber.StatusOK)
}
Expand Down Expand Up @@ -535,7 +535,7 @@ func HandlePostMovieSeenNew(c *fiber.Ctx) error {
return err
}

c.Set("HX-Redirect", fmt.Sprintf("/movies/%s?back=true", c.Params("id")))
c.Set("HX-Redirect", fmt.Sprintf("/movie/%s?back=true", c.Params("id")))

return c.SendStatus(fiber.StatusOK)
}
Expand Down
10 changes: 8 additions & 2 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ func SetupRoutes(app *fiber.App) {

// Movies
// --------------------------
movieGroup := app.Group("/movies")
movieGroup := app.Group("/movie")

movieGroup.Get("/", redirectToHome)
movieGroup.Get("/imdb", handlers.HandleGetByImdbId)
movieGroup.Get("/search", handlers.HandleSearchNew)
movieGroup.Get("/new", handlers.HandleGetMovieNew)
movieGroup.Post("/new", handlers.HandlePostMovieNew)
movieGroup.Get("/year/:year", handlers.HandleGetMoviesByYear)

movieGroup.Get("/:id", handlers.HandleGetMovieByID)
movieGroup.Get("/:id/cast", handlers.HandleGetMovieCastByID)
movieGroup.Get("/:id/seen", handlers.HandleGetMovieSeenByID)
movieGroup.Post("/:id/seen", handlers.HandlePostMovieSeenNew)

// Year
// --------------------------
yearGroup := app.Group("/year")

yearGroup.Get("/", redirectToHome)
yearGroup.Get("/:year", handlers.HandleGetMoviesByYear)

// Person
// --------------------------
personGroup := app.Group("/person")
Expand Down
6 changes: 3 additions & 3 deletions views/feed.templ
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ templ Feed(isAdmin bool, movies types.Movies, nextPage int, query string) {
<div class="md:absolute right-8 top-10 flex gap-4 items-center">
<a
class="fixed bottom-8 right-8 z-10 bg-neutral-700 w-14 h-14 shadow-md flex justify-center items-center rounded-full sm:bg-transparent sm:bottom-0 sm:right-0 sm:w-auto sm:h-auto sm:relative focus:outline-none focus-visible:outline-dashed focus-visible:outline-offset-8 focus-visible:outline-neutral-400 dark:focus-visible:outline-neutral-600"
href="/movies/new"
href="/movie/new"
>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down Expand Up @@ -85,7 +85,7 @@ init if my @data-year is not really equal to @data-year of previous <li/> then
then
make an <a.year/>
put the @data-year into its textContent
put `/movies/year/${dataYear}` into its href
put `/year/${dataYear}` into its href
put it into the previous <li/>
end
end
Expand All @@ -108,7 +108,7 @@ end
"
>
<a
href={ templ.URL(fmt.Sprintf("/movies/%d", movie.ID)) }
href={ templ.URL(fmt.Sprintf("/movie/%d", movie.ID)) }
class="flex flex-col gap-4 rounded focus:outline-none focus-visible:outline-dashed focus-visible:outline-offset-8 focus-visible:outline-neutral-400 dark:focus-visible:outline-neutral-600"
>
<header class="flex flex-col gap-1">
Expand Down
6 changes: 3 additions & 3 deletions views/feed_templ.go

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

2 changes: 1 addition & 1 deletion views/genre.templ
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ templ Genre(props GenreProps) {
<ol class="flex flex-col gap-2 md:text-sm text-neutral-500 dark:text-neutral-400">
for _, movie := range props.Movies {
<li class="flex items-end justify-between gap-4">
@components.Link(components.LinkProps{Href: fmt.Sprintf("/movies/%d", movie.ID)}) {
@components.Link(components.LinkProps{Href: fmt.Sprintf("/movie/%d", movie.ID)}) {
{ movie.Title }
}
@components.Divider()
Expand Down
2 changes: 1 addition & 1 deletion views/genre_templ.go

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

6 changes: 3 additions & 3 deletions views/movie.templ
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ templ Movie(movie types.Movie, back bool) {
@components.DescriptionListItem(components.DescriptionListItemProps{Detail: "Release date", IsTabular: true}) {
<a
class="inline-flex items-center gap-1 focus:outline-none focus-visible:rounded-sm focus-visible:outline-dashed focus-visible:outline-offset-2 focus-visible:outline-neutral-400 dark:focus-visible:outline-neutral-600 border-b border-dashed border-neutral-500 dark:border-neutral-400"
href={ templ.URL(fmt.Sprintf("/movies/year/%s", movie.ReleaseDate.Format("2006"))) }
href={ templ.URL(fmt.Sprintf("/year/%s", movie.ReleaseDate.Format("2006"))) }
>
{ movie.ReleaseDate.Format("2006-01-02") }
</a>
Expand Down Expand Up @@ -81,12 +81,12 @@ templ Movie(movie types.Movie, back bool) {
}
}
@components.DescriptionListItem(components.DescriptionListItemProps{Detail: "Watched", IsTabular: false}) {
<span hx-get={ fmt.Sprintf("/movies/%d/seen", movie.ID) } hx-trigger="load"></span>
<span hx-get={ fmt.Sprintf("/movie/%d/seen", movie.ID) } hx-trigger="load"></span>
}
}
}
<div
hx-get={ fmt.Sprintf("/movies/%d/cast", movie.ID) }
hx-get={ fmt.Sprintf("/movie/%d/cast", movie.ID) }
hx-trigger="load"
hx-swap="outerHTML"
></div>
Expand Down
10 changes: 5 additions & 5 deletions views/movie_templ.go

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

2 changes: 1 addition & 1 deletion views/moviesByYear.templ
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ templ MoviesByYear(year string, movies []types.Movie) {
<ol class="flex flex-col gap-2 md:text-sm text-neutral-500 dark:text-neutral-400">
for _, movie := range movies {
<li class="flex items-end justify-between gap-4">
@components.Link(components.LinkProps{Href: fmt.Sprintf("/movies/%d", movie.ID)}) {
@components.Link(components.LinkProps{Href: fmt.Sprintf("/movie/%d", movie.ID)}) {
{ movie.Title }
}
@components.Divider()
Expand Down
2 changes: 1 addition & 1 deletion views/moviesByYear_templ.go

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

6 changes: 3 additions & 3 deletions views/newMovie.templ
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "believer/movies/components"
templ NewMovie() {
@Layout("Add movie", "") {
<form
hx-post="/movies/new"
hx-post="/movie/new"
hx-indicator="#sending"
class="mx-auto flex max-w-xl flex-col gap-6 px-4 py-8"
>
Expand All @@ -18,7 +18,7 @@ templ NewMovie() {
@components.Label("search", "Search")
<input
type="text"
hx-get="/movies/search"
hx-get="/movie/search"
hx-trigger="keyup changed delay:500ms"
hx-target="#search-results"
hx-validate="true"
Expand All @@ -37,7 +37,7 @@ templ NewMovie() {
<input
required
type="text"
hx-get="/movies/imdb"
hx-get="/movie/imdb"
hx-trigger="blur changed"
hx-target="#movie-exists"
hx-validate="true"
Expand Down
Loading

0 comments on commit 308f5c7

Please sign in to comment.