changed column name
This commit is contained in:
@@ -23,7 +23,9 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) loansdocume
|
||||
return &repository{client: client, logger: logger}
|
||||
}
|
||||
|
||||
const documentColumns = `d.id, d.title, d.content_en, d.content_ru, d.content_tm, d.status, d.created_at, d.updated_at`
|
||||
const documentColumns = `d.id, d.title, d.content_en, d.content_ru, d.content_tm, d.active, d.created_at, d.updated_at`
|
||||
|
||||
const documentReturningColumns = `id, title, content_en, content_ru, content_tm, active, created_at, updated_at`
|
||||
|
||||
func (r *repository) List(ctx context.Context, filter loansdocument.ListFilter) (loansdocument.ListLoanDocumentDTO, error) {
|
||||
fromClause, whereClause, args := buildListQuery(filter)
|
||||
@@ -75,9 +77,9 @@ func buildListQuery(filter loansdocument.ListFilter) (fromClause, whereClause st
|
||||
)`, n))
|
||||
}
|
||||
|
||||
if filter.Status != nil {
|
||||
args = append(args, *filter.Status)
|
||||
conditions = append(conditions, fmt.Sprintf("d.status = $%d", len(args)))
|
||||
if filter.Active != nil {
|
||||
args = append(args, *filter.Active)
|
||||
conditions = append(conditions, fmt.Sprintf("d.active = $%d", len(args)))
|
||||
}
|
||||
|
||||
if len(conditions) == 0 {
|
||||
@@ -109,17 +111,17 @@ func (r *repository) Create(ctx context.Context, dto loansdocument.CreateLoanDoc
|
||||
return loansdocument.LoanDocumentDTO{}, err
|
||||
}
|
||||
|
||||
status := true
|
||||
if dto.Status != nil {
|
||||
status = *dto.Status
|
||||
active := true
|
||||
if dto.Active != nil {
|
||||
active = *dto.Active
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`
|
||||
INSERT INTO loan_required_documents (title, content_en, content_ru, content_tm, status)
|
||||
INSERT INTO loan_required_documents (title, content_en, content_ru, content_tm, active)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING %s`, documentColumns)
|
||||
RETURNING %s`, documentReturningColumns)
|
||||
|
||||
return scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, status))
|
||||
return scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, active))
|
||||
}
|
||||
|
||||
func (r *repository) Update(ctx context.Context, id int64, dto loansdocument.UpdateLoanDocumentDTO) (loansdocument.LoanDocumentDTO, error) {
|
||||
@@ -130,27 +132,27 @@ func (r *repository) Update(ctx context.Context, id int64, dto loansdocument.Upd
|
||||
|
||||
query := fmt.Sprintf(`
|
||||
UPDATE loan_required_documents SET
|
||||
title = $1, content_en = $2, content_ru = $3, content_tm = $4, status = $5,
|
||||
title = $1, content_en = $2, content_ru = $3, content_tm = $4, active = $5,
|
||||
updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
|
||||
WHERE id = $6
|
||||
RETURNING %s`, documentColumns)
|
||||
RETURNING %s`, documentReturningColumns)
|
||||
|
||||
item, err := scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, dto.Status, id))
|
||||
item, err := scanLoanDocument(r.client.QueryRow(ctx, query, title, dto.ContentEn, dto.ContentRu, dto.ContentTm, dto.Active, id))
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return loansdocument.LoanDocumentDTO{}, err
|
||||
}
|
||||
return item, err
|
||||
}
|
||||
|
||||
func (r *repository) UpdateStatus(ctx context.Context, id int64, status bool) (loansdocument.LoanDocumentDTO, error) {
|
||||
func (r *repository) UpdateActive(ctx context.Context, id int64, active bool) (loansdocument.LoanDocumentDTO, error) {
|
||||
query := fmt.Sprintf(`
|
||||
UPDATE loan_required_documents SET
|
||||
status = $1,
|
||||
active = $1,
|
||||
updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
|
||||
WHERE id = $2
|
||||
RETURNING %s`, documentColumns)
|
||||
RETURNING %s`, documentReturningColumns)
|
||||
|
||||
item, err := scanLoanDocument(r.client.QueryRow(ctx, query, status, id))
|
||||
item, err := scanLoanDocument(r.client.QueryRow(ctx, query, active, id))
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return loansdocument.LoanDocumentDTO{}, err
|
||||
}
|
||||
@@ -178,7 +180,7 @@ func scanLoanDocument(row scannable) (loansdocument.LoanDocumentDTO, error) {
|
||||
|
||||
if err := row.Scan(
|
||||
&item.Id, &titleJSON, &item.ContentEn, &item.ContentRu, &item.ContentTm,
|
||||
&item.Status, &item.CreatedAt, &item.UpdatedAt,
|
||||
&item.Active, &item.CreatedAt, &item.UpdatedAt,
|
||||
); err != nil {
|
||||
return loansdocument.LoanDocumentDTO{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user