- Cria README.md na raiz com visão global e diagrama de arquitetura - Adiciona/atualiza README.md em todos os componentes: - backend (API Go) - backoffice (NestJS) - marketplace (React/Vite) - saveinmed-bff (Python/FastAPI) - saveinmed-frontend (Next.js) - website (Fresh/Deno) - Atualiza .gitignore em todos os componentes com regras abrangentes - Cria .gitignore na raiz do projeto - Renomeia pastas para melhor organização: - backend-go → backend - backend-nest → backoffice - marketplace-front → marketplace - Documenta arquitetura, tecnologias, setup e fluxo de desenvolvimento
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gofrs/uuid/v5"
|
|
|
|
"github.com/saveinmed/backend-go/internal/domain"
|
|
)
|
|
|
|
// Repository defines DB contract for the core entities.
|
|
type Repository interface {
|
|
CreateCompany(ctx context.Context, company *domain.Company) error
|
|
ListCompanies(ctx context.Context) ([]domain.Company, error)
|
|
|
|
CreateProduct(ctx context.Context, product *domain.Product) error
|
|
ListProducts(ctx context.Context) ([]domain.Product, error)
|
|
|
|
CreateOrder(ctx context.Context, order *domain.Order) error
|
|
GetOrder(ctx context.Context, id uuid.UUID) (*domain.Order, error)
|
|
UpdateOrderStatus(ctx context.Context, id uuid.UUID, status domain.OrderStatus) error
|
|
}
|
|
|
|
// PaymentGateway abstracts Mercado Pago integration.
|
|
type PaymentGateway interface {
|
|
CreatePreference(ctx context.Context, order *domain.Order) (*domain.PaymentPreference, error)
|
|
}
|
|
|
|
type Service struct {
|
|
repo Repository
|
|
pay PaymentGateway
|
|
}
|
|
|
|
// NewService wires use cases together.
|
|
func NewService(repo Repository, pay PaymentGateway) *Service {
|
|
return &Service{repo: repo, pay: pay}
|
|
}
|
|
|
|
func (s *Service) RegisterCompany(ctx context.Context, company *domain.Company) error {
|
|
company.ID = uuid.Must(uuid.NewV7())
|
|
return s.repo.CreateCompany(ctx, company)
|
|
}
|
|
|
|
func (s *Service) ListCompanies(ctx context.Context) ([]domain.Company, error) {
|
|
return s.repo.ListCompanies(ctx)
|
|
}
|
|
|
|
func (s *Service) RegisterProduct(ctx context.Context, product *domain.Product) error {
|
|
product.ID = uuid.Must(uuid.NewV7())
|
|
return s.repo.CreateProduct(ctx, product)
|
|
}
|
|
|
|
func (s *Service) ListProducts(ctx context.Context) ([]domain.Product, error) {
|
|
return s.repo.ListProducts(ctx)
|
|
}
|
|
|
|
func (s *Service) CreateOrder(ctx context.Context, order *domain.Order) error {
|
|
order.ID = uuid.Must(uuid.NewV7())
|
|
order.Status = domain.OrderStatusPending
|
|
return s.repo.CreateOrder(ctx, order)
|
|
}
|
|
|
|
func (s *Service) GetOrder(ctx context.Context, id uuid.UUID) (*domain.Order, error) {
|
|
return s.repo.GetOrder(ctx, id)
|
|
}
|
|
|
|
func (s *Service) UpdateOrderStatus(ctx context.Context, id uuid.UUID, status domain.OrderStatus) error {
|
|
return s.repo.UpdateOrderStatus(ctx, id, status)
|
|
}
|
|
|
|
func (s *Service) CreatePaymentPreference(ctx context.Context, id uuid.UUID) (*domain.PaymentPreference, error) {
|
|
order, err := s.repo.GetOrder(ctx, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.pay.CreatePreference(ctx, order)
|
|
}
|