1
0
Fork 0

fix(training): postgres repo using name instead of title in queries and insert value count was mismatched

This commit is contained in:
Vojtěch Mareš 2024-10-11 10:19:03 +02:00
parent 6c776e5171
commit ec0ed1e61b
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D

View file

@ -26,7 +26,7 @@ func (r *PostgresRepository) Create(ctx context.Context, training *Training) err
queryErr := tx.QueryRow(ctx, `
INSERT INTO training.trainings (name, days, published)
VALUES ($1, $2, $3, $4, $5)
VALUES ($1, $2, $3)
RETURNING id
`, training.name, training.days, training.published).Scan(&training.id)
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 {
_, err := r.pg.Exec(ctx, `
UPDATE training.trainings
SET title = $2
SET name = $2
WHERE id = $1
`, training.ID, training.name)
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) {
var t Training
err := r.pg.QueryRow(ctx, `
SELECT id, title, published, retired
SELECT id, name, published, retired
FROM training.trainings
WHERE id = $1
`, 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) {
rows, err := r.pg.Query(ctx, `
SELECT id, title, published, retired
SELECT id, name, published, retired
FROM training.trainings
`)
if err != nil {