refactor(tester): refactor api

This commit is contained in:
Vyacheslav1557 2025-03-29 00:36:23 +05:00
parent 3396746d60
commit 5536c086e0
11 changed files with 257 additions and 231 deletions

View file

@ -16,6 +16,20 @@ type ContestsListItem struct {
UpdatedAt time.Time `db:"updated_at"` 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 { type ContestUpdate struct {
Title *string `json:"title"` Title *string `json:"title"`
} }

View file

@ -0,0 +1,6 @@
package models
type Pagination struct {
Page int32 `json:"page"`
Total int32 `json:"total"`
}

View file

@ -20,6 +20,22 @@ type ParticipantsListItem struct {
UpdatedAt time.Time `db:"updated_at"` 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 { type ParticipantUpdate struct {
Name *string `json:"name"` Name *string `json:"name"`
} }

View file

@ -25,7 +25,7 @@ type Problem struct {
UpdatedAt time.Time `db:"updated_at"` UpdatedAt time.Time `db:"updated_at"`
} }
type ProblemListItem struct { type ProblemsListItem struct {
Id int32 `db:"id"` Id int32 `db:"id"`
Title string `db:"title"` Title string `db:"title"`
MemoryLimit int32 `db:"memory_limit"` MemoryLimit int32 `db:"memory_limit"`
@ -34,6 +34,20 @@ type ProblemListItem struct {
UpdatedAt time.Time `db:"updated_at"` 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 { type ProblemUpdate struct {
Title *string `db:"title"` Title *string `db:"title"`
MemoryLimit *int32 `db:"memory_limit"` MemoryLimit *int32 `db:"memory_limit"`

View file

@ -38,6 +38,11 @@ type SolutionsListItem struct {
CreatedAt time.Time `db:"created_at"` CreatedAt time.Time `db:"created_at"`
} }
type SolutionsList struct {
Solutions []*SolutionsListItem
Pagination Pagination
}
type SolutionsFilter struct { type SolutionsFilter struct {
Page int32 Page int32
PageSize int32 PageSize int32
@ -49,6 +54,10 @@ type SolutionsFilter struct {
Order *int32 Order *int32
} }
func (f SolutionsFilter) Offset() int32 {
return (f.Page - 1) * f.PageSize
}
//type Result int32 //type Result int32
// //
//const ( //const (

View file

@ -22,60 +22,42 @@ func NewTesterHandlers(problemsUC tester.ProblemUseCase, contestsUC tester.Conte
} }
func (h *TesterHandlers) ListContests(c *fiber.Ctx, params testerv1.ListContestsParams) error { 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 { if err != nil {
return c.SendStatus(pkg.ToREST(err)) return c.SendStatus(pkg.ToREST(err))
} }
resp := testerv1.ListContestsResponse{ resp := testerv1.ListContestsResponse{
Contests: make([]testerv1.ContestsListItem, len(contests)), Contests: make([]testerv1.ContestsListItem, len(contestsList.Contests)),
Page: params.Page, Pagination: P2P(contestsList.Pagination),
MaxPage: func() int32 {
if count%params.PageSize == 0 {
return count / params.PageSize
}
return count/params.PageSize + 1
}(),
} }
for i, contest := range contests { for i, contest := range contestsList.Contests {
resp.Contests[i] = testerv1.ContestsListItem{ resp.Contests[i] = CLI2CLI(*contest)
Id: contest.Id,
Title: contest.Title,
CreatedAt: contest.CreatedAt,
UpdatedAt: contest.UpdatedAt,
}
} }
return c.JSON(resp) return c.JSON(resp)
} }
func (h *TesterHandlers) ListProblems(c *fiber.Ctx, params testerv1.ListProblemsParams) error { 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 { if err != nil {
return c.SendStatus(pkg.ToREST(err)) return c.SendStatus(pkg.ToREST(err))
} }
resp := testerv1.ListProblemsResponse{ resp := testerv1.ListProblemsResponse{
Problems: make([]testerv1.ProblemListItem, len(problems)), Problems: make([]testerv1.ProblemsListItem, len(problemsList.Problems)),
Page: params.Page, Pagination: P2P(problemsList.Pagination),
MaxPage: func() int32 {
if count%params.PageSize == 0 {
return count / params.PageSize
}
return count/params.PageSize + 1
}(),
} }
for i, problem := range problems { for i, problem := range problemsList.Problems {
resp.Problems[i] = testerv1.ProblemListItem{ resp.Problems[i] = PLI2PLI(*problem)
Id: problem.Id,
Title: problem.Title,
MemoryLimit: problem.MemoryLimit,
TimeLimit: problem.TimeLimit,
CreatedAt: problem.CreatedAt,
UpdatedAt: problem.UpdatedAt,
}
} }
return c.JSON(resp) return c.JSON(resp)
@ -112,18 +94,13 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error {
// return c.SendStatus(fiber.StatusUnauthorized) // return c.SendStatus(fiber.StatusUnauthorized)
//} //}
tasks, err := h.contestsUC.ReadRichTasks(c.Context(), id) tasks, err := h.contestsUC.ReadTasks(c.Context(), id)
if err != nil { if err != nil {
return c.SendStatus(pkg.ToREST(err)) return c.SendStatus(pkg.ToREST(err))
} }
resp := testerv1.GetContestResponse{ resp := testerv1.GetContestResponse{
Contest: testerv1.Contest{ Contest: C2C(*contest),
Id: id,
Title: contest.Title,
CreatedAt: contest.CreatedAt,
UpdatedAt: contest.UpdatedAt,
},
Tasks: make([]struct { Tasks: make([]struct {
Solution testerv1.Solution `json:"solution"` Solution testerv1.Solution `json:"solution"`
Task testerv1.TasksListItem `json:"task"` Task testerv1.TasksListItem `json:"task"`
@ -136,16 +113,7 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error {
Task testerv1.TasksListItem `json:"task"` Task testerv1.TasksListItem `json:"task"`
}{ }{
Solution: testerv1.Solution{}, Solution: testerv1.Solution{},
Task: testerv1.TasksListItem{ Task: TLI2TLI(*task),
Id: task.Id,
ProblemId: task.ProblemId,
Position: task.Position,
Title: task.Title,
MemoryLimit: task.MemoryLimit,
TimeLimit: task.TimeLimit,
CreatedAt: task.CreatedAt,
UpdatedAt: task.UpdatedAt,
},
} }
} }
@ -220,55 +188,27 @@ func (h *TesterHandlers) GetProblem(c *fiber.Ctx, id int32) error {
} }
return c.JSON( return c.JSON(
testerv1.GetProblemResponse{Problem: testerv1.Problem{ testerv1.GetProblemResponse{Problem: *PR2PR(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,
}},
) )
} }
func (h *TesterHandlers) ListParticipants(c *fiber.Ctx, params testerv1.ListParticipantsParams) error { 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 { if err != nil {
return c.SendStatus(pkg.ToREST(err)) return c.SendStatus(pkg.ToREST(err))
} }
resp := testerv1.ListParticipantsResponse{ resp := testerv1.ListParticipantsResponse{
Participants: make([]testerv1.ParticipantsListItem, len(participants)), Participants: make([]testerv1.ParticipantsListItem, len(participantsList.Participants)),
Page: params.Page, Pagination: P2P(participantsList.Pagination),
MaxPage: func() int32 {
if count%params.PageSize == 0 {
return count / params.PageSize
}
return count/params.PageSize + 1
}(),
} }
for i, participant := range participants { for i, participant := range participantsList.Participants {
resp.Participants[i] = testerv1.ParticipantsListItem{ resp.Participants[i] = PTLI2PTLI(*participant)
Id: participant.Id,
UserId: participant.UserId,
Name: participant.Name,
CreatedAt: participant.CreatedAt,
UpdatedAt: participant.UpdatedAt,
}
} }
return c.JSON(resp) 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 { 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, ContestId: params.ContestId,
Page: params.Page, Page: params.Page,
PageSize: params.PageSize, PageSize: params.PageSize,
@ -350,30 +290,12 @@ func (h *TesterHandlers) ListSolutions(c *fiber.Ctx, params testerv1.ListSolutio
} }
resp := testerv1.ListSolutionsResponse{ resp := testerv1.ListSolutionsResponse{
Solutions: make([]testerv1.SolutionsListItem, len(list)), Solutions: make([]testerv1.SolutionsListItem, len(solutionsList.Solutions)),
Page: params.Page, Pagination: P2P(solutionsList.Pagination),
MaxPage: func() int32 {
if total%params.PageSize == 0 {
return total / params.PageSize
}
return total/params.PageSize + 1
}(),
} }
for i, solution := range list { for i, solution := range solutionsList.Solutions {
resp.Solutions[i] = testerv1.SolutionsListItem{ resp.Solutions[i] = SLI2SLI(*solution)
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,
}
} }
return c.JSON(resp) return c.JSON(resp)
@ -427,19 +349,7 @@ func (h *TesterHandlers) GetSolution(c *fiber.Ctx, id int32) error {
} }
return c.JSON( return c.JSON(
testerv1.GetSolutionResponse{Solution: testerv1.Solution{ testerv1.GetSolutionResponse{Solution: S2S(*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,
}},
) )
} }
@ -449,7 +359,7 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error {
return c.SendStatus(pkg.ToREST(err)) 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 { if err != nil {
return c.SendStatus(pkg.ToREST(err)) return c.SendStatus(pkg.ToREST(err))
} }
@ -460,43 +370,13 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error {
} }
resp := testerv1.GetTaskResponse{ resp := testerv1.GetTaskResponse{
Contest: struct { Contest: C2C(*contest),
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)), Tasks: make([]testerv1.TasksListItem, len(tasks)),
}, Task: *T2T(t),
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,
},
} }
for i, task := range tasks { for i, task := range tasks {
resp.Contest.Tasks[i] = testerv1.TasksListItem{ resp.Tasks[i] = TLI2TLI(*task)
Id: task.Id,
Position: task.Position,
Title: task.Title,
MemoryLimit: task.MemoryLimit,
ProblemId: task.ProblemId,
TimeLimit: task.TimeLimit,
CreatedAt: task.CreatedAt,
UpdatedAt: task.UpdatedAt}
} }
return c.JSON(resp) return c.JSON(resp)
@ -513,43 +393,20 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara
return c.SendStatus(pkg.ToREST(err)) 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 { if err != nil {
return c.SendStatus(pkg.ToREST(err)) return c.SendStatus(pkg.ToREST(err))
} }
resp := testerv1.GetMonitorResponse{ resp := testerv1.GetMonitorResponse{
Contest: struct { Contest: C2C(*contest),
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)), Tasks: make([]testerv1.TasksListItem, len(tasks)),
}, Participants: make([]testerv1.ParticipantsStat, len(monitor.Participants)),
Participants: make([]struct { SummaryPerProblem: make([]testerv1.ProblemStatSummary, len(monitor.Summary)),
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)),
} }
for i, participant := range monitor.Participants { for i, participant := range monitor.Participants {
resp.Participants[i] = struct { resp.Participants[i] = testerv1.ParticipantsStat{
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"`
}{
Id: participant.Id, Id: participant.Id,
Name: participant.Name, Name: participant.Name,
PenaltyInTotal: participant.PenaltyInTotal, PenaltyInTotal: participant.PenaltyInTotal,
@ -558,28 +415,12 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara
} }
for j, solution := range participant.Solutions { for j, solution := range participant.Solutions {
resp.Participants[i].Solutions[j] = testerv1.SolutionsListItem{ resp.Participants[i].Solutions[j] = SLI2SLI(*solution)
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,
}
} }
} }
for i, problem := range monitor.Summary { for i, problem := range monitor.Summary {
resp.SummaryPerProblem[i] = struct { resp.SummaryPerProblem[i] = testerv1.ProblemStatSummary{
Id int32 `json:"id"`
Success int32 `json:"success"`
Total int32 `json:"total"`
}{
Id: problem.Id, Id: problem.Id,
Success: problem.Success, Success: problem.Success,
Total: problem.Total, Total: problem.Total,
@ -587,16 +428,142 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara
} }
for i, task := range tasks { for i, task := range tasks {
resp.Contest.Tasks[i] = testerv1.TasksListItem{ resp.Tasks[i] = TLI2TLI(*task)
Id: task.Id,
Position: task.Position,
Title: task.Title,
MemoryLimit: task.MemoryLimit,
ProblemId: task.ProblemId,
TimeLimit: task.TimeLimit,
CreatedAt: task.CreatedAt,
UpdatedAt: task.UpdatedAt}
} }
return c.JSON(resp) 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,
}
}

View file

@ -27,7 +27,7 @@ type ProblemPostgresRepository interface {
CreateProblem(ctx context.Context, q Querier, title string) (int32, error) CreateProblem(ctx context.Context, q Querier, title string) (int32, error)
ReadProblemById(ctx context.Context, q Querier, id int32) (*models.Problem, error) ReadProblemById(ctx context.Context, q Querier, id int32) (*models.Problem, error)
DeleteProblem(ctx context.Context, q Querier, id int32) 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 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 DeleteTask(ctx context.Context, taskId int32) error
AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error) AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error)
DeleteParticipant(ctx context.Context, participantId int32) error DeleteParticipant(ctx context.Context, participantId int32) error
ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) ReadTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error)
ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error) ListContests(ctx context.Context, filter models.ContestsFilter) (*models.ContestsList, error)
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) ListParticipants(ctx context.Context, filter models.ParticipantsFilter) (*models.ParticipantsList, error)
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error
ReadSolution(ctx context.Context, id int32) (*models.Solution, error) ReadSolution(ctx context.Context, id int32) (*models.Solution, error)
CreateSolution(ctx context.Context, creation *models.SolutionCreation) (int32, 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) ReadTask(ctx context.Context, id int32) (*models.Task, error)
ReadMonitor(ctx context.Context, id int32) (*models.Monitor, error) ReadMonitor(ctx context.Context, id int32) (*models.Monitor, error)
} }

