feat: update api
This commit is contained in:
parent
6cbb1ab4a9
commit
3413b136b1
@ -69,5 +69,5 @@ func (h *handler) CreateVersion(c *gin.Context) {
|
|||||||
_, status = h.taskService.ProblemBuild(payload)
|
_, status = h.taskService.ProblemBuild(payload)
|
||||||
e.Pong[any](c, status, nil)
|
e.Pong[any](c, status, nil)
|
||||||
|
|
||||||
// TODO: if failed, delete problem version
|
// consumer/problemUpdate.go will update problem version status
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ func (h *handler) Details(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only Admin is able to view disabled problems
|
||||||
claim, exist := c.Get("claim")
|
claim, exist := c.Get("claim")
|
||||||
shouldEnable := !exist || claim.(*model.Claim).Role < model.RoleAdmin
|
shouldEnable := !exist || claim.(*model.Claim).Role < model.RoleAdmin
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ type searchRequest struct {
|
|||||||
|
|
||||||
// Search
|
// Search
|
||||||
// @Summary search for problems
|
// @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
|
// @Tags problem
|
||||||
// @Accept application/x-www-form-urlencoded
|
// @Accept application/x-www-form-urlencoded
|
||||||
// @Produce json
|
// @Produce json
|
||||||
@ -33,12 +33,16 @@ func (h *handler) Search(c *gin.Context) {
|
|||||||
return
|
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
|
var count int64
|
||||||
param := problem.QueryData{
|
param := problem.QueryData{
|
||||||
Keyword: req.Keyword,
|
Keyword: req.Keyword,
|
||||||
Tag: req.Tag,
|
Tag: req.Tag,
|
||||||
Associations: true,
|
Associations: true,
|
||||||
ShouldEnable: true,
|
ShouldEnable: shouldEnable,
|
||||||
Offset: req.Offset,
|
Offset: req.Offset,
|
||||||
Limit: req.Limit,
|
Limit: req.Limit,
|
||||||
Count: &count,
|
Count: &count,
|
||||||
|
@ -3,6 +3,7 @@ package submission
|
|||||||
import (
|
import (
|
||||||
"git.0x7f.app/WOJ/woj-server/internal/e"
|
"git.0x7f.app/WOJ/woj-server/internal/e"
|
||||||
"git.0x7f.app/WOJ/woj-server/internal/model"
|
"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"
|
"git.0x7f.app/WOJ/woj-server/internal/service/submission"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -47,6 +48,13 @@ func (h *handler) Create(c *gin.Context) {
|
|||||||
return
|
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
|
// query latest version
|
||||||
pv, status := h.problemService.QueryLatestVersion(req.Pid)
|
pv, status := h.problemService.QueryLatestVersion(req.Pid)
|
||||||
if status != e.Success {
|
if status != e.Success {
|
||||||
|
@ -18,6 +18,7 @@ type Problem struct {
|
|||||||
type ProblemVersion struct {
|
type ProblemVersion struct {
|
||||||
gorm.Model `json:"meta"`
|
gorm.Model `json:"meta"`
|
||||||
ProblemID uint `json:"-" gorm:"not null;index"`
|
ProblemID uint `json:"-" gorm:"not null;index"`
|
||||||
|
Problem Problem `json:"problem" gorm:"foreignKey:ProblemID"`
|
||||||
Context pgtype.JSON `json:"context" gorm:"type:json"`
|
Context pgtype.JSON `json:"context" gorm:"type:json"`
|
||||||
StorageKey string `json:"-" gorm:"not null"`
|
StorageKey string `json:"-" gorm:"not null"`
|
||||||
IsEnabled bool `json:"is_enabled" gorm:"not null;index"`
|
IsEnabled bool `json:"is_enabled" gorm:"not null;index"`
|
||||||
|
Loading…
Reference in New Issue
Block a user