list all (wip)

This commit is contained in:
2025-10-21 19:39:49 +02:00
parent ec631e3c3a
commit 381a4e4988
4 changed files with 225 additions and 21 deletions

View File

@@ -43,6 +43,7 @@ func NewServer(data *storage.Repository, port int) *HTTPServer {
// Get information about the server
r.Get("/version", s.Information)
r.Route("/projects", func(r chi.Router) {
r.Get("/all", s.ProjectsHandler)
r.Get("/{name}", func(w http.ResponseWriter, r *http.Request) {})
r.Post("/{name}", s.ProjectPostHandler)
r.Delete("/{name}", func(w http.ResponseWriter, r *http.Request) {})
@@ -91,3 +92,14 @@ func (s *HTTPServer) ProjectPostHandler(w http.ResponseWriter, r *http.Request)
w.WriteHeader(201)
}
func (s *HTTPServer) ProjectsHandler(w http.ResponseWriter, r *http.Request) {
prs, err := s.data.List()
if err != nil {
slog.Error("failed to fetch all the projects from the database", "err", err)
internalServerError(err, w, r)
return
}
ok(prs, w, r)
}