View file

@ -87,14 +87,14 @@ LIMIT ? OFFSET ?`
CountProblemsQuery = "SELECT COUNT(*) FROM problems" 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" const op = "ContestRepository.ListProblems"
if pageSize > 20 || pageSize < 1 { if pageSize > 20 || pageSize < 1 {
pageSize = 1 pageSize = 1
} }
var problems []*models.ProblemListItem var problems []*models.ProblemsListItem
query := q.Rebind(ListProblemsQuery) query := q.Rebind(ListProblemsQuery)
err := q.SelectContext(ctx, &problems, query, pageSize, (page-1)*pageSize) err := q.SelectContext(ctx, &problems, query, pageSize, (page-1)*pageSize)
if err != nil { if err != nil {

View file

@ -9,7 +9,7 @@ type ProblemUseCase interface {
CreateProblem(ctx context.Context, title string) (int32, error) CreateProblem(ctx context.Context, title string) (int32, error)
ReadProblemById(ctx context.Context, id int32) (*models.Problem, error) ReadProblemById(ctx context.Context, id int32) (*models.Problem, error)
DeleteProblem(ctx context.Context, id int32) 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 UpdateProblem(ctx context.Context, id int32, problem models.ProblemUpdate) error
} }
@ -21,14 +21,14 @@ type ContestUseCase interface {
DeleteTask(ctx context.Context, taskId int32) error DeleteTask(ctx context.Context, taskId int32) error
AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error) AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error)
DeleteParticipant(ctx context.Context, participantId int32) error DeleteParticipant(ctx context.Context, participantId int32) error
ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) ReadTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error)
ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error) ListContests(ctx context.Context, filter models.ContestsFilter) (*models.ContestsList, error)
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) ListParticipants(ctx context.Context, filter models.ParticipantsFilter) (*models.ParticipantsList, error)
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error
ReadSolution(ctx context.Context, id int32) (*models.Solution, error) ReadSolution(ctx context.Context, id int32) (*models.Solution, error)
CreateSolution(ctx context.Context, creation *models.SolutionCreation) (int32, 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) ReadTask(ctx context.Context, id int32) (*models.Task, error)
ReadMonitor(ctx context.Context, id int32) (*models.Monitor, error) ReadMonitor(ctx context.Context, id int32) (*models.Monitor, error)
} }

View file

@ -38,7 +38,7 @@ func (u *ProblemUseCase) DeleteProblem(ctx context.Context, id int32) error {
return u.problemRepo.DeleteProblem(ctx, u.problemRepo.DB(), id) 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) return u.problemRepo.ListProblems(ctx, u.problemRepo.DB(), page, pageSize)
} }

2
proto

@ -1 +1 @@
Subproject commit 9c69ced34b0a7596c3bb37106d97c6f0a48731de Subproject commit 16781a46412eea455f27372045c216126c39d628