From 5536c086e09224ac23dcb328d1f4ccba9156bda7 Mon Sep 17 00:00:00 2001 From: Vyacheslav1557 Date: Sat, 29 Mar 2025 00:36:23 +0500 Subject: [PATCH] refactor(tester): refactor api --- internal/models/contest.go | 14 + internal/models/pagination.go | 6 + internal/models/participant.go | 16 + internal/models/problem.go | 16 +- internal/models/solution.go | 9 + internal/tester/delivery/rest/handlers.go | 399 ++++++++---------- internal/tester/pg_repository.go | 10 +- .../repository/pg_problems_repository.go | 4 +- internal/tester/usecase.go | 10 +- internal/tester/usecase/problems_usecase.go | 2 +- proto | 2 +- 11 files changed, 257 insertions(+), 231 deletions(-) create mode 100644 internal/models/pagination.go diff --git a/internal/models/contest.go b/internal/models/contest.go index d665977..3646d1b 100644 --- a/internal/models/contest.go +++ b/internal/models/contest.go @@ -16,6 +16,20 @@ type ContestsListItem struct { UpdatedAt time.Time `db:"updated_at"` } +type ContestsList struct { + Contests []*ContestsListItem + Pagination Pagination +} + +type ContestsFilter struct { + Page int32 + PageSize int32 +} + +func (f ContestsFilter) Offset() int32 { + return (f.Page - 1) * f.PageSize +} + type ContestUpdate struct { Title *string `json:"title"` } diff --git a/internal/models/pagination.go b/internal/models/pagination.go new file mode 100644 index 0000000..c2fd852 --- /dev/null +++ b/internal/models/pagination.go @@ -0,0 +1,6 @@ +package models + +type Pagination struct { + Page int32 `json:"page"` + Total int32 `json:"total"` +} diff --git a/internal/models/participant.go b/internal/models/participant.go index 9960ba7..f277a3d 100644 --- a/internal/models/participant.go +++ b/internal/models/participant.go @@ -20,6 +20,22 @@ type ParticipantsListItem struct { UpdatedAt time.Time `db:"updated_at"` } +type ParticipantsList struct { + Participants []*ParticipantsListItem + Pagination Pagination +} + +type ParticipantsFilter struct { + Page int32 + PageSize int32 + + ContestId int32 +} + +func (f ParticipantsFilter) Offset() int32 { + return (f.Page - 1) * f.PageSize +} + type ParticipantUpdate struct { Name *string `json:"name"` } diff --git a/internal/models/problem.go b/internal/models/problem.go index 92c1d01..930aa58 100644 --- a/internal/models/problem.go +++ b/internal/models/problem.go @@ -25,7 +25,7 @@ type Problem struct { UpdatedAt time.Time `db:"updated_at"` } -type ProblemListItem struct { +type ProblemsListItem struct { Id int32 `db:"id"` Title string `db:"title"` MemoryLimit int32 `db:"memory_limit"` @@ -34,6 +34,20 @@ type ProblemListItem struct { UpdatedAt time.Time `db:"updated_at"` } +type ProblemsList struct { + Problems []*ProblemsListItem `json:"problems"` + Pagination Pagination `json:"pagination"` +} + +type ProblemsFilter struct { + Page int32 + PageSize int32 +} + +func (f ProblemsFilter) Offset() int32 { + return (f.Page - 1) * f.PageSize +} + type ProblemUpdate struct { Title *string `db:"title"` MemoryLimit *int32 `db:"memory_limit"` diff --git a/internal/models/solution.go b/internal/models/solution.go index b20dcd1..c2a6735 100644 --- a/internal/models/solution.go +++ b/internal/models/solution.go @@ -38,6 +38,11 @@ type SolutionsListItem struct { CreatedAt time.Time `db:"created_at"` } +type SolutionsList struct { + Solutions []*SolutionsListItem + Pagination Pagination +} + type SolutionsFilter struct { Page int32 PageSize int32 @@ -49,6 +54,10 @@ type SolutionsFilter struct { Order *int32 } +func (f SolutionsFilter) Offset() int32 { + return (f.Page - 1) * f.PageSize +} + //type Result int32 // //const ( diff --git a/internal/tester/delivery/rest/handlers.go b/internal/tester/delivery/rest/handlers.go index 438192b..62724e2 100644 --- a/internal/tester/delivery/rest/handlers.go +++ b/internal/tester/delivery/rest/handlers.go @@ -22,60 +22,42 @@ func NewTesterHandlers(problemsUC tester.ProblemUseCase, contestsUC tester.Conte } func (h *TesterHandlers) ListContests(c *fiber.Ctx, params testerv1.ListContestsParams) error { - contests, count, err := h.contestsUC.ListContests(c.Context(), params.Page, params.PageSize) + contestsList, err := h.contestsUC.ListContests(c.Context(), models.ContestsFilter{ + Page: params.Page, + PageSize: params.PageSize, + }) if err != nil { return c.SendStatus(pkg.ToREST(err)) } resp := testerv1.ListContestsResponse{ - Contests: make([]testerv1.ContestsListItem, len(contests)), - Page: params.Page, - MaxPage: func() int32 { - if count%params.PageSize == 0 { - return count / params.PageSize - } - return count/params.PageSize + 1 - }(), + Contests: make([]testerv1.ContestsListItem, len(contestsList.Contests)), + Pagination: P2P(contestsList.Pagination), } - for i, contest := range contests { - resp.Contests[i] = testerv1.ContestsListItem{ - Id: contest.Id, - Title: contest.Title, - CreatedAt: contest.CreatedAt, - UpdatedAt: contest.UpdatedAt, - } + for i, contest := range contestsList.Contests { + resp.Contests[i] = CLI2CLI(*contest) } return c.JSON(resp) } func (h *TesterHandlers) ListProblems(c *fiber.Ctx, params testerv1.ListProblemsParams) error { - problems, count, err := h.problemsUC.ListProblems(c.Context(), params.Page, params.PageSize) + problemsList, err := h.problemsUC.ListProblems(c.Context(), models.ProblemsFilter{ + Page: params.Page, + PageSize: params.PageSize, + }) if err != nil { return c.SendStatus(pkg.ToREST(err)) } resp := testerv1.ListProblemsResponse{ - Problems: make([]testerv1.ProblemListItem, len(problems)), - Page: params.Page, - MaxPage: func() int32 { - if count%params.PageSize == 0 { - return count / params.PageSize - } - return count/params.PageSize + 1 - }(), + Problems: make([]testerv1.ProblemsListItem, len(problemsList.Problems)), + Pagination: P2P(problemsList.Pagination), } - for i, problem := range problems { - resp.Problems[i] = testerv1.ProblemListItem{ - Id: problem.Id, - Title: problem.Title, - MemoryLimit: problem.MemoryLimit, - TimeLimit: problem.TimeLimit, - CreatedAt: problem.CreatedAt, - UpdatedAt: problem.UpdatedAt, - } + for i, problem := range problemsList.Problems { + resp.Problems[i] = PLI2PLI(*problem) } return c.JSON(resp) @@ -112,18 +94,13 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error { // return c.SendStatus(fiber.StatusUnauthorized) //} - tasks, err := h.contestsUC.ReadRichTasks(c.Context(), id) + tasks, err := h.contestsUC.ReadTasks(c.Context(), id) if err != nil { return c.SendStatus(pkg.ToREST(err)) } resp := testerv1.GetContestResponse{ - Contest: testerv1.Contest{ - Id: id, - Title: contest.Title, - CreatedAt: contest.CreatedAt, - UpdatedAt: contest.UpdatedAt, - }, + Contest: C2C(*contest), Tasks: make([]struct { Solution testerv1.Solution `json:"solution"` Task testerv1.TasksListItem `json:"task"` @@ -136,16 +113,7 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error { Task testerv1.TasksListItem `json:"task"` }{ Solution: testerv1.Solution{}, - Task: testerv1.TasksListItem{ - Id: task.Id, - ProblemId: task.ProblemId, - Position: task.Position, - Title: task.Title, - MemoryLimit: task.MemoryLimit, - TimeLimit: task.TimeLimit, - CreatedAt: task.CreatedAt, - UpdatedAt: task.UpdatedAt, - }, + Task: TLI2TLI(*task), } } @@ -220,55 +188,27 @@ func (h *TesterHandlers) GetProblem(c *fiber.Ctx, id int32) error { } return c.JSON( - testerv1.GetProblemResponse{Problem: testerv1.Problem{ - Id: problem.Id, - Title: problem.Title, - TimeLimit: problem.TimeLimit, - MemoryLimit: problem.MemoryLimit, - - Legend: problem.Legend, - InputFormat: problem.InputFormat, - OutputFormat: problem.OutputFormat, - Notes: problem.Notes, - Scoring: problem.Scoring, - - LegendHtml: problem.LegendHtml, - InputFormatHtml: problem.InputFormatHtml, - OutputFormatHtml: problem.OutputFormatHtml, - NotesHtml: problem.NotesHtml, - ScoringHtml: problem.ScoringHtml, - - CreatedAt: problem.CreatedAt, - UpdatedAt: problem.UpdatedAt, - }}, + testerv1.GetProblemResponse{Problem: *PR2PR(problem)}, ) } func (h *TesterHandlers) ListParticipants(c *fiber.Ctx, params testerv1.ListParticipantsParams) error { - participants, count, err := h.contestsUC.ListParticipants(c.Context(), params.ContestId, params.Page, params.PageSize) + participantsList, err := h.contestsUC.ListParticipants(c.Context(), models.ParticipantsFilter{ + Page: params.Page, + PageSize: params.PageSize, + ContestId: params.ContestId, + }) if err != nil { return c.SendStatus(pkg.ToREST(err)) } resp := testerv1.ListParticipantsResponse{ - Participants: make([]testerv1.ParticipantsListItem, len(participants)), - Page: params.Page, - MaxPage: func() int32 { - if count%params.PageSize == 0 { - return count / params.PageSize - } - return count/params.PageSize + 1 - }(), + Participants: make([]testerv1.ParticipantsListItem, len(participantsList.Participants)), + Pagination: P2P(participantsList.Pagination), } - for i, participant := range participants { - resp.Participants[i] = testerv1.ParticipantsListItem{ - Id: participant.Id, - UserId: participant.UserId, - Name: participant.Name, - CreatedAt: participant.CreatedAt, - UpdatedAt: participant.UpdatedAt, - } + for i, participant := range participantsList.Participants { + resp.Participants[i] = PTLI2PTLI(*participant) } return c.JSON(resp) @@ -335,7 +275,7 @@ func (h *TesterHandlers) UpdateParticipant(c *fiber.Ctx, params testerv1.UpdateP } func (h *TesterHandlers) ListSolutions(c *fiber.Ctx, params testerv1.ListSolutionsParams) error { - list, total, err := h.contestsUC.ListSolutions(c.Context(), models.SolutionsFilter{ + solutionsList, err := h.contestsUC.ListSolutions(c.Context(), models.SolutionsFilter{ ContestId: params.ContestId, Page: params.Page, PageSize: params.PageSize, @@ -350,30 +290,12 @@ func (h *TesterHandlers) ListSolutions(c *fiber.Ctx, params testerv1.ListSolutio } resp := testerv1.ListSolutionsResponse{ - Solutions: make([]testerv1.SolutionsListItem, len(list)), - Page: params.Page, - MaxPage: func() int32 { - if total%params.PageSize == 0 { - return total / params.PageSize - } - return total/params.PageSize + 1 - }(), + Solutions: make([]testerv1.SolutionsListItem, len(solutionsList.Solutions)), + Pagination: P2P(solutionsList.Pagination), } - for i, solution := range list { - resp.Solutions[i] = testerv1.SolutionsListItem{ - Id: solution.Id, - TaskId: solution.TaskId, - ContestId: solution.ContestId, - ParticipantId: solution.ParticipantId, - Language: solution.Language, - Penalty: solution.Penalty, - Score: solution.Score, - State: solution.State, - TotalScore: solution.TotalScore, - CreatedAt: solution.CreatedAt, - UpdatedAt: solution.UpdatedAt, - } + for i, solution := range solutionsList.Solutions { + resp.Solutions[i] = SLI2SLI(*solution) } return c.JSON(resp) @@ -427,19 +349,7 @@ func (h *TesterHandlers) GetSolution(c *fiber.Ctx, id int32) error { } return c.JSON( - testerv1.GetSolutionResponse{Solution: testerv1.Solution{ - Id: solution.Id, - TaskId: solution.TaskId, - ParticipantId: solution.ParticipantId, - Solution: solution.Solution, - State: solution.State, - Score: solution.Score, - Penalty: solution.Penalty, - TotalScore: solution.TotalScore, - Language: solution.Language, - CreatedAt: solution.CreatedAt, - UpdatedAt: solution.UpdatedAt, - }}, + testerv1.GetSolutionResponse{Solution: S2S(*solution)}, ) } @@ -449,7 +359,7 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error { return c.SendStatus(pkg.ToREST(err)) } - tasks, err := h.contestsUC.ReadRichTasks(c.Context(), id) + tasks, err := h.contestsUC.ReadTasks(c.Context(), id) if err != nil { return c.SendStatus(pkg.ToREST(err)) } @@ -460,43 +370,13 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error { } resp := testerv1.GetTaskResponse{ - Contest: struct { - Id int32 `json:"id"` - Tasks []testerv1.TasksListItem `json:"tasks"` - Title string `json:"title"` - }{ - Id: contest.Id, - Title: contest.Title, - Tasks: make([]testerv1.TasksListItem, len(tasks)), - }, - Task: testerv1.Task{ - Id: t.Id, - Title: t.Title, - MemoryLimit: t.MemoryLimit, - TimeLimit: t.TimeLimit, - - InputFormatHtml: t.InputFormatHtml, - LegendHtml: t.LegendHtml, - NotesHtml: t.NotesHtml, - OutputFormatHtml: t.OutputFormatHtml, - Position: t.Position, - ScoringHtml: t.ScoringHtml, - - CreatedAt: t.CreatedAt, - UpdatedAt: t.UpdatedAt, - }, + Contest: C2C(*contest), + Tasks: make([]testerv1.TasksListItem, len(tasks)), + Task: *T2T(t), } for i, task := range tasks { - resp.Contest.Tasks[i] = testerv1.TasksListItem{ - Id: task.Id, - Position: task.Position, - Title: task.Title, - MemoryLimit: task.MemoryLimit, - ProblemId: task.ProblemId, - TimeLimit: task.TimeLimit, - CreatedAt: task.CreatedAt, - UpdatedAt: task.UpdatedAt} + resp.Tasks[i] = TLI2TLI(*task) } return c.JSON(resp) @@ -513,43 +393,20 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara return c.SendStatus(pkg.ToREST(err)) } - tasks, err := h.contestsUC.ReadRichTasks(c.Context(), params.ContestId) + tasks, err := h.contestsUC.ReadTasks(c.Context(), params.ContestId) if err != nil { return c.SendStatus(pkg.ToREST(err)) } resp := testerv1.GetMonitorResponse{ - Contest: struct { - Id int32 `json:"id"` - Tasks []testerv1.TasksListItem `json:"tasks"` - Title string `json:"title"` - }{ - Id: contest.Id, - Title: contest.Title, - Tasks: make([]testerv1.TasksListItem, len(tasks)), - }, - Participants: make([]struct { - Id int32 `json:"id"` - Name string `json:"name"` - PenaltyInTotal int32 `json:"penalty_in_total"` - Solutions []testerv1.SolutionsListItem `json:"solutions"` - SolvedInTotal int32 `json:"solved_in_total"` - }, len(monitor.Participants)), - SummaryPerProblem: make([]struct { - Id int32 `json:"id"` - Success int32 `json:"success"` - Total int32 `json:"total"` - }, len(monitor.Summary)), + Contest: C2C(*contest), + Tasks: make([]testerv1.TasksListItem, len(tasks)), + Participants: make([]testerv1.ParticipantsStat, len(monitor.Participants)), + SummaryPerProblem: make([]testerv1.ProblemStatSummary, len(monitor.Summary)), } for i, participant := range monitor.Participants { - resp.Participants[i] = struct { - Id int32 `json:"id"` - Name string `json:"name"` - PenaltyInTotal int32 `json:"penalty_in_total"` - Solutions []testerv1.SolutionsListItem `json:"solutions"` - SolvedInTotal int32 `json:"solved_in_total"` - }{ + resp.Participants[i] = testerv1.ParticipantsStat{ Id: participant.Id, Name: participant.Name, PenaltyInTotal: participant.PenaltyInTotal, @@ -558,28 +415,12 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara } for j, solution := range participant.Solutions { - resp.Participants[i].Solutions[j] = testerv1.SolutionsListItem{ - ContestId: solution.ContestId, - CreatedAt: solution.CreatedAt, - Id: solution.Id, - Language: solution.Language, - ParticipantId: solution.ParticipantId, - Penalty: solution.Penalty, - Score: solution.Score, - State: solution.State, - TaskId: solution.TaskId, - TotalScore: solution.TotalScore, - UpdatedAt: solution.UpdatedAt, - } + resp.Participants[i].Solutions[j] = SLI2SLI(*solution) } } for i, problem := range monitor.Summary { - resp.SummaryPerProblem[i] = struct { - Id int32 `json:"id"` - Success int32 `json:"success"` - Total int32 `json:"total"` - }{ + resp.SummaryPerProblem[i] = testerv1.ProblemStatSummary{ Id: problem.Id, Success: problem.Success, Total: problem.Total, @@ -587,16 +428,142 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara } for i, task := range tasks { - resp.Contest.Tasks[i] = testerv1.TasksListItem{ - Id: task.Id, - Position: task.Position, - Title: task.Title, - MemoryLimit: task.MemoryLimit, - ProblemId: task.ProblemId, - TimeLimit: task.TimeLimit, - CreatedAt: task.CreatedAt, - UpdatedAt: task.UpdatedAt} + resp.Tasks[i] = TLI2TLI(*task) } return c.JSON(resp) } + +func P2P(p models.Pagination) testerv1.Pagination { + return testerv1.Pagination{ + Page: p.Page, + Total: p.Total, + } +} + +func C2C(c models.Contest) testerv1.Contest { + return testerv1.Contest{ + Id: c.Id, + Title: c.Title, + CreatedAt: c.CreatedAt, + UpdatedAt: c.UpdatedAt, + } +} + +func CLI2CLI(c models.ContestsListItem) testerv1.ContestsListItem { + return testerv1.ContestsListItem{ + Id: c.Id, + Title: c.Title, + CreatedAt: c.CreatedAt, + UpdatedAt: c.UpdatedAt, + } +} + +func PLI2PLI(p models.ProblemsListItem) testerv1.ProblemsListItem { + return testerv1.ProblemsListItem{ + Id: p.Id, + Title: p.Title, + MemoryLimit: p.MemoryLimit, + TimeLimit: p.TimeLimit, + CreatedAt: p.CreatedAt, + UpdatedAt: p.UpdatedAt, + } +} + +func TLI2TLI(t models.TasksListItem) testerv1.TasksListItem { + return testerv1.TasksListItem{ + Id: t.Id, + Position: t.Position, + Title: t.Title, + MemoryLimit: t.MemoryLimit, + ProblemId: t.ProblemId, + TimeLimit: t.TimeLimit, + CreatedAt: t.CreatedAt, + UpdatedAt: t.UpdatedAt, + } +} + +func T2T(t *models.Task) *testerv1.Task { + return &testerv1.Task{ + Id: t.Id, + Title: t.Title, + MemoryLimit: t.MemoryLimit, + TimeLimit: t.TimeLimit, + + InputFormatHtml: t.InputFormatHtml, + LegendHtml: t.LegendHtml, + NotesHtml: t.NotesHtml, + OutputFormatHtml: t.OutputFormatHtml, + Position: t.Position, + ScoringHtml: t.ScoringHtml, + + CreatedAt: t.CreatedAt, + UpdatedAt: t.UpdatedAt, + } +} + +func PR2PR(p *models.Problem) *testerv1.Problem { + return &testerv1.Problem{ + Id: p.Id, + Title: p.Title, + TimeLimit: p.TimeLimit, + MemoryLimit: p.MemoryLimit, + + Legend: p.Legend, + InputFormat: p.InputFormat, + OutputFormat: p.OutputFormat, + Notes: p.Notes, + Scoring: p.Scoring, + + LegendHtml: p.LegendHtml, + InputFormatHtml: p.InputFormatHtml, + OutputFormatHtml: p.OutputFormatHtml, + NotesHtml: p.NotesHtml, + ScoringHtml: p.ScoringHtml, + + CreatedAt: p.CreatedAt, + UpdatedAt: p.UpdatedAt, + } +} + +func PTLI2PTLI(p models.ParticipantsListItem) testerv1.ParticipantsListItem { + return testerv1.ParticipantsListItem{ + Id: p.Id, + UserId: p.UserId, + Name: p.Name, + CreatedAt: p.CreatedAt, + UpdatedAt: p.UpdatedAt, + } +} + +func SLI2SLI(s models.SolutionsListItem) testerv1.SolutionsListItem { + return testerv1.SolutionsListItem{ + ContestId: s.ContestId, + CreatedAt: s.CreatedAt, + Id: s.Id, + Language: s.Language, + ParticipantId: s.ParticipantId, + Penalty: s.Penalty, + Score: s.Score, + State: s.State, + TaskId: s.TaskId, + TotalScore: s.TotalScore, + UpdatedAt: s.UpdatedAt, + } +} + +func S2S(s models.Solution) testerv1.Solution { + return testerv1.Solution{ + Id: s.Id, + TaskId: s.TaskId, + ParticipantId: s.ParticipantId, + Solution: s.Solution, + State: s.State, + Score: s.Score, + Penalty: s.Penalty, + TotalScore: s.TotalScore, + Language: s.Language, + CreatedAt: s.CreatedAt, + UpdatedAt: s.UpdatedAt, + } +} diff --git a/internal/tester/pg_repository.go b/internal/tester/pg_repository.go index d71d9fe..81883ca 100644 --- a/internal/tester/pg_repository.go +++ b/internal/tester/pg_repository.go @@ -27,7 +27,7 @@ type ProblemPostgresRepository interface { CreateProblem(ctx context.Context, q Querier, title string) (int32, error) ReadProblemById(ctx context.Context, q Querier, id int32) (*models.Problem, error) DeleteProblem(ctx context.Context, q Querier, id int32) error - ListProblems(ctx context.Context, q Querier, page int32, pageSize int32) ([]*models.ProblemListItem, int32, error) + ListProblems(ctx context.Context, q Querier, filter models.ProblemsFilter) (*models.ProblemsList, error) UpdateProblem(ctx context.Context, q Querier, id int32, heading models.ProblemUpdate) error } @@ -39,14 +39,14 @@ type ContestRepository interface { DeleteTask(ctx context.Context, taskId int32) error AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error) DeleteParticipant(ctx context.Context, participantId int32) error - ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) - ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error) - ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) + ReadTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) + ListContests(ctx context.Context, filter models.ContestsFilter) (*models.ContestsList, error) + ListParticipants(ctx context.Context, filter models.ParticipantsFilter) (*models.ParticipantsList, error) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error ReadSolution(ctx context.Context, id int32) (*models.Solution, error) CreateSolution(ctx context.Context, creation *models.SolutionCreation) (int32, error) - ListSolutions(ctx context.Context, filters models.SolutionsFilter) ([]*models.SolutionsListItem, int32, error) + ListSolutions(ctx context.Context, filter models.SolutionsFilter) (*models.SolutionsList, error) ReadTask(ctx context.Context, id int32) (*models.Task, error) ReadMonitor(ctx context.Context, id int32) (*models.Monitor, error) } diff --git a/internal/tester/repository/pg_problems_repository.go b/internal/tester/repository/pg_problems_repository.go index 4fff46e..ecdfe1b 100644 --- a/internal/tester/repository/pg_problems_repository.go +++ b/internal/tester/repository/pg_problems_repository.go @@ -87,14 +87,14 @@ LIMIT ? OFFSET ?` CountProblemsQuery = "SELECT COUNT(*) FROM problems" ) -func (r *ProblemRepository) ListProblems(ctx context.Context, q tester.Querier, page int32, pageSize int32) ([]*models.ProblemListItem, int32, error) { +func (r *ProblemRepository) ListProblems(ctx context.Context, q tester.Querier, page int32, pageSize int32) ([]*models.ProblemsListItem, int32, error) { const op = "ContestRepository.ListProblems" if pageSize > 20 || pageSize < 1 { pageSize = 1 } - var problems []*models.ProblemListItem + var problems []*models.ProblemsListItem query := q.Rebind(ListProblemsQuery) err := q.SelectContext(ctx, &problems, query, pageSize, (page-1)*pageSize) if err != nil { diff --git a/internal/tester/usecase.go b/internal/tester/usecase.go index 1d970d1..9ddf235 100644 --- a/internal/tester/usecase.go +++ b/internal/tester/usecase.go @@ -9,7 +9,7 @@ type ProblemUseCase interface { CreateProblem(ctx context.Context, title string) (int32, error) ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) DeleteProblem(ctx context.Context, id int32) error - ListProblems(ctx context.Context, page int32, pageSize int32) ([]*models.ProblemListItem, int32, error) + ListProblems(ctx context.Context, filter models.ProblemsFilter) (*models.ProblemsList, error) UpdateProblem(ctx context.Context, id int32, problem models.ProblemUpdate) error } @@ -21,14 +21,14 @@ type ContestUseCase interface { DeleteTask(ctx context.Context, taskId int32) error AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error) DeleteParticipant(ctx context.Context, participantId int32) error - ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) - ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error) - ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) + ReadTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) + ListContests(ctx context.Context, filter models.ContestsFilter) (*models.ContestsList, error) + ListParticipants(ctx context.Context, filter models.ParticipantsFilter) (*models.ParticipantsList, error) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error ReadSolution(ctx context.Context, id int32) (*models.Solution, error) CreateSolution(ctx context.Context, creation *models.SolutionCreation) (int32, error) - ListSolutions(ctx context.Context, filters models.SolutionsFilter) ([]*models.SolutionsListItem, int32, error) + ListSolutions(ctx context.Context, filter models.SolutionsFilter) (*models.SolutionsList, error) ReadTask(ctx context.Context, id int32) (*models.Task, error) ReadMonitor(ctx context.Context, id int32) (*models.Monitor, error) } diff --git a/internal/tester/usecase/problems_usecase.go b/internal/tester/usecase/problems_usecase.go index 71bd5d8..785c4a9 100644 --- a/internal/tester/usecase/problems_usecase.go +++ b/internal/tester/usecase/problems_usecase.go @@ -38,7 +38,7 @@ func (u *ProblemUseCase) DeleteProblem(ctx context.Context, id int32) error { return u.problemRepo.DeleteProblem(ctx, u.problemRepo.DB(), id) } -func (u *ProblemUseCase) ListProblems(ctx context.Context, page int32, pageSize int32) ([]*models.ProblemListItem, int32, error) { +func (u *ProblemUseCase) ListProblems(ctx context.Context, page int32, pageSize int32) ([]*models.ProblemsListItem, int32, error) { return u.problemRepo.ListProblems(ctx, u.problemRepo.DB(), page, pageSize) } diff --git a/proto b/proto index 9c69ced..16781a4 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 9c69ced34b0a7596c3bb37106d97c6f0a48731de +Subproject commit 16781a46412eea455f27372045c216126c39d628