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
+6 -3
View File
@@ -30,6 +30,7 @@ func TestTaskService(t *testing.T) {
InCompetitionPosition: 1,
MaxPoints: 100,
MaxAttempts: 10,
AnswerUrl: "https://example.com/answer",
Type: pb.TaskType_TASK_TYPE_INPUT,
}
@@ -51,6 +52,7 @@ func TestTaskService(t *testing.T) {
InCompetitionPosition: 1,
MaxPoints: 100,
MaxAttempts: 10,
AnswerUrl: "https://example.com/answer",
Type: pb.TaskType_TASK_TYPE_INPUT,
CreatedAt: timestamppb.Now(),
UpdatedAt: timestamppb.Now(),
@@ -72,6 +74,7 @@ func TestTaskService(t *testing.T) {
InCompetitionPosition: 1,
MaxPoints: 150,
MaxAttempts: 5,
AnswerUrl: "https://example.com/answer-updated",
Type: pb.TaskType_TASK_TYPE_CHECKER,
}
@@ -112,8 +115,8 @@ func TestTaskService(t *testing.T) {
showPrivate := true
req := &pb.GetTaskAttachmentsRequest{TaskId: taskID, ShowPrivate: &showPrivate}
expectedAttachments := []*pb.TaskAttachment{
{Id: "att1", FileUrl: "url1", IsPublic: true},
{Id: "att2", FileUrl: "url2", IsPublic: false},
{Id: "att1", FileUrl: "url1", Mountpoint: "mp1", IsPublic: true},
{Id: "att2", FileUrl: "url2", Mountpoint: "mp2", IsPublic: false},
}
mockRepo.EXPECT().GetTaskAttachments(ctx, taskID, showPrivate).Return(expectedAttachments, nil)
@@ -128,7 +131,7 @@ func TestTaskService(t *testing.T) {
showPrivate := false
req := &pb.GetTaskAttachmentsRequest{TaskId: taskID, ShowPrivate: &showPrivate}
expectedAttachments := []*pb.TaskAttachment{
{Id: "att1", FileUrl: "url1", IsPublic: true},
{Id: "att1", FileUrl: "url1", Mountpoint: "mp1", IsPublic: true},
}
mockRepo.EXPECT().GetTaskAttachments(ctx, taskID, showPrivate).Return(expectedAttachments, nil)