Skip to content

Commit

Permalink
adicionando coluna nome_sanitizado
Browse files Browse the repository at this point in the history
  • Loading branch information
joellensilva committed Jun 11, 2024
1 parent 43ac5da commit 6d44960
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 70 deletions.
29 changes: 15 additions & 14 deletions models/paychecks.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
87 changes: 45 additions & 42 deletions repo/database/dto/paychecksDTO.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
1 change: 1 addition & 0 deletions repo/database/init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
30 changes: 16 additions & 14 deletions repo/database/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 6d44960

Please sign in to comment.