postgres

package
v0.0.0-...-edb595d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToDomainVehicles

func ToDomainVehicles(vehicles []Vehicle) []domain.Vehicle

ToDomainVehicles converts a slice of Vehicle objects to a slice of domain.Vehicle objects.

Types

type Vehicle

type Vehicle struct {
	Year           int     `gorm:"index:idx_year" json:"year,omitempty"`
	Month          int     `gorm:"index:idx_month" json:"month,omitempty"`
	FipeCode       string  `gorm:"index:idx_fipe_code" json:"fipe_code,omitempty"`
	Brand          string  `json:"brand,omitempty"`
	VehicleModel   string  `json:"vehicle_model,omitempty"`
	YearModel      string  `json:"year_model,omitempty"`
	Authentication string  `json:"authentication,omitempty"`
	MeanValue      float32 `json:"mean_value,omitempty"`
}

type VehicleRepositoryPostgres

type VehicleRepositoryPostgres struct {
	Conn *gorm.DB
}

func NewVehicleRepositoryPostgres

func NewVehicleRepositoryPostgres(conn *gorm.DB) *VehicleRepositoryPostgres

NewVehicleRepositoryPostgres initializes a new instance of VehicleRepositoryPostgres with the given database connection. It performs automatic migrations for the Vehicle model and panics if an error occurs during migration. Returns a pointer to the VehicleRepositoryPostgres instance.

func (VehicleRepositoryPostgres) GetVehicle

func (v VehicleRepositoryPostgres) GetVehicle(
	whereClauses []domain.WhereClause,
	orderByClauses []domain.OrderByClause,
	pagination domain.Pagination) ([]domain.Vehicle, *errs.AppError)

GetVehicle retrieves vehicles from the database based on the given conditions, order by specifications and pagination settings. It validates the pagination parameters and returns an error if they are invalid. It then fetches the vehicles from the database using the fetchVehiclesFromDb function, passing the specified conditions, order by specifications, and pagination settings. If an error occurs during the fetch operation, it returns the error. Otherwise, it converts the fetched vehicles to domain.Vehicle objects using the ToDomainVehicles function and returns them along with a nil error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL