2022-10-22 17:38:39 +08:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
2023-07-14 21:47:11 +08:00
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/e"
|
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/model"
|
2022-10-22 17:38:39 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type queryByVersionRequest struct {
|
2022-10-23 17:29:35 +08:00
|
|
|
ProblemVersionID uint `form:"pvid" binding:"required"`
|
2022-10-22 17:38:39 +08:00
|
|
|
Offset int `form:"offset"`
|
2022-10-23 17:29:35 +08:00
|
|
|
Limit int `form:"limit" binding:"required"`
|
2022-10-22 17:38:39 +08:00
|
|
|
}
|
|
|
|
|
2022-10-23 17:29:35 +08:00
|
|
|
// QueryByProblemVersion
|
|
|
|
// @Summary query submissions by problem version (admin only)
|
|
|
|
// @Description query submissions by problem version (admin only)
|
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
|
// @Produce json
|
|
|
|
// @Param pvid formData uint true "problem version id"
|
2022-11-14 17:18:34 +08:00
|
|
|
// @Param offset formData int false "start position"
|
2022-10-23 17:29:35 +08:00
|
|
|
// @Param limit formData int true "limit number of records"
|
|
|
|
// @Response 200 {object} e.Response "[]*model.status"
|
|
|
|
// @Router /v1/status/query/problem_version [post]
|
2022-10-22 17:38:39 +08:00
|
|
|
func (h *handler) QueryByProblemVersion(c *gin.Context) {
|
|
|
|
|
|
|
|
claim, exist := c.Get("claim")
|
|
|
|
if !exist {
|
|
|
|
e.Pong(c, e.UserUnauthenticated, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-15 16:19:49 +08:00
|
|
|
role := claim.(*model.Claim).Role
|
2022-10-22 17:38:39 +08:00
|
|
|
|
|
|
|
req := new(queryByVersionRequest)
|
|
|
|
|
|
|
|
if err := c.ShouldBind(req); err != nil {
|
2022-10-23 17:29:35 +08:00
|
|
|
e.Pong(c, e.InvalidParameter, err.Error())
|
2022-10-22 17:38:39 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if role < model.RoleAdmin {
|
|
|
|
e.Pong(c, e.UserUnauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
statuses, eStatus := h.statusService.QueryByVersion(req.ProblemVersionID, req.Offset, req.Limit)
|
|
|
|
|
|
|
|
e.Pong(c, eStatus, statuses)
|
|
|
|
}
|