41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package problem
|
|
|
|
import (
|
|
"git.0x7f.app/WOJ/woj-server/internal/e"
|
|
_ "git.0x7f.app/WOJ/woj-server/internal/model" // swag requires this
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type searchRequest struct {
|
|
Search string `form:"search"`
|
|
}
|
|
|
|
// Search
|
|
// @Summary search for problems
|
|
// @Description Search for problems based on keywords. If the keyword is empty, return all problems.
|
|
// @Tags problem
|
|
// @Accept application/x-www-form-urlencoded
|
|
// @Produce json
|
|
// @Param search formData string false "keyword"
|
|
// @Response 200 {object} e.Response[[]model.Problem] "problems found"
|
|
// @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
|
|
}
|
|
|
|
// TODO: pagination
|
|
if req.Search == "" {
|
|
// TODO: query without LIKE
|
|
problems, status := h.problemService.QueryFuzz(req.Search, true, true)
|
|
e.Pong(c, status, problems)
|
|
return
|
|
} else {
|
|
problems, status := h.problemService.QueryFuzz(req.Search, true, true)
|
|
e.Pong(c, status, problems)
|
|
return
|
|
}
|
|
}
|