Draft, peer selection done, search in progress

This commit is contained in:
ycc
2023-03-10 11:28:38 +01:00
parent e3719fb08b
commit 87a1759ac4
17 changed files with 898 additions and 1 deletions

80
controllers/search.go Normal file
View File

@@ -0,0 +1,80 @@
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()
}