Skip to content
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 resumo rubricas #571

Merged
merged 2 commits into from
Jan 10, 2024
Merged
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
580 changes: 230 additions & 350 deletions docs/docs.go

Large diffs are not rendered by default.

575 changes: 227 additions & 348 deletions docs/swagger.json

Large diffs are not rendered by default.

919 changes: 415 additions & 504 deletions docs/swagger.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/dadosjusbr/proto v0.0.0-20221212025627-91c60aa3cd12
github.com/dadosjusbr/storage v0.0.0-20231106132314-7063d34ebc2d
github.com/dadosjusbr/storage v0.0.0-20240109194919-e8fa5bdec162
github.com/gocarina/gocsv v0.0.0-20220712153207-8b2118da4570
github.com/golang/mock v1.6.0
github.com/joho/godotenv v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ github.com/dadosjusbr/storage v0.0.0-20230711162749-e2d2c0a916f0 h1:zR5+0WcgvH4W
github.com/dadosjusbr/storage v0.0.0-20230711162749-e2d2c0a916f0/go.mod h1:ttc45wBL5bjz5uU24mgNNPV9ZHaJ3SmoRwVOmyVRZyY=
github.com/dadosjusbr/storage v0.0.0-20231106132314-7063d34ebc2d h1:vU6hL1gxD9fvKIXMqdUMvZLu5aApKW2NfYzlOywA7KQ=
github.com/dadosjusbr/storage v0.0.0-20231106132314-7063d34ebc2d/go.mod h1:JTg/Wu2+wn9SV1J19dDeEronive9J6QelMA7K6vLO8I=
github.com/dadosjusbr/storage v0.0.0-20240109194919-e8fa5bdec162 h1:adRnuhh3Lvk4YClkZl3KRJYln3XmFr+ElGBArQt86LI=
github.com/dadosjusbr/storage v0.0.0-20240109194919-e8fa5bdec162/go.mod h1:PszGy6CDoG3kNLjIsCmwD3MAWED7xL7U/OWj7ajsiHc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
18 changes: 15 additions & 3 deletions papi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ func (h handler) V2GetMonthlyInfo(c echo.Context) error {
Average: monthlyInfo.Summary.Remunerations.Average,
Total: monthlyInfo.Summary.Remunerations.Total,
},
ItemSummary: itemSummary{
FoodAllowance: monthlyInfo.Summary.ItemSummary.FoodAllowance,
Others: monthlyInfo.Summary.ItemSummary.Others,
},
},
},
Metadata: &metadata{
Expand Down Expand Up @@ -452,6 +456,10 @@ func (h handler) GetMonthlyInfosByYear(c echo.Context) error {
Average: mi.Summary.Remunerations.Average,
Total: mi.Summary.Remunerations.Total,
},
ItemSummary: itemSummary{
FoodAllowance: mi.Summary.ItemSummary.FoodAllowance,
Others: mi.Summary.ItemSummary.Others,
},
},
},
Metadata: &metadata{
Expand Down Expand Up @@ -662,9 +670,9 @@ func (h handler) V2GetAggregateIndexesWithParams(c echo.Context) error {
// @Tags public_api
// @Description Busca as informações de índices de todos os órgãos.
// @Produce json
// @Success 200 {object} []aggregateIndexesByGroup "Requisição bem sucedida."
// @Failure 500 {string} string "Erro interno do servidor."
// @Router /v2/indice [get]
// @Success 200 {object} []aggregateIndexesByGroup "Requisição bem sucedida."
// @Failure 500 {string} string "Erro interno do servidor."
// @Router /v2/indice [get]
func (h handler) V2GetAggregateIndexes(c echo.Context) error {
agregado := c.QueryParam("agregado")
detalhe := c.QueryParam("detalhe")
Expand Down Expand Up @@ -827,6 +835,10 @@ func (h handler) V2GetAllAgencyInformation(c echo.Context) error {
Average: c.Summary.Remunerations.Average,
Total: c.Summary.Remunerations.Total,
},
ItemSummary: itemSummary{
FoodAllowance: c.Summary.ItemSummary.FoodAllowance,
Others: c.Summary.ItemSummary.Others,
},
},
},
Metadata: &metadata{
Expand Down
6 changes: 6 additions & 0 deletions papi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type summary struct {
OtherRemunerations dataSummary `json:"outras_remuneracoes,omitempty"`
Discounts dataSummary `json:"descontos,omitempty"`
Remunerations dataSummary `json:"remuneracoes,omitempty"`
ItemSummary itemSummary `json:"resumo_rubricas,omitempty"`
}

type itemSummary struct {
FoodAllowance float64 `json:"auxilio_alimentacao,omitempty"`
Others float64 `json:"outras,omitempty"` // valor agregado de outras rubricas não identificadas
}

type summaries struct {
Expand Down
21 changes: 19 additions & 2 deletions uiapi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (h handler) V2GetSummaryOfAgency(c echo.Context) error {
},
HasNext: time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC).In(h.loc).Before(time.Now().AddDate(0, 1, 0)),
HasPrevious: time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC).In(h.loc).After(time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC).In(h.loc)),
ItemSummary: itemSummary{
FoodAllowance: agencyMonthlyInfo.Summary.ItemSummary.FoodAllowance,
Others: agencyMonthlyInfo.Summary.ItemSummary.Others,
},
}
return c.JSON(http.StatusOK, agencySummary)
}
Expand Down Expand Up @@ -174,7 +178,7 @@ func (h handler) GetSalaryOfAgencyMonthYear(c echo.Context) error {
// @Param orgao path string true "ID do órgão. Exemplos: tjal, tjba, mppb."
// @Param mes path string true "Mês da remuneração. Exemplos: 01, 02, 03..."
// @Param ano path string true "Ano da remuneração. Exemplos: 2018, 2019, 2020..."
// @Success 200 {object} agencySalary "Requisição bem sucedida."
// @Success 200 {object} agencyRemuneration "Requisição bem sucedida."
// @Success 206 {object} v2ProcInfoResult "Requisição bem sucedida, mas os dados do órgão não foram bem processados"
// @Failure 400 {string} string "Parâmetros inválidos."
// @Router /uiapi/v2/orgao/salario/{orgao}/{ano}/{mes} [get]
Expand Down Expand Up @@ -334,6 +338,10 @@ func (h handler) V2GetTotalsOfAgencyYear(c echo.Context) error {
Nanos: agencyMonthlyInfo.CrawlingTimestamp.GetNanos(),
},
MemberCount: agencyMonthlyInfo.Summary.Count,
ItemSummary: itemSummary{
FoodAllowance: agencyMonthlyInfo.Summary.ItemSummary.FoodAllowance,
Others: agencyMonthlyInfo.Summary.ItemSummary.Others,
},
}
monthTotalsOfYear = append(monthTotalsOfYear, monthTotals)

