migration to chi
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"backend/database"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RegisterGenresRoutes(r chi.Router) {
|
||||
r.Route("/", func(s chi.Router) {
|
||||
s.Get("/", getGenres)
|
||||
s.Post("/", addGenre)
|
||||
})
|
||||
r.Route("/{id:[0-9]+}", func(s chi.Router) {
|
||||
s.Get("/", getGenre)
|
||||
})
|
||||
r.Route("/{id:[0-9]+}/novels", func(s chi.Router) {
|
||||
s.Get("/", getGenreNovels)
|
||||
})
|
||||
}
|
||||
|
||||
func getGenres(w http.ResponseWriter, r *http.Request) {
|
||||
genres, err := database.FetchGenres()
|
||||
Response(w, err, genres)
|
||||
}
|
||||
func addGenre(w http.ResponseWriter, r *http.Request) {
|
||||
RawError(w, "method not implemented")
|
||||
}
|
||||
|
||||
func getGenre(w http.ResponseWriter, r *http.Request) {
|
||||
id := IURLParam(r, "id")
|
||||
|
||||
genre, err := database.FetchGenre(id)
|
||||
Response(w, err, genre)
|
||||
}
|
||||
|
||||
func getGenreNovels(w http.ResponseWriter, r *http.Request) {
|
||||
id := IURLParam(r, "id")
|
||||
|
||||
novels, err := database.FetchGenreNovels(id)
|
||||
Response(w, err, novels)
|
||||
}
|
||||
Reference in New Issue
Block a user