All checks were successful
Dev Build / build-test (pull_request) Successful in 2m39s
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"github.com/CubeCraft-Creations/Extrudex/backend/internal/dtos"
|
|
"github.com/CubeCraft-Creations/Extrudex/backend/internal/repositories"
|
|
)
|
|
|
|
// MaterialFinishHandler handles requests for material finish lookup data.
|
|
type MaterialFinishHandler struct {
|
|
repo *repositories.MaterialFinishRepository
|
|
}
|
|
|
|
// NewMaterialFinishHandler creates a MaterialFinishHandler with the given repository.
|
|
func NewMaterialFinishHandler(repo *repositories.MaterialFinishRepository) *MaterialFinishHandler {
|
|
return &MaterialFinishHandler{repo: repo}
|
|
}
|
|
|
|
// List handles GET /api/finishes — returns all material finishes.
|
|
func (h *MaterialFinishHandler) List(w http.ResponseWriter, r *http.Request) {
|
|
finishes, err := h.repo.GetAll(r.Context())
|
|
if err != nil {
|
|
slog.Error("failed to list finishes", "error", err)
|
|
writeJSON(w, http.StatusInternalServerError, dtos.ErrorResponse{
|
|
Error: "internal server error",
|
|
Code: http.StatusInternalServerError,
|
|
})
|
|
return
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, dtos.SingleResponse{Data: finishes})
|
|
}
|