From 41d50df41801b6622c135f9cd033bcdb4609110a Mon Sep 17 00:00:00 2001 From: Joellensilva Date: Mon, 15 May 2023 14:32:14 -0300 Subject: [PATCH 1/2] /v2/dados/:orgao --- docs/docs.go | 93 ++++++ docs/swagger.json | 93 ++++++ docs/swagger.yaml | 796 +++++++++++++++++++++++++--------------------- main.go | 1 + papi/handlers.go | 114 ++++++- papi/models.go | 16 + 6 files changed, 746 insertions(+), 367 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index f4ff678..c2e89da 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -488,6 +488,41 @@ const docTemplate = `{ } } }, + "/v2/dados/{orgao}": { + "get": { + "description": "Busca todas as informações de um órgão específico.", + "produces": [ + "application/json" + ], + "tags": [ + "public_api" + ], + "operationId": "GetAllAgencyInformation", + "parameters": [ + { + "type": "string", + "description": "órgão", + "name": "orgao", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Requisição bem sucedida.", + "schema": { + "$ref": "#/definitions/papi.allAgencyInformation" + } + }, + "400": { + "description": "Requisição inválida.", + "schema": { + "type": "string" + } + } + } + } + }, "/v2/dados/{orgao}/{ano}": { "get": { "description": "Busca os dados mensais de um órgão por ano", @@ -1005,6 +1040,64 @@ const docTemplate = `{ } } }, + "papi.allAgencyInformation": { + "type": "object", + "properties": { + "id_orgao": { + "description": "'trt13'", + "type": "string" + }, + "nome": { + "description": "'Tribunal Regional do Trabalho 13° Região'", + "type": "string" + }, + "jurisdicao": { + "description": "'Estadual', 'Eleitroral', 'Militar', etc.", + "type": "string" + }, + "entidade": { + "description": "'Tribunal', 'Ministério' or 'Conselho'.", + "type": "string" + }, + "uf": { + "description": "Short code for federative unity.", + "type": "string" + }, + "coletando": { + "type": "array", + "items": { + "$ref": "#/definitions/papi.collecting" + } + }, + "url": { + "description": "Link for state url", + "type": "string" + }, + "twitter_handle": { + "description": "Agency's twitter handle", + "type": "string" + }, + "ouvidoria": { + "description": "Agencys's ombudsman url", + "type": "string" + }, + "total_coletas_realizadas": { + "type": "integer" + }, + "meses_com_dados": { + "type": "integer" + }, + "indice_transparencia": { + "$ref": "#/definitions/papi.score" + }, + "coletas": { + "type": "array", + "items": { + "$ref": "#/definitions/papi.summaryzedMI" + } + } + } + }, "papi.backup": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 0d96535..462a6bd 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -478,6 +478,41 @@ } } }, + "/v2/dados/{orgao}": { + "get": { + "description": "Busca todas as informações de um órgão específico.", + "produces": [ + "application/json" + ], + "tags": [ + "public_api" + ], + "operationId": "GetAllAgencyInformation", + "parameters": [ + { + "type": "string", + "description": "órgão", + "name": "orgao", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Requisição bem sucedida.", + "schema": { + "$ref": "#/definitions/papi.allAgencyInformation" + } + }, + "400": { + "description": "Requisição inválida.", + "schema": { + "type": "string" + } + } + } + } + }, "/v2/dados/{orgao}/{ano}": { "get": { "description": "Busca os dados mensais de um órgão por ano", @@ -995,6 +1030,64 @@ } } }, + "papi.allAgencyInformation": { + "type": "object", + "properties": { + "id_orgao": { + "description": "'trt13'", + "type": "string" + }, + "nome": { + "description": "'Tribunal Regional do Trabalho 13° Região'", + "type": "string" + }, + "jurisdicao": { + "description": "'Estadual', 'Eleitroral', 'Militar', etc.", + "type": "string" + }, + "entidade": { + "description": "'Tribunal', 'Ministério' or 'Conselho'.", + "type": "string" + }, + "uf": { + "description": "Short code for federative unity.", + "type": "string" + }, + "coletando": { + "type": "array", + "items": { + "$ref": "#/definitions/papi.collecting" + } + }, + "url": { + "description": "Link for state url", + "type": "string" + }, + "twitter_handle": { + "description": "Agency's twitter handle", + "type": "string" + }, + "ouvidoria": { + "description": "Agencys's ombudsman url", + "type": "string" + }, + "total_coletas_realizadas": { + "type": "integer" + }, + "meses_com_dados": { + "type": "integer" + }, + "indice_transparencia": { + "$ref": "#/definitions/papi.score" + }, + "coletas": { + "type": "array", + "items": { + "$ref": "#/definitions/papi.summaryzedMI" + } + } + } + }, "papi.backup": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 88f2207..b6d6488 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -3,21 +3,23 @@ definitions: properties: coletando: items: - $ref: '#/definitions/papi.collecting' + $ref: "#/definitions/papi.collecting" type: array entidade: - description: '"J" For Judiciário, "M" for Ministério Público, "P" for Procuradorias + description: + '"J" For Judiciário, "M" for Ministério Público, "P" for Procuradorias and "D" for Defensorias.' type: string id_orgao: - description: '''trt13''' + description: "'trt13'" type: string jurisdicao: - description: '"R" for Regional, "M" for Municipal, "F" for Federal, "E" for + description: + '"R" for Regional, "M" for Municipal, "F" for Federal, "E" for State.' type: string nome: - description: '''Tribunal Regional do Trabalho 13° Região''' + description: "'Tribunal Regional do Trabalho 13° Região'" type: string ouvidoria: description: Agencys's ombudsman url @@ -35,6 +37,47 @@ definitions: description: If there is data from that agency type: boolean type: object + papi.allAgencyInformation: + properties: + coletando: + items: + $ref: "#/definitions/papi.collecting" + type: array + coletas: + items: + $ref: "#/definitions/papi.summaryzedMI" + type: array + entidade: + description: '"Tribunal", "Ministério" or "Conselho".' + type: string + id_orgao: + description: "'trt13'" + type: string + indice_transparencia: + $ref: "#/definitions/papi.score" + jurisdicao: + description: '"Estadual", "Eleitroral", "Militar", etc.' + type: string + meses_com_dados: + type: integer + nome: + description: 'ex.: "Tribunal Regional do Trabalho 13° Região".' + type: string + ouvidoria: + description: Agencys's ombudsman url + type: string + total_coletas_realizadas: + type: integer + twitter_handle: + description: Agency's twitter handle + type: string + uf: + description: Short code for federative unity. + type: string + url: + description: Link for state url + type: string + type: object papi.backup: properties: hash: @@ -125,37 +168,37 @@ definitions: papi.summaries: properties: membros_ativos: - $ref: '#/definitions/papi.summary' + $ref: "#/definitions/papi.summary" type: object papi.summary: properties: outras_remuneracoes: - $ref: '#/definitions/papi.dataSummary' + $ref: "#/definitions/papi.dataSummary" quantidade: type: integer remuneracao_base: - $ref: '#/definitions/papi.dataSummary' + $ref: "#/definitions/papi.dataSummary" type: object papi.summaryzedMI: properties: ano: type: integer dados_coleta: - $ref: '#/definitions/papi.collect' + $ref: "#/definitions/papi.collect" error: - $ref: '#/definitions/papi.miError' + $ref: "#/definitions/papi.miError" id_orgao: type: string indice_transparencia: - $ref: '#/definitions/papi.score' + $ref: "#/definitions/papi.score" mes: type: integer metadados: - $ref: '#/definitions/papi.metadata' + $ref: "#/definitions/papi.metadata" pacote_de_dados: - $ref: '#/definitions/papi.backup' + $ref: "#/definitions/papi.backup" sumarios: - $ref: '#/definitions/papi.summaries' + $ref: "#/definitions/papi.summaries" type: object papi.indexInformation: properties: @@ -164,38 +207,40 @@ definitions: ano: type: integer indice_transparencia: - $ref: '#/definitions/papi.score' + $ref: "#/definitions/papi.score" metadados: - $ref: '#/definitions/papi.metadata' + $ref: "#/definitions/papi.metadata" type: object papi.aggregateIndexes: properties: id_orgao: type: string agregado: - $ref: '#/definitions/papi.score' + $ref: "#/definitions/papi.score" detalhe: - $ref: '#/definitions/papi.indexInformation' + $ref: "#/definitions/papi.indexInformation" type: object uiapi.agency: properties: coletando: items: - $ref: '#/definitions/uiapi.collecting' + $ref: "#/definitions/uiapi.collecting" type: array entidade: - description: '"J" For Judiciário, "M" for Ministério Público, "P" for Procuradorias + description: + '"J" For Judiciário, "M" for Ministério Público, "P" for Procuradorias and "D" for Defensorias.' type: string id_orgao: - description: '''trt13''' + description: "'trt13'" type: string jurisdicao: - description: '"R" for Regional, "M" for Municipal, "F" for Federal, "E" for + description: + '"R" for Regional, "M" for Municipal, "F" for Federal, "E" for State.' type: string nome: - description: '''Tribunal Regional do Trabalho 13° Região''' + description: "'Tribunal Regional do Trabalho 13° Região'" type: string ouvidoria: description: Agencys's ombudsman url @@ -228,16 +273,16 @@ definitions: max_salario: type: number package: - $ref: '#/definitions/uiapi.backup' + $ref: "#/definitions/uiapi.backup" type: object uiapi.annualSummary: properties: dados_anuais: items: - $ref: '#/definitions/uiapi.annualSummaryData' + $ref: "#/definitions/uiapi.annualSummaryData" type: array orgao: - $ref: '#/definitions/uiapi.agency' + $ref: "#/definitions/uiapi.agency" type: object uiapi.annualSummaryData: properties: @@ -254,7 +299,7 @@ definitions: outras_remuneracoes_por_membro: type: number package: - $ref: '#/definitions/uiapi.backup' + $ref: "#/definitions/uiapi.backup" remuneracao_base: type: number remuneracao_base_por_mes: @@ -347,7 +392,7 @@ definitions: type: integer result: items: - $ref: '#/definitions/uiapi.searchResult' + $ref: "#/definitions/uiapi.searchResult" type: array search_limit: type: integer @@ -379,7 +424,7 @@ definitions: properties: agency: items: - $ref: '#/definitions/uiapi.agencyBasic' + $ref: "#/definitions/uiapi.agencyBasic" type: array flagURL: type: string @@ -412,7 +457,7 @@ definitions: tem_proximo: type: boolean timestamp: - $ref: '#/definitions/uiapi.timestamp' + $ref: "#/definitions/uiapi.timestamp" total_membros: type: integer total_remuneracao: @@ -424,17 +469,17 @@ definitions: type: integer meses: items: - $ref: '#/definitions/uiapi.v2MonthTotals' + $ref: "#/definitions/uiapi.v2MonthTotals" type: array orgao: - $ref: '#/definitions/uiapi.agency' + $ref: "#/definitions/uiapi.agency" package: - $ref: '#/definitions/uiapi.backup' + $ref: "#/definitions/uiapi.backup" type: object uiapi.v2MonthTotals: properties: error: - $ref: '#/definitions/uiapi.procError' + $ref: "#/definitions/uiapi.procError" mes: type: integer outras_remuneracoes: @@ -446,16 +491,16 @@ definitions: remuneracao_base_por_membro: type: number timestamp: - $ref: '#/definitions/uiapi.timestamp' + $ref: "#/definitions/uiapi.timestamp" total_membros: type: integer type: object uiapi.v2ProcInfoResult: properties: proc_info: - $ref: '#/definitions/uiapi.procInfo' + $ref: "#/definitions/uiapi.procInfo" timestamp: - $ref: '#/definitions/uiapi.timestamp' + $ref: "#/definitions/uiapi.timestamp" type: object info: contact: @@ -469,19 +514,19 @@ paths: description: Retorna os dados anuais de um orgão operationId: GetAnnualSummary parameters: - - description: Nome do orgão - in: path - name: orgao - required: true - type: string + - description: Nome do orgão + in: path + name: orgao + required: true + type: string produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: items: - $ref: '#/definitions/uiapi.annualSummary' + $ref: "#/definitions/uiapi.annualSummary" type: array "400": description: Parâmetro orgao inválido @@ -492,35 +537,36 @@ paths: schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/download: get: description: Baixa dados referentes a remunerações a partir de filtros operationId: DownloadByUrl parameters: - - description: 'Anos a serem pesquisados, separados por virgula. Exemplo: 2018,2019,2020' - in: query - name: anos - type: string - - description: 'Meses a serem pesquisados, separados por virgula. Exemplo: 1,2,3' - in: query - name: meses - type: string - - description: 'Orgãos a serem pesquisados, separados por virgula. Exemplo: - tjal,mpal,mppb' - in: query - name: orgaos - type: string - - description: Categorias a serem pesquisadas - enum: - - base - - outras - - descontos - in: query - name: categorias - type: string + - description: "Anos a serem pesquisados, separados por virgula. Exemplo: 2018,2019,2020" + in: query + name: anos + type: string + - description: "Meses a serem pesquisados, separados por virgula. Exemplo: 1,2,3" + in: query + name: meses + type: string + - description: + "Orgãos a serem pesquisados, separados por virgula. Exemplo: + tjal,mpal,mppb" + in: query + name: orgaos + type: string + - description: Categorias a serem pesquisadas + enum: + - base + - outras + - descontos + in: query + name: categorias + type: string produces: - - application/json + - application/json responses: "200": description: Arquivo CSV com os dados. @@ -535,26 +581,27 @@ paths: schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/geral/remuneracao/{ano}: get: - description: Busca os dados, das remunerações de um ano inteiro, agrupados por + description: + Busca os dados, das remunerações de um ano inteiro, agrupados por mês. operationId: GetGeneralRemunerationFromYear parameters: - - description: 'Ano da remuneração. Exemplos: 2018, 2019, 2020...' - in: path - name: ano - required: true - type: string + - description: "Ano da remuneração. Exemplos: 2018, 2019, 2020..." + in: path + name: ano + required: true + type: string produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: items: - $ref: '#/definitions/uiapi.mensalRemuneration' + $ref: "#/definitions/uiapi.mensalRemuneration" type: array "400": description: Parâmetro ano inválido. @@ -565,76 +612,76 @@ paths: schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/geral/resumo: get: description: Busca e resume os dados das remunerações de todos os anos operationId: GetGeneralSummary produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: - $ref: '#/definitions/uiapi.generalSummary' + $ref: "#/definitions/uiapi.generalSummary" "500": description: Erro interno do servidor. schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/orgao/{grupo}: get: description: Busca os órgãos de um determinado grupo. operationId: GetBasicInfoOfType parameters: - - description: Grupo de órgãos - enum: - - justica-eleitoral - - ministerios-publicos - - justica-estadual - - justica-do-trabalho - - justica-federal - - justica-militar - - justica-superior - - conselhos-de-justica - - AC - - AL - - AP - - AM - - BA - - CE - - DF - - ES - - GO - - MA - - MT - - MS - - MG - - PA - - PB - - PR - - PE - - PI - - RJ - - RN - - RS - - RO - - RR - - SC - - SP - - SE - - TO - in: path - name: grupo - type: string + - description: Grupo de órgãos + enum: + - justica-eleitoral + - ministerios-publicos + - justica-estadual + - justica-do-trabalho + - justica-federal + - justica-militar + - justica-superior + - conselhos-de-justica + - AC + - AL + - AP + - AM + - BA + - CE + - DF + - ES + - GO + - MA + - MT + - MS + - MG + - PA + - PB + - PR + - PE + - PI + - RJ + - RN + - RS + - RO + - RR + - SC + - SP + - SE + - TO + in: path + name: grupo + type: string produces: - - application/json + - application/json responses: "200": description: Órgãos do grupo schema: - $ref: '#/definitions/uiapi.state' + $ref: "#/definitions/uiapi.state" "400": description: Parâmetro inválido schema: @@ -644,34 +691,34 @@ paths: schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/orgao/resumo/{orgao}/{ano}/{mes}: get: description: Resume os dados de remuneração mensal de um órgão. operationId: GetSummaryOfAgency parameters: - - description: 'ID do órgão. Exemplos: tjal, tjba, mppb.' - in: path - name: orgao - required: true - type: string - - description: 'Ano da remuneração. Exemplo: 2018.' - in: path - name: ano - required: true - type: integer - - description: 'Mês da remuneração. Exemplo: 1.' - in: path - name: mes - required: true - type: integer + - description: "ID do órgão. Exemplos: tjal, tjba, mppb." + in: path + name: orgao + required: true + type: string + - description: "Ano da remuneração. Exemplo: 2018." + in: path + name: ano + required: true + type: integer + - description: "Mês da remuneração. Exemplo: 1." + in: path + name: mes + required: true + type: integer produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: - $ref: '#/definitions/uiapi.v2AgencySummary' + $ref: "#/definitions/uiapi.v2AgencySummary" "400": description: Parâmetro ano, mês ou nome do órgão são inválidos. schema: @@ -681,106 +728,108 @@ paths: schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/orgao/salario/{orgao}/{ano}/{mes}: get: description: Busca dados das remunerações mensais de um órgão. operationId: GetSalaryOfAgencyMonthYear parameters: - - description: 'ID do órgão. Exemplos: tjal, tjba, mppb.' - in: path - name: orgao - required: true - type: string - - description: 'Mês da remuneração. Exemplos: 01, 02, 03...' - in: path - name: mes - required: true - type: string - - description: 'Ano da remuneração. Exemplos: 2018, 2019, 2020...' - in: path - name: ano - required: true - type: string + - description: "ID do órgão. Exemplos: tjal, tjba, mppb." + in: path + name: orgao + required: true + type: string + - description: "Mês da remuneração. Exemplos: 01, 02, 03..." + in: path + name: mes + required: true + type: string + - description: "Ano da remuneração. Exemplos: 2018, 2019, 2020..." + in: path + name: ano + required: true + type: string produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: - $ref: '#/definitions/uiapi.agencySalary' + $ref: "#/definitions/uiapi.agencySalary" "206": - description: Requisição bem sucedida, mas os dados do órgão não foram bem + description: + Requisição bem sucedida, mas os dados do órgão não foram bem processados schema: - $ref: '#/definitions/uiapi.v2ProcInfoResult' + $ref: "#/definitions/uiapi.v2ProcInfoResult" "400": description: Parâmetros inválidos. schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/orgao/totais/{orgao}/{ano}: get: description: Busca os dados de remuneração de um órgão em um ano específico. operationId: GetTotalsOfAgencyYear parameters: - - description: 'ID do órgão. Exemplos: tjal, tjba, mppb.' - in: path - name: orgao - required: true - type: string - - description: 'Ano. Exemplo: 2018.' - in: path - name: ano - required: true - type: integer + - description: "ID do órgão. Exemplos: tjal, tjba, mppb." + in: path + name: orgao + required: true + type: string + - description: "Ano. Exemplo: 2018." + in: path + name: ano + required: true + type: integer produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: - $ref: '#/definitions/uiapi.v2AgencyTotalsYear' + $ref: "#/definitions/uiapi.v2AgencyTotalsYear" "400": description: Parâmetro ano ou orgao inválido. schema: type: string tags: - - ui_api + - ui_api /uiapi/v2/pesquisar: get: description: Faz uma busca por remunerações a partir de filtros operationId: SearchByUrl parameters: - - description: 'Anos a serem pesquisados, separados por virgula. Exemplo: 2018,2019,2020' - in: query - name: anos - type: string - - description: 'Meses a serem pesquisados, separados por virgula. Exemplo: 1,2,3' - in: query - name: meses - type: string - - description: 'Orgãos a serem pesquisados, separados por virgula. Exemplo: - tjal,mpal,mppb' - in: query - name: orgaos - type: string - - description: Categorias a serem pesquisadas - enum: - - base - - outras - - descontos - in: query - name: categorias - type: string + - description: "Anos a serem pesquisados, separados por virgula. Exemplo: 2018,2019,2020" + in: query + name: anos + type: string + - description: "Meses a serem pesquisados, separados por virgula. Exemplo: 1,2,3" + in: query + name: meses + type: string + - description: + "Orgãos a serem pesquisados, separados por virgula. Exemplo: + tjal,mpal,mppb" + in: query + name: orgaos + type: string + - description: Categorias a serem pesquisadas + enum: + - base + - outras + - descontos + in: query + name: categorias + type: string produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: - $ref: '#/definitions/uiapi.searchResponse' + $ref: "#/definitions/uiapi.searchResponse" "400": description: Erro de validação dos parâmetros. schema: @@ -790,30 +839,53 @@ paths: schema: type: string tags: - - ui_api + - ui_api + /v2/dados/{orgao}: + get: + description: Busca todas as informações de um órgão específico. + operationId: GetAllAgencyInformation + parameters: + - description: órgão + in: path + name: orgao + required: true + type: string + produces: + - application/json + responses: + "200": + description: Requisição bem sucedida. + schema: + $ref: "#/definitions/papi.allAgencyInformation" + "400": + description: Requisição inválida. + schema: + type: string + tags: + - public_api /v2/dados/{orgao}/{ano}: get: description: Busca os dados mensais de um órgão por ano operationId: GetMonthlyInfosByYear parameters: - - description: Ano - in: path - name: ano - required: true - type: integer - - description: Órgão - in: path - name: orgao - required: true - type: string + - description: Ano + in: path + name: ano + required: true + type: integer + - description: Órgão + in: path + name: orgao + required: true + type: string produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida schema: items: - $ref: '#/definitions/papi.summaryzedMI' + $ref: "#/definitions/papi.summaryzedMI" type: array "400": description: Parâmetros inválidos @@ -824,34 +896,34 @@ paths: schema: type: string tags: - - public_api + - public_api /v2/dados/{orgao}/{ano}/{mes}: get: description: Busca um dado mensal de um órgão operationId: GetMonthlyInfo parameters: - - description: Ano - in: path - name: ano - required: true - type: integer - - description: Órgão - in: path - name: orgao - required: true - type: string - - description: Mês - in: path - name: mes - required: true - type: integer + - description: Ano + in: path + name: ano + required: true + type: integer + - description: Órgão + in: path + name: orgao + required: true + type: string + - description: Mês + in: path + name: mes + required: true + type: integer produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida schema: - $ref: '#/definitions/papi.summaryzedMI' + $ref: "#/definitions/papi.summaryzedMI" "400": description: Parâmetros inválidos schema: @@ -861,58 +933,58 @@ paths: schema: type: string tags: - - public_api + - public_api /v2/orgao/{orgao}: get: description: Busca um órgão específico utilizando seu ID. operationId: GetAgencyById parameters: - - description: 'ID do órgão. Exemplos: tjal, tjba, mppb.' - in: path - name: orgao - required: true - type: string + - description: "ID do órgão. Exemplos: tjal, tjba, mppb." + in: path + name: orgao + required: true + type: string produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: - $ref: '#/definitions/papi.agency' + $ref: "#/definitions/papi.agency" "404": description: Órgão não encontrado. schema: type: string tags: - - public_api + - public_api /v2/orgaos: get: description: Busca todos os órgãos disponíveis. operationId: GetAllAgencies produces: - - application/json + - application/json responses: "200": description: Requisição bem sucedida. schema: items: - $ref: '#/definitions/papi.agency' + $ref: "#/definitions/papi.agency" type: array "500": description: Erro interno do servidor. schema: type: string tags: - - public_api - /v2/indice/{param}/{valor}": - get: - description: Busca as informações de índices de um grupo ou órgão específico. - operationId: GetAggregateIndexes - parameters: + - public_api + /v2/indice/{param}/{valor}": + get: + description: Busca as informações de índices de um grupo ou órgão específico. + operationId: GetAggregateIndexes + parameters: - description: Tipo de parâmetro. - enum: - - grupo, - - orgao, + enum: + - grupo, + - orgao, type: string, name: param, in: path, @@ -922,34 +994,34 @@ paths: name: valor, in: path, required: true - produces: + produces: - application/json - responses: - "200": - description: Requisição bem sucedida., - schema: - type: array, - items: - $ref: '#/definitions/papi.aggregateIndexes' - "400": - description: Requisição inválida., - schema: - type: string - "500": - description: Erro interno do servidor., - schema: - type: string - tags: + responses: + "200": + description: Requisição bem sucedida., + schema: + type: array, + items: + $ref: "#/definitions/papi.aggregateIndexes" + "400": + description: Requisição inválida., + schema: + type: string + "500": + description: Erro interno do servidor., + schema: + type: string + tags: - public_api - /v2/indice/{param}/{valor}/{ano}": - get: - description: Busca as informações de índices de um grupo ou órgão específico para o ano informado. - operationId: GetAggregateIndexes - parameters: + /v2/indice/{param}/{valor}/{ano}": + get: + description: Busca as informações de índices de um grupo ou órgão específico para o ano informado. + operationId: GetAggregateIndexes + parameters: - description: Tipo de parâmetro. - enum: - - grupo, - - orgao, + enum: + - grupo, + - orgao, type: string, name: param, in: path, @@ -964,34 +1036,34 @@ paths: name: ano, in: path, required: true - produces: + produces: - application/json - responses: - "200": - description: Requisição bem sucedida., - schema: - type: array, - items: - $ref: '#/definitions/papi.aggregateIndexes' - "400": - description: Requisição inválida., - schema: - type: string - "500": - description: Erro interno do servidor., - schema: - type: string - tags: + responses: + "200": + description: Requisição bem sucedida., + schema: + type: array, + items: + $ref: "#/definitions/papi.aggregateIndexes" + "400": + description: Requisição inválida., + schema: + type: string + "500": + description: Erro interno do servidor., + schema: + type: string + tags: - public_api - /v2/indice/{param}/{valor}/{ano}/{mes}": - get: - description: Busca as informações de índices de um grupo ou órgão específico para o ano e mês informados. - operationId: GetAggregateIndexes - parameters: + /v2/indice/{param}/{valor}/{ano}/{mes}": + get: + description: Busca as informações de índices de um grupo ou órgão específico para o ano e mês informados. + operationId: GetAggregateIndexes + parameters: - description: Tipo de parâmetro. - enum: - - grupo, - - orgao, + enum: + - grupo, + - orgao, type: string, name: param, in: path, @@ -1011,74 +1083,74 @@ paths: name: mes, in: path, required: true - produces: + produces: - application/json - responses: - "200": - description: Requisição bem sucedida., - schema: - type: array, - items: - $ref: '#/definitions/papi.aggregateIndexes' - "400": - description: Requisição inválida., - schema: - type: string - "500": - description: Erro interno do servidor., - schema: - type: string - tags: + responses: + "200": + description: Requisição bem sucedida., + schema: + type: array, + items: + $ref: "#/definitions/papi.aggregateIndexes" + "400": + description: Requisição inválida., + schema: + type: string + "500": + description: Erro interno do servidor., + schema: + type: string + tags: - public_api /v2/indice: get: - description: Busca as informações de índices de todos os órgãos. - operationId: GetAggregateIndexes - produces: + description: Busca as informações de índices de todos os órgãos. + operationId: GetAggregateIndexes + produces: - application/json - responses: - "200": - description: Requisição bem sucedida., - schema: - type: array, - items: - $ref: '#/definitions/papi.aggregateIndexes' - "500": - description: Erro interno do servidor., - schema: - type: string - tags: + responses: + "200": + description: Requisição bem sucedida., + schema: + type: array, + items: + $ref: "#/definitions/papi.aggregateIndexes" + "500": + description: Erro interno do servidor., + schema: + type: string + tags: - public_api /v2/indices/{ano}: get: - description: Busca as informações de índices de todos os órgãos para um ano específico. - operationId: GetAggregateIndexes - parameters: + description: Busca as informações de índices de todos os órgãos para um ano específico. + operationId: GetAggregateIndexes + parameters: - description: Ano. type: string, name: ano, in: path, required: true - produces: + produces: - application/json - responses: - "200": - description: Requisição bem sucedida., - schema: - type: array, - items: - $ref: '#/definitions/papi.aggregateIndexes' - "500": - description: Erro interno do servidor., - schema: - type: string - tags: + responses: + "200": + description: Requisição bem sucedida., + schema: + type: array, + items: + $ref: "#/definitions/papi.aggregateIndexes" + "500": + description: Erro interno do servidor., + schema: + type: string + tags: - public_api /v2/indices/{ano}/{mes}: get: - description: Busca as informações de índices de todos os órgãos para um ano e mês específicos. - operationId: GetAggregateIndexes - parameters: + description: Busca as informações de índices de todos os órgãos para um ano e mês específicos. + operationId: GetAggregateIndexes + parameters: - description: Ano. type: string, name: ano, @@ -1089,19 +1161,19 @@ paths: name: mes, in: path, required: true - produces: + produces: - application/json - responses: - "200": - description: Requisição bem sucedida., - schema: - type: array, - items: - $ref: '#/definitions/papi.aggregateIndexes' - "500": - description: Erro interno do servidor., - schema: - type: string - tags: + responses: + "200": + description: Requisição bem sucedida., + schema: + type: array, + items: + $ref: "#/definitions/papi.aggregateIndexes" + "500": + description: Erro interno do servidor., + schema: + type: string + tags: - public_api swagger: "2.0" diff --git a/main.go b/main.go index d138ac4..af0a98c 100644 --- a/main.go +++ b/main.go @@ -223,6 +223,7 @@ func main() { apiGroupV2.GET("/indice", apiHandler.V2GetAggregateIndexes) apiGroupV2.GET("/indices/:ano", apiHandler.V2GetAggregateIndexes) apiGroupV2.GET("/indices/:ano/:mes", apiHandler.V2GetAggregateIndexes) + apiGroupV2.GET("/dados/:orgao", apiHandler.V2GetAllAgencyInformation) s := &http.Server{ Addr: fmt.Sprintf(":%d", conf.Port), diff --git a/papi/handlers.go b/papi/handlers.go index 1c1e66f..b9d5cc2 100644 --- a/papi/handlers.go +++ b/papi/handlers.go @@ -467,11 +467,11 @@ func (h handler) GetMonthlyInfosByYear(c echo.Context) error { // @Tags public_api // @Description Busca as informações de índices de um grupo ou órgão específico. // @Produce json -// @Success 200 {object} []aggregateIndexes "Requisição bem sucedida." -// @Failure 400 {string} string "Requisição inválida." -// @Failure 500 {string} string "Erro interno do servidor." -// @Param param path string true "'grupo' ou 'orgao'" -// @Param valor path string true "Jurisdição ou ID do órgao" +// @Success 200 {object} []aggregateIndexes "Requisição bem sucedida." +// @Failure 400 {string} string "Requisição inválida." +// @Failure 500 {string} string "Erro interno do servidor." +// @Param param path string true "'grupo' ou 'orgao'" +// @Param valor path string true "Jurisdição ou ID do órgao" // @Router /v2/indice/{param}/{valor} [get] func (h handler) V2GetAggregateIndexes(c echo.Context) error { param := c.Param("param") @@ -620,6 +620,110 @@ func (h handler) V2GetAggregateIndexes(c echo.Context) error { return c.JSON(http.StatusOK, aggregate) } +// @ID GetAllAgencyInformation +// @Tags public_api +// @Description Busca todas as informações de um órgão específico. +// @Produce json +// @Success 200 {object} allAgencyInformation "Requisição bem sucedida." +// @Failure 400 {string} string "Requisição inválida." +// @Param orgao path string true "órgão" +// @Router /v2/dados/{orgao} [get] +func (h handler) V2GetAllAgencyInformation(c echo.Context) error { + agency := strings.ToLower(c.Param("orgao")) + + ag, err := h.client.Db.GetAgency(agency) + if err != nil { + return c.JSON(http.StatusNotFound, fmt.Sprintf("Órgão não encontrado: %s", strings.ToUpper(agency))) + } + collections, err := h.client.Db.GetAllAgencyCollection(agency) + if err != nil { + return c.JSON(http.StatusNotFound, fmt.Sprintf("Não encontramos dados para o órgão %s", strings.ToUpper(agency))) + } + + aggregateScore := 0.0 + aggregateEasinessScore := 0.0 + aggregateCompletenessScore := 0.0 + numMonthsWithData := 0 + var result []summaryzedMI + + for _, c := range collections { + if c.ProcInfo == nil || c.ProcInfo.String() == "" { + result = append(result, summaryzedMI{ + Error: nil, + Month: c.Month, + Year: c.Year, + Summary: &summaries{ + MemberActive: summary{ + Count: c.Summary.Count, + BaseRemuneration: dataSummary{ + Max: c.Summary.BaseRemuneration.Max, + Min: c.Summary.BaseRemuneration.Min, + Average: c.Summary.BaseRemuneration.Average, + Total: c.Summary.BaseRemuneration.Total, + }, + OtherRemunerations: dataSummary{ + Max: c.Summary.OtherRemunerations.Max, + Min: c.Summary.OtherRemunerations.Min, + Average: c.Summary.OtherRemunerations.Average, + Total: c.Summary.OtherRemunerations.Total, + }, + }, + }, + Metadata: &metadata{ + OpenFormat: c.Meta.OpenFormat, + Access: c.Meta.Access, + Extension: c.Meta.Extension, + StrictlyTabular: c.Meta.StrictlyTabular, + ConsistentFormat: c.Meta.ConsistentFormat, + HasEnrollment: c.Meta.HaveEnrollment, + HasCapacity: c.Meta.ThereIsACapacity, + HasPosition: c.Meta.HasPosition, + BaseRevenue: c.Meta.BaseRevenue, + OtherRecipes: c.Meta.OtherRecipes, + Expenditure: c.Meta.Expenditure, + }, + Score: &score{ + Score: c.Score.Score, + CompletenessScore: c.Score.CompletenessScore, + EasinessScore: c.Score.EasinessScore, + }}) + numMonthsWithData++ + } + aggregateScore += c.Score.Score + aggregateCompletenessScore += c.Score.CompletenessScore + aggregateEasinessScore += c.Score.EasinessScore + } + + var collect []collecting + for _, c := range ag.Collecting { + collect = append(collect, collecting{ + Timestamp: c.Timestamp, + Description: c.Description, + }) + } + + agencyInfo := allAgencyInformation{ + ID: ag.ID, + Name: ag.Name, + Type: ag.Type, + Entity: ag.Entity, + UF: ag.UF, + URL: ag.URL, + Collecting: collect, + TwitterHandle: ag.TwitterHandle, + OmbudsmanURL: ag.OmbudsmanURL, + TotalCollections: len(collections), + NumMonthsWithData: numMonthsWithData, + Score: &score{ + Score: aggregateScore / float64(len(collections)), + EasinessScore: aggregateEasinessScore / float64(len(collections)), + CompletenessScore: aggregateCompletenessScore / float64(len(collections)), + }, + Collections: result, + } + return c.JSON(http.StatusOK, agencyInfo) +} + func (h handler) formatDownloadUrl(url string) string { return strings.Replace(url, h.packageRepoURL, h.dadosJusURL, -1) } diff --git a/papi/models.go b/papi/models.go index 46c82b1..a96779c 100644 --- a/papi/models.go +++ b/papi/models.go @@ -100,3 +100,19 @@ type indexInformation struct { Score *score `json:"indice_transparencia,omitempty"` Metadata *metadata `json:"metadados,omitempty"` } + +type allAgencyInformation struct { + ID string `json:"id_orgao,omitempty"` // 'trt13' + Name string `json:"nome,omitempty"` // 'Tribunal Regional do Trabalho 13° Região' + Type string `json:"jurisdicao,omitempty"` // "R" for Regional, "M" for Municipal, "F" for Federal, "E" for State. + Entity string `json:"entidade,omitempty"` // "J" For Judiciário, "M" for Ministério Público, "P" for Procuradorias and "D" for Defensorias. + UF string `json:"uf,omitempty"` // Short code for federative unity. + URL string `json:"url,omitempty"` // Link for state url + Collecting []collecting `json:"coletando,omitempty"` + TwitterHandle string `json:"twitter_handle,omitempty"` // Agency's twitter handle + OmbudsmanURL string `json:"ouvidoria,omitempty"` //Agencys's ombudsman url + TotalCollections int `json:"total_coletas_realizadas,omitempty"` + NumMonthsWithData int `json:"meses_com_dados"` + Score *score `json:"indice_transparencia,omitempty"` + Collections []summaryzedMI `json:"coletas"` +} From 4a988b9ebde50b9681f47ac1d9d3410b54b7fac8 Mon Sep 17 00:00:00 2001 From: Joellensilva Date: Wed, 17 May 2023 13:27:47 -0300 Subject: [PATCH 2/2] =?UTF-8?q?atualizando=20vers=C3=A3o=20storage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index fcdbff2..41c1b2d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/dadosjusbr/proto v0.0.0-20221212025627-91c60aa3cd12 - github.com/dadosjusbr/storage v0.0.0-20230420170502-31dc5a2caf92 + github.com/dadosjusbr/storage v0.0.0-20230516114123-dc6ae51c4bb1 github.com/gocarina/gocsv v0.0.0-20220712153207-8b2118da4570 github.com/golang/mock v1.6.0 github.com/joho/godotenv v1.4.0 diff --git a/go.sum b/go.sum index 039e25e..cc9bfa7 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,8 @@ github.com/dadosjusbr/storage v0.0.0-20230413185823-e1bb61c2aff7 h1:Fk8O0T88k8Lx github.com/dadosjusbr/storage v0.0.0-20230413185823-e1bb61c2aff7/go.mod h1:ttc45wBL5bjz5uU24mgNNPV9ZHaJ3SmoRwVOmyVRZyY= github.com/dadosjusbr/storage v0.0.0-20230420170502-31dc5a2caf92 h1:73BiNvlognV5PGCy6fWxa7T8QTxl8R84sU/hWC0ulKA= github.com/dadosjusbr/storage v0.0.0-20230420170502-31dc5a2caf92/go.mod h1:ttc45wBL5bjz5uU24mgNNPV9ZHaJ3SmoRwVOmyVRZyY= +github.com/dadosjusbr/storage v0.0.0-20230516114123-dc6ae51c4bb1 h1:cW0gM/0LR2Zth/lvO4plo0YWCZb4oZ686tIXgLcI0QE= +github.com/dadosjusbr/storage v0.0.0-20230516114123-dc6ae51c4bb1/go.mod h1:ttc45wBL5bjz5uU24mgNNPV9ZHaJ3SmoRwVOmyVRZyY= 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=