fix(training): postgres repo using name instead of title in queries and insert value count was mismatched
This commit is contained in:
parent
6c776e5171
commit
ec0ed1e61b
1 changed files with 4 additions and 4 deletions
|
|
@ -26,7 +26,7 @@ func (r *PostgresRepository) Create(ctx context.Context, training *Training) err
|
||||||
|
|
||||||
queryErr := tx.QueryRow(ctx, `
|
queryErr := tx.QueryRow(ctx, `
|
||||||
INSERT INTO training.trainings (name, days, published)
|
INSERT INTO training.trainings (name, days, published)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`, training.name, training.days, training.published).Scan(&training.id)
|
`, training.name, training.days, training.published).Scan(&training.id)
|
||||||
if queryErr != nil {
|
if queryErr != nil {
|
||||||
|
|
@ -41,7 +41,7 @@ func (r *PostgresRepository) Create(ctx context.Context, training *Training) err
|
||||||
func (r *PostgresRepository) Update(ctx context.Context, training *Training) error {
|
func (r *PostgresRepository) Update(ctx context.Context, training *Training) error {
|
||||||
_, err := r.pg.Exec(ctx, `
|
_, err := r.pg.Exec(ctx, `
|
||||||
UPDATE training.trainings
|
UPDATE training.trainings
|
||||||
SET title = $2
|
SET name = $2
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`, training.ID, training.name)
|
`, training.ID, training.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -54,7 +54,7 @@ func (r *PostgresRepository) Update(ctx context.Context, training *Training) err
|
||||||
func (r *PostgresRepository) FindByID(ctx context.Context, id ID) (*Training, error) {
|
func (r *PostgresRepository) FindByID(ctx context.Context, id ID) (*Training, error) {
|
||||||
var t Training
|
var t Training
|
||||||
err := r.pg.QueryRow(ctx, `
|
err := r.pg.QueryRow(ctx, `
|
||||||
SELECT id, title, published, retired
|
SELECT id, name, published, retired
|
||||||
FROM training.trainings
|
FROM training.trainings
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`, id).Scan(&t.id, &t.name, &t.published, &t.retired)
|
`, id).Scan(&t.id, &t.name, &t.published, &t.retired)
|
||||||
|
|
@ -67,7 +67,7 @@ func (r *PostgresRepository) FindByID(ctx context.Context, id ID) (*Training, er
|
||||||
|
|
||||||
func (r *PostgresRepository) FindAll(ctx context.Context) ([]Training, error) {
|
func (r *PostgresRepository) FindAll(ctx context.Context) ([]Training, error) {
|
||||||
rows, err := r.pg.Query(ctx, `
|
rows, err := r.pg.Query(ctx, `
|
||||||
SELECT id, title, published, retired
|
SELECT id, name, published, retired
|
||||||
FROM training.trainings
|
FROM training.trainings
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Reference in a new issue