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
35 lines
1013 B
Go
35 lines
1013 B
Go
package handlers
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"github.com/CubeCraft-Creations/Extrudex/backend/internal/dtos"
|
|
"github.com/CubeCraft-Creations/Extrudex/backend/internal/repositories"
|
|
)
|
|
|
|
// MaterialHandler handles requests for material lookup data.
|
|
type MaterialHandler struct {
|
|
repo *repositories.MaterialRepository
|
|
}
|
|
|
|
// NewMaterialHandler creates a MaterialHandler with the given repository.
|
|
func NewMaterialHandler(repo *repositories.MaterialRepository) *MaterialHandler {
|
|
return &MaterialHandler{repo: repo}
|
|
}
|
|
|
|
// List handles GET /api/materials — returns all material bases.
|
|
func (h *MaterialHandler) List(w http.ResponseWriter, r *http.Request) {
|
|
materials, err := h.repo.GetAll(r.Context())
|
|
if err != nil {
|
|
slog.Error("failed to list materials", "error", err)
|
|
writeJSON(w, http.StatusInternalServerError, dtos.ErrorResponse{
|
|
Error: "internal server error",
|
|
Code: http.StatusInternalServerError,
|
|
})
|
|
return
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, dtos.SingleResponse{Data: materials})
|
|
}
|