CUB-113: implement core CRUD API endpoints
Some checks failed
Dev Build / build-test (pull_request) Failing after 2m4s

- Add dtos package with request/response structs
- Add repositories: Material, Filament, Printer, PrintJob, UsageLog
- Add services: FilamentService, PrinterService, PrintJobService
- Add handlers for all 5 resources with consistent error responses
- Wire all endpoints into Chi router under /api
- Validation on POST/PUT filament endpoints
- Filter/pagination support on list endpoints
- Soft-delete for filaments (DELETE /api/filaments/{id})
- go build ./... && go vet ./... → PASS
This commit is contained in:
2026-05-06 14:24:58 -04:00
parent 1b86d617cd
commit fca2ef5b84
19 changed files with 1496 additions and 3 deletions

View File

@@ -1,12 +1,13 @@
package router
import (
"log/slog"
"net/http"
"time"
"github.com/CubeCraft-Creations/Extrudex/backend/internal/config"
"github.com/CubeCraft-Creations/Extrudex/backend/internal/handlers"
"github.com/CubeCraft-Creations/Extrudex/backend/internal/repositories"
"github.com/CubeCraft-Creations/Extrudex/backend/internal/services"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/jackc/pgx/v5/pgxpool"
@@ -41,5 +42,43 @@ func New(cfg *config.Config, dbPool *pgxpool.Pool) chi.Router {
healthHandler := handlers.NewHealthHandler(dbPool)
r.Get("/health", healthHandler.ServeHTTP)
// ── Repositories ──────────────────────────────────────────────────────
materialRepo := repositories.NewMaterialRepository(dbPool)
filamentRepo := repositories.NewFilamentRepository(dbPool)
printerRepo := repositories.NewPrinterRepository(dbPool)
printJobRepo := repositories.NewPrintJobRepository(dbPool)
usageLogRepo := repositories.NewUsageLogRepository(dbPool)
// ── Services ──────────────────────────────────────────────────────────
filamentService := services.NewFilamentService(filamentRepo)
printerService := services.NewPrinterService(printerRepo)
printJobService := services.NewPrintJobService(printJobRepo)
// ── Handlers ──────────────────────────────────────────────────────────
materialHandler := handlers.NewMaterialHandler(materialRepo)
filamentHandler := handlers.NewFilamentHandler(filamentService)
printerHandler := handlers.NewPrinterHandler(printerService)
printJobHandler := handlers.NewPrintJobHandler(printJobService)
usageLogHandler := handlers.NewUsageLogHandler(usageLogRepo)
// ── API Routes ────────────────────────────────────────────────────────
r.Route("/api", func(r chi.Router) {
r.Get("/materials", materialHandler.List)
r.Route("/filaments", func(r chi.Router) {
r.Get("/", filamentHandler.List)
r.Post("/", filamentHandler.Create)
r.Route("/{id}", func(r chi.Router) {
r.Get("/", filamentHandler.Get)
r.Put("/", filamentHandler.Update)
r.Delete("/", filamentHandler.Delete)
})
})
r.Get("/printers", printerHandler.List)
r.Get("/print-jobs", printJobHandler.List)
r.Get("/usage-logs", usageLogHandler.List)
})
return r
}