style: reformatted all files
This commit is contained in:
@@ -3,8 +3,9 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "datarush/pkg/api/task"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
|
||||
pb "datarush/pkg/api/task"
|
||||
)
|
||||
|
||||
type TaskService interface {
|
||||
@@ -12,7 +13,10 @@ type TaskService interface {
|
||||
GetTask(ctx context.Context, req *pb.GetTaskRequest) (*pb.Task, error)
|
||||
EditTask(ctx context.Context, req *pb.Task) (*pb.Task, error)
|
||||
DeleteTask(ctx context.Context, req *pb.DeleteTaskRequest) (*emptypb.Empty, error)
|
||||
ListCompetitionTasks(ctx context.Context, req *pb.ListCompetitionTasksRequest) (*pb.ListCompetitionTasksResponse, error)
|
||||
ListCompetitionTasks(
|
||||
ctx context.Context,
|
||||
req *pb.ListCompetitionTasksRequest,
|
||||
) (*pb.ListCompetitionTasksResponse, error)
|
||||
GetTaskAttachments(ctx context.Context, req *pb.GetTaskAttachmentsRequest) (*pb.GetTaskAttachmentsResponse, error)
|
||||
}
|
||||
|
||||
@@ -41,10 +45,16 @@ func (h *TaskHandler) DeleteTask(ctx context.Context, req *pb.DeleteTaskRequest)
|
||||
return h.service.DeleteTask(ctx, req)
|
||||
}
|
||||
|
||||
func (h *TaskHandler) ListCompetitionTasks(ctx context.Context, req *pb.ListCompetitionTasksRequest) (*pb.ListCompetitionTasksResponse, error) {
|
||||
func (h *TaskHandler) ListCompetitionTasks(
|
||||
ctx context.Context,
|
||||
req *pb.ListCompetitionTasksRequest,
|
||||
) (*pb.ListCompetitionTasksResponse, error) {
|
||||
return h.service.ListCompetitionTasks(ctx, req)
|
||||
}
|
||||
|
||||
func (h *TaskHandler) GetTaskAttachments(ctx context.Context, req *pb.GetTaskAttachmentsRequest) (*pb.GetTaskAttachmentsResponse, error) {
|
||||
func (h *TaskHandler) GetTaskAttachments(
|
||||
ctx context.Context,
|
||||
req *pb.GetTaskAttachmentsRequest,
|
||||
) (*pb.GetTaskAttachmentsResponse, error) {
|
||||
return h.service.GetTaskAttachments(ctx, req)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ func (r *TaskRepository) CreateTask(ctx context.Context, t *task.Task) (*task.Ta
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7) 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).StructScan(&createdTask)
|
||||
err := r.db.QueryRowxContext(ctx, query, t.CompetitionId, t.Title, t.Description, t.InCompetitionPosition, t.MaxPoints, t.MaxAttempts, t.Type).
|
||||
StructScan(&createdTask)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -46,7 +47,8 @@ func (r *TaskRepository) EditTask(ctx context.Context, t *task.Task) (*task.Task
|
||||
WHERE id = $7 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).StructScan(&updatedTask)
|
||||
err := r.db.QueryRowxContext(ctx, query, t.Title, t.Description, t.InCompetitionPosition, t.MaxPoints, t.MaxAttempts, t.Type, t.Id).
|
||||
StructScan(&updatedTask)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -65,7 +67,11 @@ func (r *TaskRepository) ListCompetitionTasks(ctx context.Context, competitionID
|
||||
return tasks, err
|
||||
}
|
||||
|
||||
func (r *TaskRepository) GetTaskAttachments(ctx context.Context, taskID string, showPrivate bool) ([]*task.TaskAttachment, error) {
|
||||
func (r *TaskRepository) GetTaskAttachments(
|
||||
ctx context.Context,
|
||||
taskID string,
|
||||
showPrivate bool,
|
||||
) ([]*task.TaskAttachment, error) {
|
||||
var attachments []*task.TaskAttachment
|
||||
query := "SELECT * FROM task_attachments WHERE task_id = $1"
|
||||
args := []interface{}{taskID}
|
||||
@@ -76,4 +82,4 @@ func (r *TaskRepository) GetTaskAttachments(ctx context.Context, taskID string,
|
||||
|
||||
err := r.db.SelectContext(ctx, &attachments, query, args...)
|
||||
return attachments, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "datarush/pkg/api/task"
|
||||
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
@@ -41,7 +42,10 @@ func (s *TaskService) DeleteTask(ctx context.Context, req *pb.DeleteTaskRequest)
|
||||
return &emptypb.Empty{}, err
|
||||
}
|
||||
|
||||
func (s *TaskService) ListCompetitionTasks(ctx context.Context, req *pb.ListCompetitionTasksRequest) (*pb.ListCompetitionTasksResponse, error) {
|
||||
func (s *TaskService) ListCompetitionTasks(
|
||||
ctx context.Context,
|
||||
req *pb.ListCompetitionTasksRequest,
|
||||
) (*pb.ListCompetitionTasksResponse, error) {
|
||||
tasks, err := s.repo.ListCompetitionTasks(ctx, req.CompetitionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -49,7 +53,10 @@ func (s *TaskService) ListCompetitionTasks(ctx context.Context, req *pb.ListComp
|
||||
return &pb.ListCompetitionTasksResponse{Tasks: tasks}, nil
|
||||
}
|
||||
|
||||
func (s *TaskService) GetTaskAttachments(ctx context.Context, req *pb.GetTaskAttachmentsRequest) (*pb.GetTaskAttachmentsResponse, error) {
|
||||
func (s *TaskService) GetTaskAttachments(
|
||||
ctx context.Context,
|
||||
req *pb.GetTaskAttachmentsRequest,
|
||||
) (*pb.GetTaskAttachmentsResponse, error) {
|
||||
showPrivate := false
|
||||
if req.ShowPrivate != nil {
|
||||
showPrivate = *req.ShowPrivate
|
||||
@@ -59,4 +66,4 @@ func (s *TaskService) GetTaskAttachments(ctx context.Context, req *pb.GetTaskAtt
|
||||
return nil, err
|
||||
}
|
||||
return &pb.GetTaskAttachmentsResponse{Attachments: attachments}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"datarush/internal/task/service/mocks"
|
||||
pb "datarush/pkg/api/task"
|
||||
|
||||
"go.uber.org/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
@@ -24,13 +24,13 @@ func TestTaskService(t *testing.T) {
|
||||
|
||||
t.Run("CreateTask", func(t *testing.T) {
|
||||
task := &pb.Task{
|
||||
CompetitionId: "comp1",
|
||||
Title: "Test Task",
|
||||
Description: "This is a test task",
|
||||
CompetitionId: "comp1",
|
||||
Title: "Test Task",
|
||||
Description: "This is a test task",
|
||||
InCompetitionPosition: 1,
|
||||
MaxPoints: 100,
|
||||
MaxAttempts: 10,
|
||||
Type: pb.TaskType_TASK_TYPE_INPUT,
|
||||
MaxPoints: 100,
|
||||
MaxAttempts: 10,
|
||||
Type: pb.TaskType_TASK_TYPE_INPUT,
|
||||
}
|
||||
|
||||
mockRepo.EXPECT().CreateTask(ctx, task).Return(task, nil)
|
||||
@@ -44,16 +44,16 @@ func TestTaskService(t *testing.T) {
|
||||
taskID := "task1"
|
||||
req := &pb.GetTaskRequest{TaskId: taskID}
|
||||
expectedTask := &pb.Task{
|
||||
Id: taskID,
|
||||
CompetitionId: "comp1",
|
||||
Title: "Test Task",
|
||||
Description: "This is a test task",
|
||||
Id: taskID,
|
||||
CompetitionId: "comp1",
|
||||
Title: "Test Task",
|
||||
Description: "This is a test task",
|
||||
InCompetitionPosition: 1,
|
||||
MaxPoints: 100,
|
||||
MaxAttempts: 10,
|
||||
Type: pb.TaskType_TASK_TYPE_INPUT,
|
||||
CreatedAt: timestamppb.Now(),
|
||||
UpdatedAt: timestamppb.Now(),
|
||||
MaxPoints: 100,
|
||||
MaxAttempts: 10,
|
||||
Type: pb.TaskType_TASK_TYPE_INPUT,
|
||||
CreatedAt: timestamppb.Now(),
|
||||
UpdatedAt: timestamppb.Now(),
|
||||
}
|
||||
|
||||
mockRepo.EXPECT().GetTask(ctx, taskID).Return(expectedTask, nil)
|
||||
@@ -65,14 +65,14 @@ func TestTaskService(t *testing.T) {
|
||||
|
||||
t.Run("EditTask", func(t *testing.T) {
|
||||
task := &pb.Task{
|
||||
Id: "task1",
|
||||
CompetitionId: "comp1",
|
||||
Title: "Updated Test Task",
|
||||
Description: "This is an updated test task",
|
||||
Id: "task1",
|
||||
CompetitionId: "comp1",
|
||||
Title: "Updated Test Task",
|
||||
Description: "This is an updated test task",
|
||||
InCompetitionPosition: 1,
|
||||
MaxPoints: 150,
|
||||
MaxAttempts: 5,
|
||||
Type: pb.TaskType_TASK_TYPE_CHECKER,
|
||||
MaxPoints: 150,
|
||||
MaxAttempts: 5,
|
||||
Type: pb.TaskType_TASK_TYPE_CHECKER,
|
||||
}
|
||||
|
||||
mockRepo.EXPECT().EditTask(ctx, task).Return(task, nil)
|
||||
@@ -137,4 +137,4 @@ func TestTaskService(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedAttachments, resp.Attachments)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user