feat: update api

This commit is contained in:
Paul Pan 2024-04-28 23:19:00 +08:00
parent 6cbb1ab4a9
commit 3413b136b1
Signed by: Paul
GPG Key ID: D639BDF5BA578AF4
5 changed files with 17 additions and 3 deletions

View File

@ -69,5 +69,5 @@ func (h *handler) CreateVersion(c *gin.Context) {
_, status = h.taskService.ProblemBuild(payload)
e.Pong[any](c, status, nil)
// TODO: if failed, delete problem version
// consumer/problemUpdate.go will update problem version status
}

View File

@ -32,6 +32,7 @@ func (h *handler) Details(c *gin.Context) {
return
}
// Only Admin is able to view disabled problems
claim, exist := c.Get("claim")
shouldEnable := !exist || claim.(*model.Claim).Role < model.RoleAdmin

View File

@ -16,7 +16,7 @@ type searchRequest struct {
// Search
// @Summary search for problems
// @Description Search for problems based on keywords. If the keyword is empty, return all problems.
// @Description Search for problems based on keywords. If the keyword is empty, return all problems. Admin could view all problems.
// @Tags problem
// @Accept application/x-www-form-urlencoded
// @Produce json
@ -33,12 +33,16 @@ func (h *handler) Search(c *gin.Context) {
return
}
// Only Admin is able to view disabled problems
claim, exist := c.Get("claim")
shouldEnable := !exist || claim.(*model.Claim).Role < model.RoleAdmin
var count int64
param := problem.QueryData{
Keyword: req.Keyword,
Tag: req.Tag,
Associations: true,
ShouldEnable: true,
ShouldEnable: shouldEnable,
Offset: req.Offset,
Limit: req.Limit,
Count: &count,

View File

@ -3,6 +3,7 @@ package submission
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"
"git.0x7f.app/WOJ/woj-server/internal/service/submission"
"github.com/gin-gonic/gin"
)
@ -47,6 +48,13 @@ func (h *handler) Create(c *gin.Context) {
return
}
// check problem enabled
_, status := h.problemService.Query(&problem.QueryData{ID: req.Pid, Associations: false, ShouldEnable: role < model.RoleAdmin})
if status != e.Success {
e.Pong[any](c, status, nil)
return
}
// query latest version
pv, status := h.problemService.QueryLatestVersion(req.Pid)
if status != e.Success {

View File

@ -18,6 +18,7 @@ type Problem struct {
type ProblemVersion struct {
gorm.Model `json:"meta"`
ProblemID uint `json:"-" gorm:"not null;index"`
Problem Problem `json:"problem" gorm:"foreignKey:ProblemID"`
Context pgtype.JSON `json:"context" gorm:"type:json"`
StorageKey string `json:"-" gorm:"not null"`
IsEnabled bool `json:"is_enabled" gorm:"not null;index"`