2022-09-26 16:13:31 +08:00
|
|
|
package problem
|
|
|
|
|
|
|
|
import (
|
2023-07-14 21:47:11 +08:00
|
|
|
"git.0x7f.app/WOJ/woj-server/internal/e"
|
2023-12-22 15:19:13 +08:00
|
|
|
_ "git.0x7f.app/WOJ/woj-server/internal/model" // swag requires this
|
2022-09-26 16:13:31 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type searchRequest struct {
|
|
|
|
Search string `form:"search"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search
|
2023-12-22 15:19:13 +08:00
|
|
|
// @Summary search for problems
|
|
|
|
// @Description Search for problems based on keywords. If the keyword is empty, return all problems.
|
2023-12-18 21:21:15 +08:00
|
|
|
// @Tags problem
|
2022-09-26 16:13:31 +08:00
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
|
// @Produce json
|
2023-12-22 15:19:13 +08:00
|
|
|
// @Param search formData string false "keyword"
|
|
|
|
// @Response 200 {object} e.Response[[]model.Problem] "problems found"
|
2022-09-26 16:13:31 +08:00
|
|
|
// @Router /v1/problem/search [post]
|
|
|
|
func (h *handler) Search(c *gin.Context) {
|
|
|
|
req := new(searchRequest)
|
|
|
|
if err := c.ShouldBind(req); err != nil {
|
|
|
|
e.Pong(c, e.InvalidParameter, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:38:39 +08:00
|
|
|
// TODO: pagination
|
|
|
|
if req.Search == "" {
|
|
|
|
// TODO: query without LIKE
|
2022-10-23 17:29:35 +08:00
|
|
|
problems, status := h.problemService.QueryFuzz(req.Search, true, true)
|
|
|
|
e.Pong(c, status, problems)
|
2022-09-26 16:13:31 +08:00
|
|
|
return
|
|
|
|
} else {
|
2022-10-23 17:29:35 +08:00
|
|
|
problems, status := h.problemService.QueryFuzz(req.Search, true, true)
|
|
|
|
e.Pong(c, status, problems)
|
2022-09-26 16:13:31 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|