diff --git a/uiapi/handlers.go b/uiapi/handlers.go index 3ae45e92..aac20896 100644 --- a/uiapi/handlers.go +++ b/uiapi/handlers.go @@ -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" ) @@ -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) @@ -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 @@ -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, @@ -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) } diff --git a/uiapi/models.go b/uiapi/models.go index aa0503da..45b41a14 100644 --- a/uiapi/models.go +++ b/uiapi/models.go @@ -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 { diff --git a/uiapi/uiapi_test.go b/uiapi/uiapi_test.go index accdb0fa..d8d26e9b 100644 --- a/uiapi/uiapi_test.go +++ b/uiapi/uiapi_test.go @@ -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, @@ -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 } } `