fix: check problem version exists on update when IsEnabled = true (#3)

This commit is contained in:
Paul Pan 2023-12-27 22:28:58 +08:00
parent 6a72198541
commit cc2c42bded
Signed by: Paul
GPG Key ID: D639BDF5BA578AF4

View File

@ -84,6 +84,16 @@ func (h *handler) Update(c *gin.Context) {
return return
} }
// if IsEnabled is set to true, check if the problem has a latest version
if req.IsEnabled {
_, status := h.problemService.QueryLatestVersion(p.ID)
if status != e.Success {
e.Pong[any](c, status, nil)
return
}
p.IsEnabled = true
}
// update problem // update problem
p.Title = utils.If(req.Title != "", req.Title, p.Title) p.Title = utils.If(req.Title != "", req.Title, p.Title)
p.Statement = utils.If(req.Statement != "", req.Statement, p.Statement) p.Statement = utils.If(req.Statement != "", req.Statement, p.Statement)
@ -92,7 +102,6 @@ func (h *handler) Update(c *gin.Context) {
_ = tags.Set(req.Tags) _ = tags.Set(req.Tags)
p.Tags = tags p.Tags = tags
} }
p.IsEnabled = req.IsEnabled
p, status = h.problemService.Update(p) p, status = h.problemService.Update(p)
e.Pong(c, status, p) e.Pong(c, status, p)