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
68 lines
3.0 KiB
Go
68 lines
3.0 KiB
Go
// Package dtos defines request/response data transfer objects for the Extrudex API.
|
|
// DTOs keep HTTP serialization concerns separate from domain models.
|
|
package dtos
|
|
|
|
// ============================================================================
|
|
// Common Response Wrappers
|
|
// ============================================================================
|
|
|
|
// ListResponse wraps a paginated collection response.
|
|
type ListResponse struct {
|
|
Data any `json:"data"`
|
|
Total int `json:"total"`
|
|
Limit int `json:"limit"`
|
|
Offset int `json:"offset"`
|
|
}
|
|
|
|
// SingleResponse wraps a single-item response.
|
|
type SingleResponse struct {
|
|
Data any `json:"data"`
|
|
}
|
|
|
|
// ErrorResponse is the standard error payload for all API errors.
|
|
type ErrorResponse struct {
|
|
Error string `json:"error"`
|
|
Code int `json:"code"`
|
|
}
|
|
|
|
// ============================================================================
|
|
// Filament DTOs
|
|
// ============================================================================
|
|
|
|
// CreateFilamentRequest is the POST body for creating a new filament spool.
|
|
type CreateFilamentRequest struct {
|
|
Name string `json:"name"`
|
|
MaterialBaseID int `json:"material_base_id"`
|
|
MaterialFinishID int `json:"material_finish_id"`
|
|
MaterialModifierID *int `json:"material_modifier_id,omitempty"`
|
|
ColorHex string `json:"color_hex"`
|
|
Brand *string `json:"brand,omitempty"`
|
|
DiameterMM *float64 `json:"diameter_mm,omitempty"` // defaults to 1.75
|
|
InitialGrams int `json:"initial_grams"`
|
|
RemainingGrams int `json:"remaining_grams"`
|
|
SpoolWeightGrams *int `json:"spool_weight_grams,omitempty"`
|
|
CostUSD *float64 `json:"cost_usd,omitempty"`
|
|
LowStockThresholdGrams *int `json:"low_stock_threshold_grams,omitempty"` // defaults to 50
|
|
Notes *string `json:"notes,omitempty"`
|
|
Barcode *string `json:"barcode,omitempty"`
|
|
}
|
|
|
|
// UpdateFilamentRequest is the PUT body for partially updating a filament spool.
|
|
// All fields are optional — only non-nil fields are applied.
|
|
type UpdateFilamentRequest struct {
|
|
Name *string `json:"name,omitempty"`
|
|
MaterialBaseID *int `json:"material_base_id,omitempty"`
|
|
MaterialFinishID *int `json:"material_finish_id,omitempty"`
|
|
MaterialModifierID *int `json:"material_modifier_id,omitempty"`
|
|
ColorHex *string `json:"color_hex,omitempty"`
|
|
Brand *string `json:"brand,omitempty"`
|
|
DiameterMM *float64 `json:"diameter_mm,omitempty"`
|
|
InitialGrams *int `json:"initial_grams,omitempty"`
|
|
RemainingGrams *int `json:"remaining_grams,omitempty"`
|
|
SpoolWeightGrams *int `json:"spool_weight_grams,omitempty"`
|
|
CostUSD *float64 `json:"cost_usd,omitempty"`
|
|
LowStockThresholdGrams *int `json:"low_stock_threshold_grams,omitempty"`
|
|
Notes *string `json:"notes,omitempty"`
|
|
Barcode *string `json:"barcode,omitempty"`
|
|
}
|