migration to chi
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"backend/database"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RegisterClubRoutes(r chi.Router) {
|
||||
r.Route("/", func(s chi.Router) {
|
||||
s.Get("/", getClubs)
|
||||
})
|
||||
r.Route("/{id:[0-9]+}", func(s chi.Router) {
|
||||
s.Get("/", getClub)
|
||||
})
|
||||
}
|
||||
|
||||
func getClubs(w http.ResponseWriter, r *http.Request) {
|
||||
userId, err := GetCurrentUserID(r)
|
||||
if err != nil {
|
||||
Error(w, err)
|
||||
return
|
||||
}
|
||||
clubs, err := database.GetClubs(int(userId))
|
||||
Response(w, err, clubs)
|
||||
}
|
||||
|
||||
func getClub(w http.ResponseWriter, r *http.Request) {
|
||||
id := IURLParam(r, "id")
|
||||
|
||||
userId, err := GetCurrentUserID(r)
|
||||
if err != nil {
|
||||
Error(w, err)
|
||||
return
|
||||
}
|
||||
club, err := database.GetClub(id, userId)
|
||||
Response(w, err, club)
|
||||
}
|
||||
Reference in New Issue
Block a user