package problem import ( "git.0x7f.app/WOJ/woj-server/internal/e" "git.0x7f.app/WOJ/woj-server/internal/model" "git.0x7f.app/WOJ/woj-server/internal/service/problem" "github.com/gin-gonic/gin" ) type detailsRequest struct { Pid uint `form:"pid" json:"pid"` } type problemDetailsResponse struct { Problem *model.Problem `json:"problem"` Context interface{} `json:"context"` } // Details // @Summary get details of a problem // @Description Get details of a problem. // @Tags problem // @Accept application/x-www-form-urlencoded // @Produce json // @Param pid formData int true "problem id" // @Response 200 {object} e.Response[problemDetailsResponse] "problem details" // @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 } // Only Admin is able to view disabled problems claim, exist := c.Get("claim") shouldEnable := !exist || claim.(*model.Claim).Role < model.RoleAdmin p, status := h.problemService.Query(&problem.QueryData{ID: req.Pid, Associations: true, ShouldEnable: shouldEnable}) if status != e.Success { e.Pong[any](c, status, nil) return } pv, status := h.problemService.QueryLatestVersion(req.Pid) if status != e.Success { e.Pong[any](c, status, nil) return } e.Pong(c, e.Success, problemDetailsResponse{ Problem: p, Context: pv.Context.Get(), }) }