Skip to content

Commit

Permalink
retornando avisos dos órgãos do BD
Browse files Browse the repository at this point in the history
  • Loading branch information
joellensilva committed Jan 27, 2025
1 parent 68bc570 commit 9b53085
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/monthlyInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type AgencyMonthlyInfo struct {
Duration float64 `json:"duration,omitempty"` // Crawling duration (seconds)
ManualCollection bool `json:"coleta_manual,omitempty"` // If the data was collected manually
Inconsistent bool `json:"inconsistent"` // If the data is inconsistent
Notices string `json:"notices"` // If the data has notices
}

type Meta struct {
Expand Down
15 changes: 15 additions & 0 deletions repo/database/database_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions repo/database/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type Interface interface {
GetPaychecks(agency models.Agency, year int) ([]models.Paycheck, error)
GetPaycheckItems(agency models.Agency, year int) ([]models.PaycheckItem, error)
GetAveragePerCapita(agency string, year int) (*models.PerCapitaData, error)
GetNotices(agency string, year int, month int) ([]*string, error)
}
24 changes: 24 additions & 0 deletions repo/database/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,27 @@ func (p *PostgresDB) GetAveragePerCapita(agency string, ano int) (*models.PerCap
avg := dtoAvg.ConvertToModel()
return avg, nil
}

func (p *PostgresDB) GetNotices(agency string, year int, month int) ([]*string, error) {
var notices []*string
params := []interface{}{}

query := "atual = true AND avisos IS NOT NULL AND id_orgao = ?"
params = append(params, agency)

if year != 0 {
query = query + " AND ano = ?"
params = append(params, year)
if month != 0 {
query = query + " AND mes = ?"
params = append(params, month)
}
}

result := p.db.Model(&dto.AgencyMonthlyInfoDTO{}).Distinct("avisos").Where(query, params...)
if err := result.Find(&notices).Error; err != nil {
return nil, fmt.Errorf("error getting notices: %w", err)
}

return notices, nil
}

0 comments on commit 9b53085

Please sign in to comment.