Expand Down Expand Up @@ -575,7 +583,7 @@ func (h handler) V2GetGeneralRemunerationFromYear(c echo.Context) error {
data, err := h.client.Db.GetGeneralMonthlyInfosFromYear(year)
if err != nil {
fmt.Println("Error searching for monthly info from year: %w", err)
return c.JSON(http.StatusInternalServerError, fmt.Sprintf("Error buscando dados"))
return c.JSON(http.StatusInternalServerError, "error buscando dados")
}
annualRemu := []mensalRemuneration{}
for _, d := range data {
Expand All @@ -586,6 +594,10 @@ func (h handler) V2GetGeneralRemunerationFromYear(c echo.Context) error {
OtherRemunerations: d.OtherRemunerations,
Discounts: d.Discounts,
Remunerations: d.Remunerations,
ItemSummary: itemSummary{
FoodAllowance: d.ItemSummary.FoodAllowance,
Others: d.ItemSummary.Others,
},
})
}
return c.JSON(http.StatusOK, annualRemu)
Expand Down Expand Up @@ -797,6 +809,10 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
remPerCapita := s.Remunerations / float64(s.TotalCount)
discountsRemPerMonth := s.Discounts / float64(s.NumMonthsWithData)
discountsRemPerCapita := s.Discounts / float64(s.TotalCount)
itemSummary := itemSummary{
FoodAllowance: s.ItemSummary.FoodAllowance,
Others: s.ItemSummary.Others,
}
annualData = append(annualData, annualSummaryData{
Year: s.Year,
AverageMemberCount: s.AverageCount,
Expand All @@ -818,6 +834,7 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
Hash: s.Package.Hash,
Size: s.Package.Size,
},
ItemSummary: itemSummary,
})
}
var collect []collecting
Expand Down
103 changes: 56 additions & 47 deletions uiapi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,20 @@ type agencySummary struct {
}

