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
+6 -3
View File
@@ -68,6 +68,7 @@ type TaskRequest struct {
InCompetitionPosition int32 `json:"in_competition_position" validate:"required"`
MaxPoints int32 `json:"max_points,omitempty"`
MaxAttempts int32 `json:"max_attempts,omitempty"`
AnswerURL string `json:"answer_url,omitempty"`
Type string `json:"type" validate:"required,oneof=input checker review"`
}
@@ -79,6 +80,7 @@ type TaskResponse struct {
InCompetitionPosition int32 `json:"in_competition_position"`
MaxPoints int32 `json:"max_points,omitempty"`
MaxAttempts int32 `json:"max_attempts,omitempty"`
AnswerURL string `json:"answer_url,omitempty"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
@@ -89,9 +91,10 @@ type ListTasksResponse struct {
}
type TaskAttachmentResponse struct {
ID string `json:"id"`
FileURL string `json:"file_url"`
IsPublic bool `json:"is_public"`
ID string `json:"id"`
FileURL string `json:"file_url"`
Mountpoint string `json:"mountpoint,omitempty"`
IsPublic bool `json:"is_public"`
}
type SubmissionResponse struct {
+11
View File
@@ -49,12 +49,22 @@ func TaskProtoToHTTP(t *taskpb.Task) *domain.TaskResponse {
InCompetitionPosition: t.InCompetitionPosition,
MaxPoints: t.MaxPoints,
MaxAttempts: t.MaxAttempts,
AnswerURL: t.AnswerUrl,
Type: TaskTypeToString(t.Type),
CreatedAt: t.CreatedAt.AsTime(),
UpdatedAt: t.UpdatedAt.AsTime(),
}
}
func TaskAttachmentProtoToHTTP(a *taskpb.TaskAttachment) *domain.TaskAttachmentResponse {
return &domain.TaskAttachmentResponse{
ID: a.Id,
FileURL: a.FileUrl,
Mountpoint: a.Mountpoint,
IsPublic: a.IsPublic,
}
}
func SubmissionProtoToHTTP(s *subpb.Submission) *domain.SubmissionResponse {
return &domain.SubmissionResponse{
ID: s.Id,
@@ -150,6 +160,7 @@ func TaskHTTPToProto(req *domain.TaskRequest) *taskpb.Task {
InCompetitionPosition: req.InCompetitionPosition,
MaxPoints: req.MaxPoints,
MaxAttempts: req.MaxAttempts,
AnswerUrl: req.AnswerURL,
Type: StringToTaskType(req.Type),
}
}
@@ -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)