chore(api)!: added new fields to contract

This commit is contained in:
ITQ
2025-12-20 18:06:28 +03:00
parent 31738d3a0a
commit acfe7275eb
6 changed files with 60 additions and 19 deletions
@@ -17,11 +17,11 @@ func NewTaskRepository(db *sqlx.DB) *TaskRepository {
}
func (r *TaskRepository) CreateTask(ctx context.Context, t *task.Task) (*task.Task, error) {
query := `INSERT INTO tasks (competition_id, title, description, in_competition_position, max_points, max_attempts, type)
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id, created_at, updated_at`
query := `INSERT INTO tasks (competition_id, title, description, in_competition_position, max_points, max_attempts, type, answer_url)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, created_at, updated_at`
var createdTask task.Task
err := r.db.QueryRowxContext(ctx, query, t.CompetitionId, t.Title, t.Description, t.InCompetitionPosition, t.MaxPoints, t.MaxAttempts, t.Type).
err := r.db.QueryRowxContext(ctx, query, t.CompetitionId, t.Title, t.Description, t.InCompetitionPosition, t.MaxPoints, t.MaxAttempts, t.Type, t.AnswerUrl).
StructScan(&createdTask)
if err != nil {
return nil, err
@@ -33,6 +33,7 @@ func (r *TaskRepository) CreateTask(ctx context.Context, t *task.Task) (*task.Ta
createdTask.MaxPoints = t.MaxPoints
createdTask.MaxAttempts = t.MaxAttempts
createdTask.Type = t.Type
createdTask.AnswerUrl = t.AnswerUrl
return &createdTask, nil
}
@@ -43,11 +44,11 @@ func (r *TaskRepository) GetTask(ctx context.Context, id string) (*task.Task, er
}
func (r *TaskRepository) EditTask(ctx context.Context, t *task.Task) (*task.Task, error) {
query := `UPDATE tasks SET title = $1, description = $2, in_competition_position = $3, max_points = $4, max_attempts = $5, type = $6, updated_at = now()
WHERE id = $7 RETURNING updated_at`
query := `UPDATE tasks SET title = $1, description = $2, in_competition_position = $3, max_points = $4, max_attempts = $5, type = $6, answer_url = $7, updated_at = now()
WHERE id = $8 RETURNING updated_at`
var updatedTask task.Task
err := r.db.QueryRowxContext(ctx, query, t.Title, t.Description, t.InCompetitionPosition, t.MaxPoints, t.MaxAttempts, t.Type, t.Id).
err := r.db.QueryRowxContext(ctx, query, t.Title, t.Description, t.InCompetitionPosition, t.MaxPoints, t.MaxAttempts, t.Type, t.AnswerUrl, t.Id).
StructScan(&updatedTask)
if err != nil {
return nil, err