-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package handler | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/OJ-lab/oj-lab-services/core" | ||
"github.com/OJ-lab/oj-lab-services/service" | ||
"github.com/OJ-lab/oj-lab-services/service/mapper" | ||
"github.com/OJ-lab/oj-lab-services/service/model" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func SetupSubmissionRouter(baseRoute *gin.RouterGroup) { | ||
g := baseRoute.Group("/submission") | ||
{ | ||
g.GET("", getSubmissionList) | ||
} | ||
} | ||
|
||
type getSubmissionResponseBody struct { | ||
Total int64 `json:"total"` | ||
Data []*model.JudgeTaskSubmission `json:"data"` | ||
} | ||
|
||
// Get Submission List | ||
// | ||
// @Summary Get submission list | ||
// @Description Get submission list | ||
// @Tags submission | ||
// @Accept json | ||
// @Param limit query int false "limit" | ||
// @Param offset query int false "offset" | ||
// @Router /submission [get] | ||
// @Success 200 {object} getSubmissionResponseBody | ||
func getSubmissionList(ginCtx *gin.Context) { | ||
limitQuery, _ := ginCtx.GetQuery("limit") | ||
offsetQuery, _ := ginCtx.GetQuery("offset") | ||
if limitQuery == "" { | ||
limitQuery = "10" | ||
} | ||
if offsetQuery == "" { | ||
offsetQuery = "0" | ||
} | ||
|
||
limit, err := strconv.Atoi(limitQuery) | ||
if err != nil { | ||
core.NewInvalidParamError("limit", "invalid limit").AppendToGin(ginCtx) | ||
return | ||
} | ||
offset, err := strconv.Atoi(offsetQuery) | ||
if err != nil { | ||
core.NewInvalidParamError("offset", "invalid offset").AppendToGin(ginCtx) | ||
return | ||
} | ||
|
||
options := mapper.GetSubmissionOptions{ | ||
Limit: &limit, | ||
Offset: &offset, | ||
} | ||
|
||
submissions, total, svcErr := service.GetJudgeTaskSubmissionList(ginCtx, options) | ||
if svcErr != nil { | ||
svcErr.AppendToGin(ginCtx) | ||
return | ||
} | ||
|
||
ginCtx.JSON(200, getSubmissionResponseBody{ | ||
Total: total, | ||
Data: submissions, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/OJ-lab/oj-lab-services/core" | ||
gormAgent "github.com/OJ-lab/oj-lab-services/core/agent/gorm" | ||
"github.com/OJ-lab/oj-lab-services/service/mapper" | ||
"github.com/OJ-lab/oj-lab-services/service/model" | ||
) | ||
|
||
func GetJudgeTaskSubmissionList( | ||
ctx context.Context, options mapper.GetSubmissionOptions, | ||
) ([]*model.JudgeTaskSubmission, int64, *core.SeviceError) { | ||
db := gormAgent.GetDefaultDB() | ||
submissions, total, err := mapper.GetSubmissionListByOptions(db, options) | ||
if err != nil { | ||
return nil, 0, core.NewInternalError("failed to get submission list") | ||
} | ||
|
||
return submissions, total, nil | ||
} | ||
|
||
func CreateJudgeTaskSubmission( | ||
ctx context.Context, submission model.JudgeTaskSubmission, | ||
) (*model.JudgeTaskSubmission, *core.SeviceError) { | ||
db := gormAgent.GetDefaultDB() | ||
newSubmission, err := mapper.CreateSubmission(db, submission) | ||
if err != nil { | ||
return nil, core.NewInternalError("failed to create submission") | ||
} | ||
|
||
return newSubmission, nil | ||
} |