2022-09-26 16:13:31 +08:00
|
|
|
package problem
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/WHUPRJ/woj-server/internal/e"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type searchRequest struct {
|
|
|
|
Search string `form:"search"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search
|
|
|
|
// @Summary get detail of a problem
|
|
|
|
// @Description get detail of a problem
|
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
|
// @Produce json
|
2022-10-22 17:38:39 +08:00
|
|
|
// @Param search formData string false "word search"
|
|
|
|
// @Response 200 {object} e.Response "problemset"
|
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
|
|
|
|
}
|
|
|
|
}
|