initial commit
This commit is contained in:
31
controllers/search.go
Normal file
31
controllers/search.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-catalog/models"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
type SearchController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// TODO: Search by word is very very inneficent for not small databases
|
||||
// @Title Search by word
|
||||
// @Description find resources by word
|
||||
// @Param word query string true "Word to search across all resources"
|
||||
// @Success 200 {object} models.SearchResult
|
||||
// @Failure 503 Internal error
|
||||
// @router /byWord [get]
|
||||
func (o *SearchController) FindByWord(word string) {
|
||||
if word != "" {
|
||||
ob, err := models.FindByWord(word)
|
||||
if err != nil {
|
||||
o.Data["json"] = err.Error()
|
||||
o.Ctx.Output.Status = 503
|
||||
} else {
|
||||
o.Data["json"] = ob
|
||||
}
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user