Skip to content

Commit

Permalink
chore: refactor monthlyInfoDTO to include ManualCollection flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JezzDiego committed Sep 10, 2024
1 parent 43ac5da commit f21457d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
3 changes: 2 additions & 1 deletion models/monthlyInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
47 changes: 25 additions & 22 deletions repo/database/dto/monthlyInfoDTO.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions repo/database/init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions repo/database/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}

Expand Down

0 comments on commit f21457d

Please sign in to comment.