feat(todo-api): add full-stack POC demonstrating micro-lib v0.9.0
Runnable REST API exercising every micro-lib tier in a containerless setup: N-layer architecture, SQLite persistence, header-based auth simulating Firebase output, and bit-mask RBAC enforcement. What's included: - cmd/todo-api: minimal main delegating to application.Run - internal/application: full object graph wiring — launcher, sqlite, httpserver, httpmw stack, routes in BeforeStart - internal/domain: User entity, ResourceTodos constant, PermReadTodo/PermWriteTodo bit positions - internal/repository: TodoRepository, UserRepository, DBPermissionProvider (SQLite via modernc) - internal/service: TodoService, UserService with interface-based dependencies - internal/handler: TodoHandler, UserHandler using httputil adapters and valid for input validation - internal/middleware: Auth (X-User-ID → rbac.Identity) and Require (bit-mask permission gate) - logAdapter: bridges logz.Logger.With return type to httpmw.Logger interface - SQLite schema: users, user_role (bitmask), todos; migrations run in BeforeStart - Routes: POST /users (open), GET+POST /todos (RBAC), GET /users (RBAC) Tested-via: todo-api POC integration Reviewed-against: docs/adr/
This commit is contained in:
36
internal/service/todo_service.go
Normal file
36
internal/service/todo_service.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.nochebuena.dev/go/todo-api/internal/domain"
|
||||
"code.nochebuena.dev/go/todo-api/internal/repository"
|
||||
)
|
||||
|
||||
// CreateTodoRequest is the input for creating a new todo.
|
||||
type CreateTodoRequest struct {
|
||||
Title string `json:"title" validate:"required,min=1,max=255"`
|
||||
}
|
||||
|
||||
// TodoService handles todo business logic.
|
||||
type TodoService interface {
|
||||
FindAll(ctx context.Context) ([]domain.Todo, error)
|
||||
Create(ctx context.Context, req CreateTodoRequest) (domain.Todo, error)
|
||||
}
|
||||
|
||||
type todoService struct {
|
||||
repo repository.TodoRepository
|
||||
}
|
||||
|
||||
// NewTodoService returns a TodoService backed by the given repository.
|
||||
func NewTodoService(repo repository.TodoRepository) TodoService {
|
||||
return &todoService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *todoService) FindAll(ctx context.Context) ([]domain.Todo, error) {
|
||||
return s.repo.FindAll(ctx)
|
||||
}
|
||||
|
||||
func (s *todoService) Create(ctx context.Context, req CreateTodoRequest) (domain.Todo, error) {
|
||||
return s.repo.Create(ctx, domain.Todo{Title: req.Title})
|
||||
}
|
||||
Reference in New Issue
Block a user