add task service
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "datarush/pkg/api/task"
|
||||
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
type TaskRepository interface {
|
||||
CreateTask(ctx context.Context, t *pb.Task) (*pb.Task, error)
|
||||
GetTask(ctx context.Context, id string) (*pb.Task, error)
|
||||
EditTask(ctx context.Context, t *pb.Task) (*pb.Task, error)
|
||||
DeleteTask(ctx context.Context, id string) error
|
||||
ListCompetitionTasks(ctx context.Context, competitionID string) ([]*pb.Task, error)
|
||||
GetTaskAttachments(ctx context.Context, taskID string, showPrivate bool) ([]*pb.TaskAttachment, error)
|
||||
}
|
||||
|
||||
type TaskService struct {
|
||||
repo TaskRepository
|
||||
}
|
||||
|
||||
func NewTaskService(repo TaskRepository) *TaskService {
|
||||
return &TaskService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *TaskService) CreateTask(ctx context.Context, req *pb.Task) (*pb.Task, error) {
|
||||
return s.repo.CreateTask(ctx, req)
|
||||
}
|
||||
|
||||
func (s *TaskService) GetTask(ctx context.Context, req *pb.GetTaskRequest) (*pb.Task, error) {
|
||||
return s.repo.GetTask(ctx, req.TaskId)
|
||||
}
|
||||
|
||||
func (s *TaskService) EditTask(ctx context.Context, req *pb.Task) (*pb.Task, error) {
|
||||
return s.repo.EditTask(ctx, req)
|
||||
}
|
||||
|
||||
func (s *TaskService) DeleteTask(ctx context.Context, req *pb.DeleteTaskRequest) (*emptypb.Empty, error) {
|
||||
err := s.repo.DeleteTask(ctx, req.TaskId)
|
||||
return &emptypb.Empty{}, err
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
return &pb.ListCompetitionTasksResponse{Tasks: tasks}, nil
|
||||
}
|
||||
|
||||
func (s *TaskService) GetTaskAttachments(ctx context.Context, req *pb.GetTaskAttachmentsRequest) (*pb.GetTaskAttachmentsResponse, error) {
|
||||
showPrivate := false
|
||||
if req.ShowPrivate != nil {
|
||||
showPrivate = *req.ShowPrivate
|
||||
}
|
||||
attachments, err := s.repo.GetTaskAttachments(ctx, req.TaskId, showPrivate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.GetTaskAttachmentsResponse{Attachments: attachments}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user