changed column name
This commit is contained in:
@@ -23,7 +23,9 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) paymentcard
|
||||
return &repository{client: client, logger: logger}
|
||||
}
|
||||
|
||||
const cardColumns = `c.id, c.price, c.title, c.content, c.status`
|
||||
const cardColumns = `c.id, c.price, c.title, c.content, c.active`
|
||||
|
||||
const cardReturningColumns = `id, price, title, content, active`
|
||||
|
||||
func (r *repository) List(ctx context.Context, filter paymentcard.ListFilter) (paymentcard.ListPaymentCardDTO, error) {
|
||||
fromClause, whereClause, args := buildListQuery(filter)
|
||||
@@ -75,9 +77,9 @@ func buildListQuery(filter paymentcard.ListFilter) (fromClause, whereClause stri
|
||||
)`, n))
|
||||
}
|
||||
|
||||
if filter.Status != nil {
|
||||
args = append(args, *filter.Status)
|
||||
conditions = append(conditions, fmt.Sprintf("c.status = $%d", len(args)))
|
||||
if filter.Active != nil {
|
||||
args = append(args, *filter.Active)
|
||||
conditions = append(conditions, fmt.Sprintf("c.active = $%d", len(args)))
|
||||
}
|
||||
|
||||
if len(conditions) == 0 {
|
||||
@@ -109,17 +111,17 @@ func (r *repository) Create(ctx context.Context, dto paymentcard.CreatePaymentCa
|
||||
return paymentcard.PaymentCardDTO{}, err
|
||||
}
|
||||
|
||||
status := true
|
||||
if dto.Status != nil {
|
||||
status = *dto.Status
|
||||
active := true
|
||||
if dto.Active != nil {
|
||||
active = *dto.Active
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`
|
||||
INSERT INTO payment_cards (price, title, content, status)
|
||||
INSERT INTO payment_cards (price, title, content, active)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING %s`, cardColumns)
|
||||
RETURNING %s`, cardReturningColumns)
|
||||
|
||||
return scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, status))
|
||||
return scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, active))
|
||||
}
|
||||
|
||||
func (r *repository) Update(ctx context.Context, id int64, dto paymentcard.UpdatePaymentCardDTO) (paymentcard.PaymentCardDTO, error) {
|
||||
@@ -130,24 +132,24 @@ func (r *repository) Update(ctx context.Context, id int64, dto paymentcard.Updat
|
||||
|
||||
query := fmt.Sprintf(`
|
||||
UPDATE payment_cards SET
|
||||
price = $1, title = $2, content = $3, status = $4
|
||||
price = $1, title = $2, content = $3, active = $4
|
||||
WHERE id = $5
|
||||
RETURNING %s`, cardColumns)
|
||||
RETURNING %s`, cardReturningColumns)
|
||||
|
||||
item, err := scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, dto.Status, id))
|
||||
item, err := scanPaymentCard(r.client.QueryRow(ctx, query, dto.Price, title, content, dto.Active, id))
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return paymentcard.PaymentCardDTO{}, err
|
||||
}
|
||||
return item, err
|
||||
}
|
||||
|
||||
func (r *repository) UpdateStatus(ctx context.Context, id int64, status bool) (paymentcard.PaymentCardDTO, error) {
|
||||
func (r *repository) UpdateActive(ctx context.Context, id int64, active bool) (paymentcard.PaymentCardDTO, error) {
|
||||
query := fmt.Sprintf(`
|
||||
UPDATE payment_cards SET status = $1
|
||||
UPDATE payment_cards SET active = $1
|
||||
WHERE id = $2
|
||||
RETURNING %s`, cardColumns)
|
||||
RETURNING %s`, cardReturningColumns)
|
||||
|
||||
item, err := scanPaymentCard(r.client.QueryRow(ctx, query, status, id))
|
||||
item, err := scanPaymentCard(r.client.QueryRow(ctx, query, active, id))
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return paymentcard.PaymentCardDTO{}, err
|
||||
}
|
||||
@@ -186,7 +188,7 @@ func scanPaymentCard(row scannable) (paymentcard.PaymentCardDTO, error) {
|
||||
var titleJSON, contentJSON []byte
|
||||
|
||||
if err := row.Scan(
|
||||
&item.Id, &item.Price, &titleJSON, &contentJSON, &item.Status,
|
||||
&item.Id, &item.Price, &titleJSON, &contentJSON, &item.Active,
|
||||
); err != nil {
|
||||
return paymentcard.PaymentCardDTO{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user