2024-05-16 18:42:31 +02:00
|
|
|
package api
|
2024-05-16 17:59:21 +02:00
|
|
|
|
|
|
|
|
import (
|
2025-05-07 22:33:21 +02:00
|
|
|
"log"
|
2024-05-16 17:59:21 +02:00
|
|
|
"net/http"
|
|
|
|
|
"portfolio/api/handlers"
|
|
|
|
|
)
|
|
|
|
|
|
2025-02-24 00:18:04 +01:00
|
|
|
func Routes() *http.ServeMux {
|
2025-05-07 22:33:21 +02:00
|
|
|
log.Println("Setup web routes")
|
2024-05-16 17:59:21 +02:00
|
|
|
// Create a new request multiplexer
|
|
|
|
|
// Take incoming requests and dispatch them to the matching webHandler
|
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
2024-05-19 23:56:53 +02:00
|
|
|
// routes
|
2024-05-16 18:42:31 +02:00
|
|
|
mux.HandleFunc("/", handlers.CatchAllHandler)
|
2024-05-19 23:56:53 +02:00
|
|
|
mux.HandleFunc("GET /check", handlers.CheckRoleHandler)
|
|
|
|
|
|
|
|
|
|
//user
|
2024-06-24 15:23:38 +02:00
|
|
|
mux.HandleFunc("GET /user/{id}", handlers.GetUserHandler)
|
2024-05-19 23:56:53 +02:00
|
|
|
|
|
|
|
|
//auth
|
2024-05-19 17:49:20 +02:00
|
|
|
mux.HandleFunc("POST /login", handlers.Login)
|
2024-06-24 15:23:38 +02:00
|
|
|
mux.HandleFunc("POST /register", handlers.CreateUserHandler)
|
2024-06-25 00:26:56 +02:00
|
|
|
mux.HandleFunc("GET /htmx/canEdit", handlers.CanEdit)
|
2024-06-24 15:23:38 +02:00
|
|
|
|
|
|
|
|
//Project
|
|
|
|
|
mux.HandleFunc("POST /project", handlers.CreateProjectHandler)
|
|
|
|
|
mux.HandleFunc("PATCH /project/{id}", handlers.UpdateProjectHandler)
|
2024-07-04 12:02:43 +02:00
|
|
|
mux.HandleFunc("PATCH /projects", handlers.UpdateProjectsHandler)
|
2024-06-24 15:23:38 +02:00
|
|
|
mux.HandleFunc("GET /project/{id}", handlers.GetProjectHandler)
|
|
|
|
|
mux.HandleFunc("GET /projects", handlers.GetProjectsHandler)
|
2024-09-12 15:34:45 +02:00
|
|
|
mux.HandleFunc("GET /projects/backup", handlers.GetProjectsBackupHandler)
|
2024-05-16 17:59:21 +02:00
|
|
|
|
|
|
|
|
return mux
|
|
|
|
|
}
|