feat: merge auth&tester

This commit is contained in:
Vyacheslav1557 2025-04-22 20:44:52 +05:00
parent 0a2dea6c23
commit 441af4c6a2
72 changed files with 4910 additions and 2378 deletions

View file

@ -0,0 +1,39 @@
package usecase
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/contests"
"git.sch9.ru/new_gate/ms-tester/internal/models"
)
type ContestUseCase struct {
contestRepo contests.Repository
}
func NewContestUseCase(
contestRepo contests.Repository,
) *ContestUseCase {
return &ContestUseCase{
contestRepo: contestRepo,
}
}
func (uc *ContestUseCase) CreateContest(ctx context.Context, title string) (int32, error) {
return uc.contestRepo.CreateContest(ctx, title)
}
func (uc *ContestUseCase) GetContest(ctx context.Context, id int32) (*models.Contest, error) {
return uc.contestRepo.GetContest(ctx, id)
}
func (uc *ContestUseCase) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error {
return uc.contestRepo.UpdateContest(ctx, id, contestUpdate)
}
func (uc *ContestUseCase) DeleteContest(ctx context.Context, id int32) error {
return uc.contestRepo.DeleteContest(ctx, id)
}
func (uc *ContestUseCase) ListContests(ctx context.Context, filter models.ContestsFilter) (*models.ContestsList, error) {
return uc.contestRepo.ListContests(ctx, filter)
}

View file

@ -0,0 +1,10 @@
package usecase
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/models"
)
func (uc *ContestUseCase) GetMonitor(ctx context.Context, contestId int32) (*models.Monitor, error) {
return uc.contestRepo.GetMonitor(ctx, contestId, 20)
}

View file

@ -0,0 +1,34 @@
package usecase
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/models"
)
func (uc *ContestUseCase) GetParticipantId(ctx context.Context, contestId int32, userId int32) (int32, error) {
return uc.contestRepo.GetParticipantId(ctx, contestId, userId)
}
func (uc *ContestUseCase) GetParticipantId2(ctx context.Context, taskId, userId int32) (int32, error) {
return uc.contestRepo.GetParticipantId2(ctx, taskId, userId)
}
func (uc *ContestUseCase) GetParticipantId3(ctx context.Context, solutionId int32) (int32, error) {
return uc.contestRepo.GetParticipantId3(ctx, solutionId)
}
func (uc *ContestUseCase) CreateParticipant(ctx context.Context, contestId int32, userId int32) (id int32, err error) {
return uc.contestRepo.CreateParticipant(ctx, contestId, userId)
}
func (uc *ContestUseCase) DeleteParticipant(ctx context.Context, participantId int32) error {
return uc.contestRepo.DeleteParticipant(ctx, participantId)
}
func (uc *ContestUseCase) ListParticipants(ctx context.Context, filter models.ParticipantsFilter) (*models.ParticipantsList, error) {
return uc.contestRepo.ListParticipants(ctx, filter)
}
func (uc *ContestUseCase) UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error {
return uc.contestRepo.UpdateParticipant(ctx, id, participantUpdate)
}

View file

@ -0,0 +1,29 @@
package usecase
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/models"
)
func (uc *ContestUseCase) GetSolution(ctx context.Context, id int32) (*models.Solution, error) {
return uc.contestRepo.GetSolution(ctx, id)
}
func (uc *ContestUseCase) CreateSolution(ctx context.Context, creation *models.SolutionCreation) (int32, error) {
participantId, err := uc.contestRepo.GetParticipantId2(ctx, creation.TaskId, creation.UserId)
if err != nil {
return 0, err
}
creation.ParticipantId = participantId
return uc.contestRepo.CreateSolution(ctx, creation)
}
func (uc *ContestUseCase) ListSolutions(ctx context.Context, filter models.SolutionsFilter) (*models.SolutionsList, error) {
return uc.contestRepo.ListSolutions(ctx, filter)
}
func (uc *ContestUseCase) GetBestSolutions(ctx context.Context, contestId int32, participantId int32) ([]*models.SolutionsListItem, error) {
return uc.contestRepo.GetBestSolutions(ctx, contestId, participantId)
}

View file

@ -0,0 +1,22 @@
package usecase
import (
"context"
"git.sch9.ru/new_gate/ms-tester/internal/models"
)
func (uc *ContestUseCase) CreateTask(ctx context.Context, contestId int32, taskId int32) (id int32, err error) {
return uc.contestRepo.CreateTask(ctx, contestId, taskId)
}
func (uc *ContestUseCase) GetTask(ctx context.Context, id int32) (*models.Task, error) {
return uc.contestRepo.GetTask(ctx, id)
}
func (uc *ContestUseCase) GetTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) {
return uc.contestRepo.GetTasks(ctx, contestId)
}
func (uc *ContestUseCase) DeleteTask(ctx context.Context, taskId int32) error {
return uc.contestRepo.DeleteTask(ctx, taskId)
}