fix: restore missing interface methods and cleanup syntax in usecase.go and postgres.go
This commit is contained in:
parent
5464678ae5
commit
fa9ddbdeef
2 changed files with 133 additions and 126 deletions
|
|
@ -1607,6 +1607,8 @@ func (r *Repository) CreateAddress(ctx context.Context, address *domain.Address)
|
||||||
|
|
||||||
_, err := r.db.NamedExecContext(ctx, query, address)
|
_, err := r.db.NamedExecContext(ctx, query, address)
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Repository) ListAddresses(ctx context.Context, entityID uuid.UUID) ([]domain.Address, error) {
|
func (r *Repository) ListAddresses(ctx context.Context, entityID uuid.UUID) ([]domain.Address, error) {
|
||||||
var addresses []domain.Address
|
var addresses []domain.Address
|
||||||
query := `SELECT id, entity_id, title, zip_code, street, number, complement, district, city, state, latitude, longitude, created_at, updated_at FROM addresses WHERE entity_id = $1 ORDER BY created_at DESC`
|
query := `SELECT id, entity_id, title, zip_code, street, number, complement, district, city, state, latitude, longitude, created_at, updated_at FROM addresses WHERE entity_id = $1 ORDER BY created_at DESC`
|
||||||
|
|
@ -1620,10 +1622,6 @@ func (r *Repository) ListAllAddresses(ctx context.Context) ([]domain.Address, er
|
||||||
err := r.db.SelectContext(ctx, &addresses, query)
|
err := r.db.SelectContext(ctx, &addresses, query)
|
||||||
return addresses, err
|
return addresses, err
|
||||||
}
|
}
|
||||||
// If no rows, SelectContext returns nil error but empty slice if initialized, or maybe error?
|
|
||||||
// sqlx returns error if slice is empty? No, SelectContext handles empty result by returning empty slice usually.
|
|
||||||
return addresses, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Repository) GetAddress(ctx context.Context, id uuid.UUID) (*domain.Address, error) {
|
func (r *Repository) GetAddress(ctx context.Context, id uuid.UUID) (*domain.Address, error) {
|
||||||
var addr domain.Address
|
var addr domain.Address
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Repository defines the persistence contract for all core entities.
|
// Repository defines the persistence contract for all core entities.
|
||||||
// Implementations live in internal/repository/postgres/.
|
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
CreateCompany(ctx context.Context, company *domain.Company) error
|
CreateCompany(ctx context.Context, company *domain.Company) error
|
||||||
ListCompanies(ctx context.Context, filter domain.CompanyFilter) ([]domain.Company, int64, error)
|
ListCompanies(ctx context.Context, filter domain.CompanyFilter) ([]domain.Company, int64, error)
|
||||||
|
|
@ -83,17 +82,19 @@ CompleteReservation(ctx context.Context, reservationID uuid.UUID) error
|
||||||
ExpireReservations(ctx context.Context) error
|
ExpireReservations(ctx context.Context) error
|
||||||
GetActiveReservations(ctx context.Context, inventoryItemID uuid.UUID) (int64, error)
|
GetActiveReservations(ctx context.Context, inventoryItemID uuid.UUID) (int64, error)
|
||||||
|
|
||||||
GetPaymentGatewayConfig(ctx context.Context, provider string) (*domain.PaymentGatewayConfig, error)UpsertPaymentGatewayConfig(ctx context.Context, config *domain.PaymentGatewayConfig) error
|
GetPaymentGatewayConfig(ctx context.Context, provider string) (*domain.PaymentGatewayConfig, error)
|
||||||
|
UpsertPaymentGatewayConfig(ctx context.Context, config *domain.PaymentGatewayConfig) error
|
||||||
GetSellerPaymentAccount(ctx context.Context, sellerID uuid.UUID) (*domain.SellerPaymentAccount, error)
|
GetSellerPaymentAccount(ctx context.Context, sellerID uuid.UUID) (*domain.SellerPaymentAccount, error)
|
||||||
UpsertSellerPaymentAccount(ctx context.Context, account *domain.SellerPaymentAccount) error
|
UpsertSellerPaymentAccount(ctx context.Context, account *domain.SellerPaymentAccount) error
|
||||||
|
|
||||||
CreateAddress(ctx context.Context, address *domain.Address) error
|
CreateAddress(ctx context.Context, address *domain.Address) error
|
||||||
ListAddresses(ctx context.Context, entityID uuid.UUID) ([]domain.Address, error)
|
ListAddresses(ctx context.Context, entityID uuid.UUID) ([]domain.Address, error)
|
||||||
|
ListAllAddresses(ctx context.Context) ([]domain.Address, error)
|
||||||
GetAddress(ctx context.Context, id uuid.UUID) (*domain.Address, error)
|
GetAddress(ctx context.Context, id uuid.UUID) (*domain.Address, error)
|
||||||
UpdateAddress(ctx context.Context, address *domain.Address) error
|
UpdateAddress(ctx context.Context, address *domain.Address) error
|
||||||
DeleteAddress(ctx context.Context, id uuid.UUID) error
|
DeleteAddress(ctx context.Context, id uuid.UUID) error
|
||||||
ListAllAddresses(ctx context.Context) ([]domain.Address, error)
|
|
||||||
GeocodeAllAddresses(ctx context.Context) (int, error)
|
GeocodeAllAddresses(ctx context.Context) (int, error)
|
||||||
|
StartStockCleanupWorker(ctx context.Context)
|
||||||
|
|
||||||
ListManufacturers(ctx context.Context) ([]string, error)
|
ListManufacturers(ctx context.Context) ([]string, error)
|
||||||
ListCategories(ctx context.Context) ([]string, error)
|
ListCategories(ctx context.Context) ([]string, error)
|
||||||
|
|
@ -101,7 +102,6 @@ GetProductByEAN(ctx context.Context, ean string) (*domain.Product, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PaymentGateway abstracts the payment provider (Mercado Pago, Asaas, etc.).
|
// PaymentGateway abstracts the payment provider (Mercado Pago, Asaas, etc.).
|
||||||
// Implementations live in internal/infrastructure/payments/.
|
|
||||||
type PaymentGateway interface {
|
type PaymentGateway interface {
|
||||||
CreatePreference(ctx context.Context, order *domain.Order, payer *domain.User, sellerAcc *domain.SellerPaymentAccount) (*domain.PaymentPreference, error)
|
CreatePreference(ctx context.Context, order *domain.Order, payer *domain.User, sellerAcc *domain.SellerPaymentAccount) (*domain.PaymentPreference, error)
|
||||||
CreatePayment(ctx context.Context, order *domain.Order, token, issuerID, paymentMethodID string, installments int, payer *domain.User, sellerAcc *domain.SellerPaymentAccount) (*domain.PaymentResult, error)
|
CreatePayment(ctx context.Context, order *domain.Order, token, issuerID, paymentMethodID string, installments int, payer *domain.User, sellerAcc *domain.SellerPaymentAccount) (*domain.PaymentResult, error)
|
||||||
|
|
@ -109,19 +109,8 @@ type PaymentGateway interface {
|
||||||
CreateBoletoPayment(ctx context.Context, order *domain.Order, payer *domain.User) (*domain.BoletoPaymentResult, error)
|
CreateBoletoPayment(ctx context.Context, order *domain.Order, payer *domain.User) (*domain.BoletoPaymentResult, error)
|
||||||
GetPaymentStatus(ctx context.Context, paymentID string) (*domain.PaymentWebhookEvent, error)
|
GetPaymentStatus(ctx context.Context, paymentID string) (*domain.PaymentWebhookEvent, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service orchestrates all business use cases.
|
// Service orchestrates all business use cases.
|
||||||
// Methods are split across domain-specific files in this package:
|
|
||||||
// - auth_usecase.go – authentication, JWT, password reset
|
|
||||||
// - company_usecase.go – company registration, KYC, shipping options
|
|
||||||
// - product_usecase.go – catalogue, inventory management
|
|
||||||
// - order_usecase.go – order lifecycle and state machine
|
|
||||||
// - shipping_usecase.go – shipping calculation and configuration
|
|
||||||
// - cart_usecase.go – cart operations and B2B discounts
|
|
||||||
// - payment_usecase.go – payment preferences and webhook handling
|
|
||||||
// - review_usecase.go – buyer reviews and ratings
|
|
||||||
// - user_usecase.go – user CRUD
|
|
||||||
// - address_usecase.go – address management
|
|
||||||
// - dashboard_usecase.go – seller and admin KPI dashboards
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
repo Repository
|
repo Repository
|
||||||
pay PaymentGateway
|
pay PaymentGateway
|
||||||
|
|
@ -167,3 +156,23 @@ passwordPepper: pepper,
|
||||||
func (s *Service) GetNotificationService() notifications.NotificationService {
|
func (s *Service) GetNotificationService() notifications.NotificationService {
|
||||||
return s.notify
|
return s.notify
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteAddress handles address removal logic.
|
||||||
|
func (s *Service) DeleteAddress(ctx context.Context, id uuid.UUID) error {
|
||||||
|
return s.repo.DeleteAddress(ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListManufacturers returns manufacturers from the repo.
|
||||||
|
func (s *Service) ListManufacturers(ctx context.Context) ([]string, error) {
|
||||||
|
return s.repo.ListManufacturers(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListCategories returns categories from the repo.
|
||||||
|
func (s *Service) ListCategories(ctx context.Context) ([]string, error) {
|
||||||
|
return s.repo.ListCategories(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProductByEAN finds a product by its EAN code.
|
||||||
|
func (s *Service) GetProductByEAN(ctx context.Context, ean string) (*domain.Product, error) {
|
||||||
|
return s.repo.GetProductByEAN(ctx, ean)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue