From 6d44960b36d2b0e87e019056da562f3fa8552704 Mon Sep 17 00:00:00 2001 From: Joellensilva Date: Tue, 11 Jun 2024 17:12:19 -0300 Subject: [PATCH] adicionando coluna nome_sanitizado --- models/paychecks.go | 29 ++++++----- repo/database/dto/paychecksDTO.go | 87 ++++++++++++++++--------------- repo/database/init_db.sql | 1 + repo/database/postgres_test.go | 30 ++++++----- 4 files changed, 77 insertions(+), 70 deletions(-) diff --git a/models/paychecks.go b/models/paychecks.go index 03ef5f9..48710ab 100644 --- a/models/paychecks.go +++ b/models/paychecks.go @@ -1,20 +1,21 @@ package models type Paycheck struct { - ID int `json:"id,omitempty"` - Agency string `json:"orgao,omitempty"` - Month int `json:"mes,omitempty"` - Year int `json:"ano,omitempty"` - CollectKey string `json:"chave_coleta,omitempty"` - Name string `json:"nome,omitempty"` - RegisterID string `json:"matricula,omitempty"` - Role string `json:"funcao,omitempty"` - Workplace string `json:"local_trabalho,omitempty"` - Salary float64 `json:"salario,omitempty"` - Benefits float64 `json:"beneficios,omitempty"` - Discounts float64 `json:"descontos,omitempty"` - Remuneration float64 `json:"remuneracao,omitempty"` - Situation *string `json:"situacao,omitempty"` + ID int `json:"id,omitempty"` + Agency string `json:"orgao,omitempty"` + Month int `json:"mes,omitempty"` + Year int `json:"ano,omitempty"` + CollectKey string `json:"chave_coleta,omitempty"` + Name string `json:"nome,omitempty"` + RegisterID string `json:"matricula,omitempty"` + Role string `json:"funcao,omitempty"` + Workplace string `json:"local_trabalho,omitempty"` + Salary float64 `json:"salario,omitempty"` + Benefits float64 `json:"beneficios,omitempty"` + Discounts float64 `json:"descontos,omitempty"` + Remuneration float64 `json:"remuneracao,omitempty"` + Situation *string `json:"situacao,omitempty"` + SanitizedName string `json:"nome_sanitizado,omitempty"` } type PaycheckItem struct { diff --git a/repo/database/dto/paychecksDTO.go b/repo/database/dto/paychecksDTO.go index b09d510..34ebb15 100644 --- a/repo/database/dto/paychecksDTO.go +++ b/repo/database/dto/paychecksDTO.go @@ -3,20 +3,21 @@ package dto import "github.com/dadosjusbr/storage/models" type PaycheckDTO struct { - ID int `gorm:"column:id"` - Agency string `gorm:"column:orgao"` - Month int `gorm:"column:mes"` - Year int `gorm:"column:ano"` - CollectKey string `gorm:"column:chave_coleta"` - Name string `gorm:"column:nome"` - RegisterID string `gorm:"column:matricula"` - Role string `gorm:"column:funcao"` - Workplace string `gorm:"column:local_trabalho"` - Salary float64 `gorm:"column:salario"` - Benefits float64 `gorm:"column:beneficios"` - Discounts float64 `gorm:"column:descontos"` - Remuneration float64 `gorm:"column:remuneracao"` - Situation *string `gorm:"column:situacao"` + ID int `gorm:"column:id"` + Agency string `gorm:"column:orgao"` + Month int `gorm:"column:mes"` + Year int `gorm:"column:ano"` + CollectKey string `gorm:"column:chave_coleta"` + Name string `gorm:"column:nome"` + RegisterID string `gorm:"column:matricula"` + Role string `gorm:"column:funcao"` + Workplace string `gorm:"column:local_trabalho"` + Salary float64 `gorm:"column:salario"` + Benefits float64 `gorm:"column:beneficios"` + Discounts float64 `gorm:"column:descontos"` + Remuneration float64 `gorm:"column:remuneracao"` + Situation *string `gorm:"column:situacao"` + SanitizedName string `gorm:"column:nome_sanitizado"` } func (PaycheckDTO) TableName() string { @@ -25,38 +26,40 @@ func (PaycheckDTO) TableName() string { func (p PaycheckDTO) ConvertToModel() *models.Paycheck { return &models.Paycheck{ - ID: p.ID, - Agency: p.Agency, - Month: p.Month, - Year: p.Year, - CollectKey: p.CollectKey, - Name: p.Name, - RegisterID: p.RegisterID, - Role: p.Role, - Workplace: p.Workplace, - Salary: p.Salary, - Benefits: p.Benefits, - Discounts: p.Discounts, - Remuneration: p.Remuneration, - Situation: p.Situation, + ID: p.ID, + Agency: p.Agency, + Month: p.Month, + Year: p.Year, + CollectKey: p.CollectKey, + Name: p.Name, + RegisterID: p.RegisterID, + Role: p.Role, + Workplace: p.Workplace, + Salary: p.Salary, + Benefits: p.Benefits, + Discounts: p.Discounts, + Remuneration: p.Remuneration, + Situation: p.Situation, + SanitizedName: p.SanitizedName, } } func NewPaycheckDTO(p models.Paycheck) *PaycheckDTO { return &PaycheckDTO{ - ID: p.ID, - Agency: p.Agency, - Month: p.Month, - Year: p.Year, - CollectKey: p.CollectKey, - Name: p.Name, - RegisterID: p.RegisterID, - Role: p.Role, - Workplace: p.Workplace, - Salary: p.Salary, - Benefits: p.Benefits, - Discounts: p.Discounts, - Remuneration: p.Remuneration, - Situation: p.Situation, + ID: p.ID, + Agency: p.Agency, + Month: p.Month, + Year: p.Year, + CollectKey: p.CollectKey, + Name: p.Name, + RegisterID: p.RegisterID, + Role: p.Role, + Workplace: p.Workplace, + Salary: p.Salary, + Benefits: p.Benefits, + Discounts: p.Discounts, + Remuneration: p.Remuneration, + Situation: p.Situation, + SanitizedName: p.SanitizedName, } } diff --git a/repo/database/init_db.sql b/repo/database/init_db.sql index e9acba0..1c1c8d1 100644 --- a/repo/database/init_db.sql +++ b/repo/database/init_db.sql @@ -77,6 +77,7 @@ create table contracheques descontos numeric, remuneracao numeric, situacao varchar(5), + nome_sanitizado varchar(150), constraint contracheques_pk primary key (id, orgao, mes, ano) ); diff --git a/repo/database/postgres_test.go b/repo/database/postgres_test.go index 71d958b..cadcba9 100644 --- a/repo/database/postgres_test.go +++ b/repo/database/postgres_test.go @@ -2169,6 +2169,7 @@ func (paycheck) testStorePaychecks(t *testing.T) { assert.Equal(t, len(dtoPaychecks), 1) assert.Equal(t, len(dtoPaycheckItems), 3) assert.Equal(t, dtoPaychecks[0].Name, "nome") + assert.Equal(t, dtoPaychecks[0].SanitizedName, "nome") assert.Equal(t, dtoPaychecks[0].Remuneration, 2000.0) assert.Equal(t, dtoPaycheckItems[0].Type, "R/B") assert.Equal(t, dtoPaycheckItems[1].Inconsistent, true) @@ -2296,20 +2297,21 @@ func paychecks() ([]models.Paycheck, []models.PaycheckItem) { situation := "A" p := []models.Paycheck{ { - ID: 1, - Agency: "tjal", - Month: 5, - Year: 2023, - CollectKey: "tjal/05/2023", - Name: "nome", - RegisterID: "123", - Role: "funcao", - Workplace: "local de trabalho", - Salary: 1000, - Benefits: 1200, - Discounts: 200, - Remuneration: 2000, - Situation: &situation, + ID: 1, + Agency: "tjal", + Month: 5, + Year: 2023, + CollectKey: "tjal/05/2023", + Name: "nome", + RegisterID: "123", + Role: "funcao", + Workplace: "local de trabalho", + Salary: 1000, + Benefits: 1200, + Discounts: 200, + Remuneration: 2000, + Situation: &situation, + SanitizedName: "nome", }, } itemSanitizado := []string{"subsidio", "descontos diversos"}