-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
retornando a data da última coleta #115
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,7 +222,9 @@ func (p *PostgresDB) GetAgenciesByUF(uf string) ([]models.Agency, error) { | |
func (p *PostgresDB) GetAgency(aid string) (*models.Agency, error) { | ||
var dtoOrgao dto.AgencyDTO | ||
aid = strings.ToLower(aid) | ||
if err := p.db.Model(&dto.AgencyDTO{}).Where("id = ?", aid).First(&dtoOrgao).Error; err != nil { | ||
m := p.db.Model(&dto.AgencyDTO{}).Select("orgaos.*, max(coletas.timestamp) as ultima_coleta") | ||
m = m.Joins("INNER JOIN coletas ON atual = true AND coletas.id_orgao = orgaos.id AND orgaos.id = ?", aid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não seria melhor colocar o actual = true o orgaos.id == aid para uma cláusula where? Penso que isso vai diminuir o impacto negativo do join. |
||
if err := m.Group("orgaos.id").First(&dtoOrgao).Error; err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Precisamos mesmo desse agrupamento? |
||
return nil, fmt.Errorf("error getting agency '%s': %q", aid, err) | ||
} | ||
orgao, err := dtoOrgao.ConvertToModel() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisamos mesmo desse
orgaos.*
?