migration to chi

This commit is contained in:
2025-03-12 16:30:40 +03:00
parent ae81fbcce9
commit 45bb32e7a6
46 changed files with 1352 additions and 1323 deletions
+38
View File
@@ -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)
}