Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion uiapi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gocarina/gocsv"
"github.com/labstack/echo/v4"
"github.com/newrelic/go-agent/v3/newrelic"
"google.golang.org/protobuf/types/known/timestamppb"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -785,6 +786,7 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, fmt.Sprintf("Algo deu errado ao tentar coletar os dados anuais do orgao=%s", agencyName))
}
var annualData []annualSummaryData
var t *timestamppb.Timestamp
for _, s := range summaries {
baseRemPerMonth := s.BaseRemuneration / float64(s.NumMonthsWithData)
baseRemPerCapita := s.BaseRemuneration / float64(s.TotalCount)
Expand All @@ -811,6 +813,9 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
Size: s.Package.Size,
},
})
if s.Timestamp.AsTime().After(t.AsTime()) {
t = s.Timestamp
}
}
var collect []collecting
var hasData bool
Expand All @@ -821,6 +826,11 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
})
hasData = c.Collecting
}

crawlingTimestamp := timestamp{
Seconds: t.GetSeconds(),
Nanos: t.GetNanos(),
}
annualSum := annualSummary{
Agency: &agency{
ID: strAgency.ID,
Expand All @@ -834,7 +844,8 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
OmbudsmanURL: strAgency.OmbudsmanURL,
HasData: hasData,
},
Data: annualData,
Data: annualData,
CrawlingTimestamp: crawlingTimestamp,
}
return c.JSON(http.StatusOK, annualSum)
}
Expand Down
5 changes: 3 additions & 2 deletions uiapi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ type collecting struct {
}

type annualSummary struct {
Agency *agency `json:"orgao,omitempty"`
Data []annualSummaryData `json:"dados_anuais,omitempty"`
Agency *agency `json:"orgao,omitempty"`
CrawlingTimestamp timestamp `json:"timestamp,omitempty"`
Data []annualSummaryData `json:"dados_anuais,omitempty"`
}

type annualSummaryData struct {
Expand Down
8 changes: 8 additions & 0 deletions uiapi/uiapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,10 @@ func (g getAnnualSummary) testWhenDataExists(t *testing.T) {
"ouvidoria": "http://www.tjal.jus.br/ombudsman",
"url": "example.com/v2/orgao/tjal"
},
"timestamp": {
"nanos":0,
"seconds":0
},
"dados_anuais": [
{
"ano": 2020,
Expand Down Expand Up @@ -1477,6 +1481,10 @@ func (g getAnnualSummary) testWhenAgencyDoesNotHaveData(t *testing.T) {
"twitter_handle": "tjaloficial",
"ouvidoria": "http://www.tjal.jus.br/ombudsman",
"url": "example.com/v2/orgao/tjal"
},
"timestamp": {
"nanos":0,
"seconds":0
}
}
`
Expand Down