62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"git.maximotejeda.com/maximo/cedulados/internal/application/core/domain"
|
|
"git.maximotejeda.com/maximo/cedulados/internal/ports"
|
|
)
|
|
|
|
type Application struct {
|
|
infoDB ports.DBPorts
|
|
fotoDB ports.DBPorts
|
|
log *slog.Logger
|
|
}
|
|
|
|
func NewApplication(infoDB, fotoDB ports.DBPorts) *Application {
|
|
log := slog.Default()
|
|
log = log.With("adapter", "application")
|
|
return &Application{
|
|
infoDB: infoDB,
|
|
fotoDB: fotoDB,
|
|
log: log,
|
|
}
|
|
}
|
|
|
|
// ByCedula
|
|
// Query db with a cedula complete info
|
|
func (a Application) ByCedula(ctx context.Context, cedula *domain.Cedula) (*domain.Cedulado, error) {
|
|
return a.infoDB.ByCedula(ctx, cedula)
|
|
}
|
|
// GetByNameLastName
|
|
// Query db by name, lastname
|
|
func (a Application) GetByNameLastName(ctx context.Context, nombre, apellido1, apellido2 string, page int64) (*domain.MultipleResults, error) {
|
|
return a.infoDB.GetByNameLastName(ctx, nombre, apellido1, apellido2, page)
|
|
}
|
|
// GetByFTS
|
|
// make a full text search
|
|
func (a Application) GetByFTS(ctx context.Context, parametros string, page int64) (*domain.MultipleResults, error) {
|
|
return a.infoDB.GetByFTS(ctx, parametros, page)
|
|
}
|
|
// ByNameAndLocation
|
|
// search coincidents names in a location
|
|
func (a Application) ByNameAndLocation(ctx context.Context, nombre, apellido1, apellido2, municipio string, page int64) (*domain.MultipleResults, error) {
|
|
return a.infoDB.ByNameAndLocation(ctx, nombre, apellido1, apellido2, municipio, page)
|
|
}
|
|
// QueryFotoByCedula
|
|
// query foto db with full cedula info
|
|
func (a Application) QueryFotoByCedula(ctx context.Context, cedula *domain.Cedula) (*domain.Foto, error) {
|
|
return a.fotoDB.QueryFotoByCedula(ctx, cedula)
|
|
}
|
|
// QueryFotoById
|
|
// knowing id of a record get the photo
|
|
func (a Application) QueryFotoById(ctx context.Context, id int64) (*domain.Foto, error) {
|
|
return a.fotoDB.QueryFotoById(ctx, id)
|
|
}
|
|
// QueryAllCedulas
|
|
// Query a list of cedulas
|
|
func (a Application) QueryAllCedulas(ctx context.Context, cedulas []*domain.Cedula) ([]*domain.Foto, error) {
|
|
return a.fotoDB.QueryAllCedulas(ctx, cedulas)
|
|
}
|