package problem import ( "git.0x7f.app/WOJ/woj-server/internal/e" "git.0x7f.app/WOJ/woj-server/internal/model" "git.0x7f.app/WOJ/woj-server/internal/service/problem" "github.com/gin-gonic/gin" ) type searchRequest struct { Keyword string `form:"keyword" json:"keyword"` Tag string `form:"tag" json:"tag"` Offset int `form:"offset" json:"offset"` Limit int `form:"limit" json:"limit" binding:"required"` } // 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 keyword formData string false "keyword" // @Param tag formData string false "tag" // @Param offset formData int false "start position" // @Param limit formData int true "limit number of records" // @Response 200 {object} e.Response[e.WithCount[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 } var count int64 param := problem.QueryData{ Keyword: req.Keyword, Tag: req.Tag, Associations: true, ShouldEnable: true, Offset: req.Offset, Limit: req.Limit, Count: &count, } problems, status := h.problemService.QueryFuzz(¶m) e.Pong(c, status, e.WithCount[*model.Problem]{Count: count, Data: problems}) }