oc-discovery/controllers/identity.go

42 lines
908 B
Go
Raw Permalink Normal View History

2023-03-07 13:29:08 +01:00
package controllers
import (
"encoding/json"
"oc-discovery/models"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about Identitys
type IdentityController struct {
beego.Controller
}
// @Title CreateIdentity
// @Description create identitys
// @Param body body models.Identity true "body for identity content"
2023-03-08 16:48:36 +01:00
// @Success 200 {result} "ok" or error
2023-03-07 13:29:08 +01:00
// @Failure 403 body is empty
// @router / [post]
func (u *IdentityController) Post() {
var identity models.Identity
json.Unmarshal(u.Ctx.Input.RequestBody, &identity)
2023-03-08 16:48:36 +01:00
err := models.UpdateIdentity(&identity)
if err != nil {
u.Data["json"] = err.Error()
} else {
u.Data["json"] = "ok"
}
2023-03-07 13:29:08 +01:00
u.ServeJSON()
}
// @Title Get
// @Description get Identity
// @Success 200 {object} models.Identity
// @router / [get]
func (u *IdentityController) GetAll() {
identity := models.GetIdentity()
u.Data["json"] = identity
u.ServeJSON()
}