type v2AgencySummary struct {
Agency string `json:"orgao"`
BaseRemuneration float64 `json:"remuneracao_base"`
MaxBase float64 `json:"max_remuneracao_base"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
MaxOther float64 `json:"max_outras_remuneracoes"`
Discounts float64 `json:"descontos"`
MaxDiscounts float64 `json:"max_descontos"`
MaxRemuneration float64 `json:"max_remuneracao"`
CrawlingTime timestamp `json:"timestamp"`
TotalMembers int `json:"total_membros"`
TotalRemuneration float64 `json:"total_remuneracao"`
HasNext bool `json:"tem_proximo"`
HasPrevious bool `json:"tem_anterior"`
Agency string `json:"orgao"`
BaseRemuneration float64 `json:"remuneracao_base"`
MaxBase float64 `json:"max_remuneracao_base"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
MaxOther float64 `json:"max_outras_remuneracoes"`
Discounts float64 `json:"descontos"`
MaxDiscounts float64 `json:"max_descontos"`
MaxRemuneration float64 `json:"max_remuneracao"`
CrawlingTime timestamp `json:"timestamp"`
TotalMembers int `json:"total_membros"`
TotalRemuneration float64 `json:"total_remuneracao"`
HasNext bool `json:"tem_proximo"`
HasPrevious bool `json:"tem_anterior"`
ItemSummary itemSummary `json:"resumo_rubricas"`
}

// AgencyTotalsYear - Represents the totals of an year
Expand Down Expand Up @@ -153,18 +154,19 @@ type monthTotals struct {
}

type v2MonthTotals struct {
Error *procError `json:"error,omitempty"`
Month int `json:"mes"`
MemberCount int `json:"total_membros"`
BaseRemuneration float64 `json:"remuneracao_base"`
BaseRemunerationPerCapita float64 `json:"remuneracao_base_por_membro"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
OtherRemunerationsPerCapita float64 `json:"outras_remuneracoes_por_membro"`
Discounts float64 `json:"descontos"`
DiscountsPerCapita float64 `json:"descontos_por_membro"`
Remunerations float64 `json:"remuneracoes"`
RemunerationsPerCapita float64 `json:"remuneracoes_por_membro"`
CrawlingTimestamp timestamp `json:"timestamp"`
Error *procError `json:"error,omitempty"`
Month int `json:"mes"`
MemberCount int `json:"total_membros"`
BaseRemuneration float64 `json:"remuneracao_base"`
BaseRemunerationPerCapita float64 `json:"remuneracao_base_por_membro"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
OtherRemunerationsPerCapita float64 `json:"outras_remuneracoes_por_membro"`
Discounts float64 `json:"descontos"`
DiscountsPerCapita float64 `json:"descontos_por_membro"`
Remunerations float64 `json:"remuneracoes"`
RemunerationsPerCapita float64 `json:"remuneracoes_por_membro"`
CrawlingTimestamp timestamp `json:"timestamp"`
ItemSummary itemSummary `json:"resumo_rubricas"`
}

