Align loan type and required document schema with updated column names.

Rename loan_required_documents to loan_order_required_docs, simplify document fields to name/value, and map loan_types columns to name, maturity, notes, and active.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
guwandykandCursor committed 2026-07-06 22:48:19 +05:00
1 parent 08be61cbcd
commit ef56625321
9 files changed
+66 -89

No files matched your search

+20 -15
View File
@@ -23,9 +23,9 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) loantype.Re
return &repository{client: client, logger: logger}
}
const loanTypeColumns = `lt.id, lt.title, lt.tax, lt.loan_term, lt.content, lt.created_at, lt.updated_at`
const loanTypeColumns = `lt.id, lt.name, lt.tax, lt.maturity, lt.notes, lt.active, lt.created_at, lt.updated_at`
const loanTypeReturningColumns = `id, title, tax, loan_term, content, created_at, updated_at`
const loanTypeReturningColumns = `id, name, tax, maturity, notes, active, created_at, updated_at`
func (r *repository) List(ctx context.Context, filter loantype.ListFilter) (loantype.ListLoanTypeDTO, error) {
fromClause, whereClause, args := buildListQuery(filter)
@@ -72,7 +72,7 @@ func buildListQuery(filter loantype.ListFilter) (fromClause, whereClause string,
args = append(args, likePattern(filter.LoanTypeName))
n := len(args)
conditions = append(conditions, fmt.Sprintf(`(
lt.title->>'en' ILIKE $%[1]d OR lt.title->>'ru' ILIKE $%[1]d OR lt.title->>'tm' ILIKE $%[1]d
lt.name->>'en' ILIKE $%[1]d OR lt.name->>'ru' ILIKE $%[1]d OR lt.name->>'tm' ILIKE $%[1]d
)`, n))
}
@@ -100,33 +100,38 @@ func (r *repository) GetByID(ctx context.Context, id int64) (loantype.LoanTypeDT
}
func (r *repository) Create(ctx context.Context, dto loantype.CreateLoanTypeDTO) (loantype.LoanTypeDTO, error) {
title, content, err := marshalJSON(dto.Title, dto.Content)
name, notes, err := marshalJSON(dto.Title, dto.Content)
if err != nil {
return loantype.LoanTypeDTO{}, err
}
active := true
if dto.Active != nil {
active = *dto.Active
}
query := fmt.Sprintf(`
INSERT INTO loan_types (title, tax, loan_term, content)
VALUES ($1, $2, $3, $4)
INSERT INTO loan_types (name, tax, maturity, notes, active)
VALUES ($1, $2, $3, $4, $5)
RETURNING %s`, loanTypeReturningColumns)
return scanLoanType(r.client.QueryRow(ctx, query, title, dto.Tax, dto.LoanTerm, content))
return scanLoanType(r.client.QueryRow(ctx, query, name, dto.Tax, dto.LoanTerm, notes, active))
}
func (r *repository) Update(ctx context.Context, id int64, dto loantype.UpdateLoanTypeDTO) (loantype.LoanTypeDTO, error) {
title, content, err := marshalJSON(dto.Title, dto.Content)
name, notes, err := marshalJSON(dto.Title, dto.Content)
if err != nil {
return loantype.LoanTypeDTO{}, err
}
query := fmt.Sprintf(`
UPDATE loan_types SET
title = $1, tax = $2, loan_term = $3, content = $4,
name = $1, tax = $2, maturity = $3, notes = $4, active = $5,
updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
WHERE id = $5
WHERE id = $6
RETURNING %s`, loanTypeReturningColumns)
item, err := scanLoanType(r.client.QueryRow(ctx, query, title, dto.Tax, dto.LoanTerm, content, id))
item, err := scanLoanType(r.client.QueryRow(ctx, query, name, dto.Tax, dto.LoanTerm, notes, dto.Active, id))
if errors.Is(err, pgx.ErrNoRows) {
return loantype.LoanTypeDTO{}, err
}
@@ -162,17 +167,17 @@ type scannable interface {
func scanLoanType(row scannable) (loantype.LoanTypeDTO, error) {
var item loantype.LoanTypeDTO
var titleJSON, contentJSON []byte
var nameJSON, notesJSON []byte
if err := row.Scan(
&item.Id, &titleJSON, &item.Tax, &item.LoanTerm, &contentJSON, &item.CreatedAt, &item.UpdatedAt,
&item.Id, &nameJSON, &item.Tax, &item.LoanTerm, &notesJSON, &item.Active, &item.CreatedAt, &item.UpdatedAt,
); err != nil {
return loantype.LoanTypeDTO{}, err
}
if err := json.Unmarshal(titleJSON, &item.Title); err != nil {
if err := json.Unmarshal(nameJSON, &item.Title); err != nil {
return loantype.LoanTypeDTO{}, err
}
if err := json.Unmarshal(contentJSON, &item.Content); err != nil {
if err := json.Unmarshal(notesJSON, &item.Content); err != nil {
return loantype.LoanTypeDTO{}, err
}
return item, nil
+3
View File
@@ -14,6 +14,7 @@ type LoanTypeDTO struct {
Tax float64 `json:"tax"`
LoanTerm string `json:"loanTerm"`
Content LocalizedTitle `json:"content"`
Active bool `json:"active"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
@@ -23,6 +24,7 @@ type CreateLoanTypeDTO struct {
Tax float64 `json:"tax" binding:"required"`
LoanTerm string `json:"loanTerm" binding:"required"`
Content LocalizedTitle `json:"content" binding:"required"`
Active *bool `json:"active"`
}
type UpdateLoanTypeDTO struct {
@@ -30,6 +32,7 @@ type UpdateLoanTypeDTO struct {
Tax float64 `json:"tax" binding:"required"`
LoanTerm string `json:"loanTerm" binding:"required"`
Content LocalizedTitle `json:"content" binding:"required"`
Active bool `json:"active"`
}
type ListFilter struct {