2022-10-22 17:38:39 +08:00
|
|
|
package problem
|
|
|
|
|
|
|
|
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 detailsRequest struct {
|
2023-12-23 15:35:09 +08:00
|
|
|
Pid uint `form:"pid" json:"pid"`
|
2022-10-22 17:38:39 +08:00
|
|
|
}
|
|
|
|
|
2023-12-22 15:19:13 +08:00
|
|
|
type problemDetailsResponse struct {
|
|
|
|
Problem *model.Problem `json:"problem"`
|
|
|
|
Context interface{} `json:"context"`
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:38:39 +08:00
|
|
|
// Details
|
|
|
|
// @Summary get details of a problem
|
2023-12-22 15:19:13 +08:00
|
|
|
// @Description Get details of a problem.
|
2023-12-18 21:21:15 +08:00
|
|
|
// @Tags problem
|
2022-10-22 17:38:39 +08:00
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
|
// @Produce json
|
|
|
|
// @Param pid formData int true "problem id"
|
2023-12-22 15:19:13 +08:00
|
|
|
// @Response 200 {object} e.Response[problemDetailsResponse] "problem details"
|
2022-10-22 17:38:39 +08:00
|
|
|
// @Router /v1/problem/details [post]
|
|
|
|
func (h *handler) Details(c *gin.Context) {
|
|
|
|
req := new(detailsRequest)
|
|
|
|
if err := c.ShouldBind(req); err != nil {
|
|
|
|
e.Pong(c, e.InvalidParameter, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
claim, exist := c.Get("claim")
|
2023-07-15 16:19:49 +08:00
|
|
|
shouldEnable := !exist || claim.(*model.Claim).Role < model.RoleAdmin
|
2022-10-22 17:38:39 +08:00
|
|
|
|
|
|
|
p, status := h.problemService.Query(req.Pid, true, shouldEnable)
|
|
|
|
if status != e.Success {
|
2023-12-22 15:19:13 +08:00
|
|
|
e.Pong[any](c, status, nil)
|
2022-10-22 17:38:39 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pv, status := h.problemService.QueryLatestVersion(req.Pid)
|
2022-10-23 17:29:35 +08:00
|
|
|
if status != e.Success {
|
2023-12-22 15:19:13 +08:00
|
|
|
e.Pong[any](c, status, nil)
|
2022-11-14 17:18:34 +08:00
|
|
|
return
|
2022-10-23 17:29:35 +08:00
|
|
|
}
|
2023-12-22 15:19:13 +08:00
|
|
|
|
|
|
|
e.Pong(c, e.Success, problemDetailsResponse{
|
|
|
|
Problem: p,
|
|
|
|
Context: pv.Context.Get(),
|
2022-10-22 17:38:39 +08:00
|
|
|
})
|
|
|
|
}
|