type timestamp struct {
Expand Down Expand Up @@ -251,29 +253,36 @@ type annualSummary struct {
}

type annualSummaryData struct {
Year int `json:"ano,omitempty"`
AverageMemberCount int `json:"num_membros,omitempty"`
BaseRemuneration float64 `json:"remuneracao_base"`
BaseRemunerationPerMonth float64 `json:"remuneracao_base_por_mes"`
BaseRemunerationPerCapita float64 `json:"remuneracao_base_por_membro"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
OtherRemunerationsPerMonth float64 `json:"outras_remuneracoes_por_mes"`
OtherRemunerationsPerCapita float64 `json:"outras_remuneracoes_por_membro"`
Discounts float64 `json:"descontos"`
DiscountsPerMonth float64 `json:"descontos_por_mes"`
DiscountsPerCapita float64 `json:"descontos_por_membro"`
Remunerations float64 `json:"remuneracoes"`
RemunerationsPerMonth float64 `json:"remuneracoes_por_mes"`
RemunerationsPerCapita float64 `json:"remuneracoes_por_membro"`
NumMonthsWithData int `json:"meses_com_dados"`
Package *backup `json:"package,omitempty"`
Year int `json:"ano,omitempty"`
AverageMemberCount int `json:"num_membros,omitempty"`
BaseRemuneration float64 `json:"remuneracao_base"`
BaseRemunerationPerMonth float64 `json:"remuneracao_base_por_mes"`
BaseRemunerationPerCapita float64 `json:"remuneracao_base_por_membro"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
OtherRemunerationsPerMonth float64 `json:"outras_remuneracoes_por_mes"`
OtherRemunerationsPerCapita float64 `json:"outras_remuneracoes_por_membro"`
Discounts float64 `json:"descontos"`
DiscountsPerMonth float64 `json:"descontos_por_mes"`
DiscountsPerCapita float64 `json:"descontos_por_membro"`
Remunerations float64 `json:"remuneracoes"`
RemunerationsPerMonth float64 `json:"remuneracoes_por_mes"`
RemunerationsPerCapita float64 `json:"remuneracoes_por_membro"`
NumMonthsWithData int `json:"meses_com_dados"`
Package *backup `json:"package,omitempty"`
ItemSummary itemSummary `json:"resumo_rubricas"`
}

type itemSummary struct {
FoodAllowance float64 `json:"auxilio_alimentacao,omitempty"`
Others float64 `json:"outras,omitempty"` // valor agregado de outras rubricas não identificadas
}

type mensalRemuneration struct {
Month int `json:"mes,omitempty"`
Members int `json:"num_membros,omitempty"`
BaseRemuneration float64 `json:"remuneracao_base"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
Discounts float64 `json:"descontos"`
Remunerations float64 `json:"remuneracoes"`
Month int `json:"mes,omitempty"`
Members int `json:"num_membros,omitempty"`
BaseRemuneration float64 `json:"remuneracao_base"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
Discounts float64 `json:"descontos"`
Remunerations float64 `json:"remuneracoes"`
ItemSummary itemSummary `json:"resumo_rubricas"`
}
36 changes: 31 additions & 5 deletions uiapi/uiapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func (g getSummaryOfAgency) testWhenDataExists(t *testing.T) {
"total_membros": 214,
"total_remuneracao": 7.099024400000013e+06,
"tem_proximo": true,
"tem_anterior": true
"tem_anterior": true,
"resumo_rubricas": {}
}
`

Expand Down Expand Up @@ -949,6 +950,10 @@ func (g getGenerealRemunerationFromYear) testWhenDataExists(t *testing.T) {
OtherRemunerations: 1000,
Discounts: 1000,
Remunerations: 10000,
ItemSummary: models.ItemSummary{
FoodAllowance: 100,
Others: 200,
},
},
{
Month: 2,
Expand All @@ -957,6 +962,10 @@ func (g getGenerealRemunerationFromYear) testWhenDataExists(t *testing.T) {
OtherRemunerations: 2000,
Discounts: 1000,
Remunerations: 21000,
ItemSummary: models.ItemSummary{
FoodAllowance: 100,
Others: 200,
},
},
}
dbMock.EXPECT().Connect().Return(nil).Times(1)
Expand Down Expand Up @@ -989,15 +998,23 @@ func (g getGenerealRemunerationFromYear) testWhenDataExists(t *testing.T) {
"remuneracao_base": 10000,
"outras_remuneracoes": 1000,
"descontos": 1000,
"remuneracoes": 10000
"remuneracoes": 10000,
"resumo_rubricas": {
"auxilio_alimentacao": 100,
"outras": 200
}
},
{
"mes": 2,
"num_membros": 200,
"remuneracao_base": 20000,
"outras_remuneracoes": 2000,
"descontos": 1000,
"remuneracoes": 21000
"remuneracoes": 21000,
"resumo_rubricas": {
"auxilio_alimentacao": 100,
"outras": 200
}
}
]
`
Expand Down Expand Up @@ -1149,7 +1166,8 @@ func (g getTotalsOfAgencyYear) testWhenDataExists(t *testing.T) {
"seconds": 1,
"nanos": 1
},
"total_membros": 214
"total_membros": 214,
"resumo_rubricas": {}
}
],
"package": {
Expand Down Expand Up @@ -1293,6 +1311,10 @@ func (g getAnnualSummary) testWhenDataExists(t *testing.T) {
Hash: "4d7ca8986101673aea060ac1d8e5a529",
Size: 30195,
},
ItemSummary: models.ItemSummary{
FoodAllowance: 100,
Others: 200,
},
},
}
dbMock.EXPECT().Connect().Return(nil).Times(1)
Expand Down Expand Up @@ -1352,7 +1374,11 @@ func (g getAnnualSummary) testWhenDataExists(t *testing.T) {
"url": "https://dadosjusbr.org/download/tjal/datapackage/tjal-2020-1.zip",
"hash": "4d7ca8986101673aea060ac1d8e5a529",
"size": 30195
}
},
"resumo_rubricas": {
"auxilio_alimentacao": 100,
"outras": 200
}
}
]
}
Expand Down
Loading