From f21457d6442675001048aa7d6a18df38f5556856 Mon Sep 17 00:00:00 2001 From: JezzDiego Date: Tue, 10 Sep 2024 09:55:13 -0300 Subject: [PATCH] chore: refactor monthlyInfoDTO to include ManualCollection flag --- models/monthlyInfo.go | 3 +- repo/database/dto/monthlyInfoDTO.go | 47 +++++++++++++++-------------- repo/database/init_db.sql | 1 + repo/database/postgres_test.go | 5 +++ 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/models/monthlyInfo.go b/models/monthlyInfo.go index 7a435fc..afb0cf7 100644 --- a/models/monthlyInfo.go +++ b/models/monthlyInfo.go @@ -35,7 +35,8 @@ type AgencyMonthlyInfo struct { Package *Backup `json:"package,omitempty"` // Making this a pointer because it should be an optional field due to backwards compatibility. Meta *Meta `json:"meta,omitempty"` Score *Score `json:"score,omitempty"` - Duration float64 `json:"duration,omitempty"` // Crawling duration (seconds) + Duration float64 `json:"duration,omitempty"` // Crawling duration (seconds) + ManualCollection bool `json:"coleta_manual,omitempty"` // If the data was collected manually } type Meta struct { diff --git a/repo/database/dto/monthlyInfoDTO.go b/repo/database/dto/monthlyInfoDTO.go index f242e95..18b2f6d 100644 --- a/repo/database/dto/monthlyInfoDTO.go +++ b/repo/database/dto/monthlyInfoDTO.go @@ -31,6 +31,7 @@ type AgencyMonthlyInfoDTO struct { Duration float64 `gorm:"column:duracao_segundos"` // Tempo de execução da coleta em segundos Meta Score + ManualCollection bool `gorm:"column:manual"` // Tempo de execução da coleta em segundos } func (AgencyMonthlyInfoDTO) TableName() string { @@ -126,11 +127,12 @@ func (a AgencyMonthlyInfoDTO) ConvertToModel() (*models.AgencyMonthlyInfo, error BaseRevenue: a.Meta.BaseRevenue, OtherRecipes: a.Meta.OtherRecipes, }, - Summary: &summary, - Backups: []models.Backup{backup}, - ProcInfo: &procInfo, - Package: &pkg, - Duration: a.Duration, + Summary: &summary, + Backups: []models.Backup{backup}, + ProcInfo: &procInfo, + Package: &pkg, + Duration: a.Duration, + ManualCollection: a.ManualCollection, }, nil } @@ -192,23 +194,24 @@ func NewAgencyMonthlyInfoDTO(agmi models.AgencyMonthlyInfo) (*AgencyMonthlyInfoD } return &AgencyMonthlyInfoDTO{ - ID: fmt.Sprintf("%s/%s/%d", agmi.AgencyID, AddZeroes(agmi.Month), agmi.Year), - Actual: true, - AgencyID: agmi.AgencyID, - Month: agmi.Month, - Year: agmi.Year, - CrawlerVersion: agmi.CrawlerVersion, - CrawlerRepo: agmi.CrawlerRepo, - ParserRepo: agmi.ParserRepo, - ParserVersion: agmi.ParserVersion, - Timestamp: timestamp, - Score: score, - Meta: meta, - Summary: summary, - Backup: backup, - ProcInfo: procInfo, - Package: pkg, - Duration: agmi.Duration, + ID: fmt.Sprintf("%s/%s/%d", agmi.AgencyID, AddZeroes(agmi.Month), agmi.Year), + Actual: true, + AgencyID: agmi.AgencyID, + Month: agmi.Month, + Year: agmi.Year, + CrawlerVersion: agmi.CrawlerVersion, + CrawlerRepo: agmi.CrawlerRepo, + ParserRepo: agmi.ParserRepo, + ParserVersion: agmi.ParserVersion, + Timestamp: timestamp, + Score: score, + Meta: meta, + Summary: summary, + Backup: backup, + ProcInfo: procInfo, + Package: pkg, + Duration: agmi.Duration, + ManualCollection: agmi.ManualCollection, }, nil } diff --git a/repo/database/init_db.sql b/repo/database/init_db.sql index e9acba0..1e43c48 100644 --- a/repo/database/init_db.sql +++ b/repo/database/init_db.sql @@ -43,6 +43,7 @@ create table coletas backups json, formato_aberto boolean, duracao_segundos double precision, + manual boolean, constraint coleta_pk primary key (id,timestamp), constraint coleta_orgao_fk foreign key (id_orgao) references orgaos(id) on delete cascade diff --git a/repo/database/postgres_test.go b/repo/database/postgres_test.go index 71d958b..fcdcd33 100644 --- a/repo/database/postgres_test.go +++ b/repo/database/postgres_test.go @@ -787,12 +787,14 @@ func (g getMonthlyInfo) testWhenMonthlyInfoExists(t *testing.T) { Year: 2020, Month: 1, CrawlingTimestamp: timestamppb.Now(), + ManualCollection: false, }, { AgencyID: "tjsp", Year: 2020, Month: 1, CrawlingTimestamp: timestamppb.Now(), + ManualCollection: true, }, } if err := insertMonthlyInfos(agmis); err != nil { @@ -812,6 +814,9 @@ func (g getMonthlyInfo) testWhenMonthlyInfoExists(t *testing.T) { assert.Equal(t, agmiMap["tjsp"][0].AgencyID, returnedAgmis["tjsp"][0].AgencyID) assert.Equal(t, agmiMap["tjsp"][0].Year, returnedAgmis["tjsp"][0].Year) assert.Equal(t, agmiMap["tjsp"][0].Month, returnedAgmis["tjsp"][0].Month) + assert.Equal(t, agmiMap["tjal"][0].ManualCollection, returnedAgmis["tjal"][0].ManualCollection) + assert.Equal(t, agmiMap["tjsp"][0].ManualCollection, returnedAgmis["tjsp"][0].ManualCollection) + truncateTables() }