feat: implement filament and spool preset services with CRUD operations

- Add `FilamentService` for managing filament inventory, including creation, retrieval, updating, and deletion of filaments.
- Introduce `SpoolPresetService` for handling spool presets, allowing users to create, update, and delete their custom presets.
- Create domain models for `Filament` and `SpoolPreset` with necessary fields and methods.
- Define repository interfaces for filament and spool preset persistence.
- Implement application configuration management from environment variables.
- Set up error handling with a centralized `AppError` type.
- Build the Axum router with public and protected routes for user authentication and resource management.
This commit is contained in:
2026-03-14 09:38:28 -03:00
parent c90d2f920b
commit abdc2fe8ce
67 changed files with 7832 additions and 0 deletions
@@ -0,0 +1,16 @@
-- Migration: 001 - Criar tabela de usuários
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
email TEXT NOT NULL UNIQUE,
password_hash TEXT,
google_id TEXT UNIQUE,
email_verified BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_users_email ON users (email);
CREATE INDEX idx_users_google_id ON users (google_id) WHERE google_id IS NOT NULL;
@@ -0,0 +1,30 @@
-- Migration: 002 - Criar tabela de presets de carretel e inserir presets do sistema
CREATE TABLE spool_presets (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
spool_weight_g INTEGER NOT NULL CHECK (spool_weight_g > 0),
is_system BOOLEAN NOT NULL DEFAULT FALSE,
user_id UUID REFERENCES users (id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
-- Presets do sistema não têm user_id; presets customizados têm
CONSTRAINT chk_preset_ownership CHECK (
(is_system = TRUE AND user_id IS NULL) OR
(is_system = FALSE AND user_id IS NOT NULL)
)
);
CREATE INDEX idx_spool_presets_user_id ON spool_presets (user_id) WHERE user_id IS NOT NULL;
CREATE INDEX idx_spool_presets_is_system ON spool_presets (is_system);
-- Presets built-in do sistema (somente leitura para usuários)
INSERT INTO spool_presets (name, spool_weight_g, is_system) VALUES
('Bambu Lab (Plástico)', 250, TRUE),
('Elegoo (Papelão)', 200, TRUE),
('Creality (Plástico)', 230, TRUE),
('Prusament (Plástico)', 201, TRUE),
('Sunlu (Papelão)', 200, TRUE),
('Polymaker (Plástico)', 220, TRUE),
('Genérico Papelão 1kg', 200, TRUE),
('Genérico Plástico 1kg', 250, TRUE);
@@ -0,0 +1,26 @@
-- Migration: 003 - Criar tabela de filamentos
CREATE TABLE filaments (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
material TEXT NOT NULL,
brand TEXT NOT NULL,
model TEXT,
color_hex TEXT NOT NULL,
spool_preset_id UUID NOT NULL REFERENCES spool_presets (id),
total_weight_g INTEGER NOT NULL CHECK (total_weight_g > 0),
net_weight_g INTEGER NOT NULL CHECK (net_weight_g >= 0),
temp_hotend_c INTEGER CHECK (temp_hotend_c > 0),
temp_bed_c INTEGER CHECK (temp_bed_c >= 0),
flow_factor_pct DOUBLE PRECISION CHECK (flow_factor_pct > 0),
notes TEXT,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_filaments_user_id ON filaments (user_id);
CREATE INDEX idx_filaments_material ON filaments (user_id, material);
CREATE INDEX idx_filaments_brand ON filaments (user_id, brand);
CREATE INDEX idx_filaments_updated_at ON filaments (user_id, updated_at DESC);
-- Índice para suporte a alertas de estoque baixo
CREATE INDEX idx_filaments_net_weight ON filaments (user_id, net_weight_g);