oc-aggregator/controllers/search.go

81 lines
1.9 KiB
Go

package controllers
import (
"oc-aggregator/models"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about object
type SearchController struct {
beego.Controller
}
// @Title Search
// @Description search using json post
// @Param body body models.Object true "The object content"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router / [post]
func (o *SearchController) Post() {
o.ServeJSON()
}
// @Title Search
// @Description search by query
// @Param query path string true "the query string you need"
// @Success 200 {string} searchId
// @Failure 403 :query is empty
// @router /:query [get]
func (o *SearchController) Get() {
objectId := o.Ctx.Input.Param(":query")
if objectId != "" {
ob, err := models.StartSearch(objectId)
if err != nil {
o.Data["json"] = err.Error()
} else {
o.Data["json"] = ob
}
}
o.ServeJSON()
}
// @Title Search
// @Description get the search progress
// @Param objectId path string true "the searchId you want to get progress for"
// @Success 200 {int} progress percentage
// @Failure 403 :searchId is empty
// @router /progress/:searchId [get]
func (o *SearchController) GetProgress() {
objectId := o.Ctx.Input.Param(":searchId")
if objectId != "" {
ob, err := models.StartSearch(objectId)
if err != nil {
o.Data["json"] = err.Error()
} else {
o.Data["json"] = ob
}
}
o.ServeJSON()
}
// @Title Search
// @Description get the search results in the current state
// @Param searchId path string true "the searchId for which you want results"
// @Success 200 {results} models.Object
// @Failure 403 :objectId is empty
// @router /results/:searchId [get]
func (o *SearchController) GetResults() {
objectId := o.Ctx.Input.Param(":searchId")
if objectId != "" {
ob, err := models.StartSearch(objectId)
if err != nil {
o.Data["json"] = err.Error()
} else {
o.Data["json"] = ob
}
}
o.ServeJSON()
}