Initial commit
This commit is contained in:
37
controllers/identity.go
Normal file
37
controllers/identity.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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"
|
||||
// @Success 200 {int} models.Identity.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router / [post]
|
||||
func (u *IdentityController) Post() {
|
||||
var identity models.Identity
|
||||
json.Unmarshal(u.Ctx.Input.RequestBody, &identity)
|
||||
id := models.UpdateIdentity(&identity)
|
||||
u.Data["json"] = id
|
||||
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()
|
||||
}
|
||||
90
controllers/peer.go
Normal file
90
controllers/peer.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"oc-discovery/models"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Operations about peer
|
||||
type PeerController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create peer
|
||||
// @Param body body models.Peer true "The peer content"
|
||||
// @Success 200 {string} models.Peer.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router / [post]
|
||||
func (o *PeerController) Post() {
|
||||
var ob models.Peer
|
||||
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
|
||||
peerid := models.AddOne(ob)
|
||||
o.Data["json"] = map[string]string{"PeerId": peerid}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find peer by peerid
|
||||
// @Param peerId path string true "the peerid you want to get"
|
||||
// @Success 200 {peer} models.Peer
|
||||
// @Failure 403 :peerId is empty
|
||||
// @router /:peerId [get]
|
||||
func (o *PeerController) Get() {
|
||||
peerId := o.Ctx.Input.Param(":peerId")
|
||||
if peerId != "" {
|
||||
ob, err := models.GetOne(peerId)
|
||||
if err != nil {
|
||||
o.Data["json"] = err.Error()
|
||||
} else {
|
||||
o.Data["json"] = ob
|
||||
}
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description get all peers
|
||||
// @Success 200
|
||||
// @router / [get]
|
||||
func (o *PeerController) GetAll() {
|
||||
obs := models.GetAll()
|
||||
o.Data["json"] = obs
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Update
|
||||
// @Description update the peer
|
||||
// @Param peerId path string true "The peerid you want to update"
|
||||
// @Param body body models.Peer true "The body"
|
||||
// @Success 200 {peer} models.Peer
|
||||
// @Failure 403 :peerId is empty
|
||||
// @router /:peerId [put]
|
||||
func (o *PeerController) Put() {
|
||||
peerId := o.Ctx.Input.Param(":peerId")
|
||||
var ob models.Peer
|
||||
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
|
||||
|
||||
err := models.Update(peerId, ob.Score)
|
||||
if err != nil {
|
||||
o.Data["json"] = err.Error()
|
||||
} else {
|
||||
o.Data["json"] = "update success!"
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the peer
|
||||
// @Param peerId path string true "The peerId you want to delete"
|
||||
// @Success 200 {string} delete success!
|
||||
// @Failure 403 peerId is empty
|
||||
// @router /:peerId [delete]
|
||||
func (o *PeerController) Delete() {
|
||||
peerId := o.Ctx.Input.Param(":peerId")
|
||||
models.Delete(peerId)
|
||||
o.Data["json"] = "delete success!"
|
||||
o.ServeJSON()
|
||||
}
|
||||
19
controllers/version.go
Normal file
19
controllers/version.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// VersionController operations for Version
|
||||
type VersionController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description get version
|
||||
// @Success 200
|
||||
// @router / [get]
|
||||
func (c *VersionController) GetAll() {
|
||||
c.Data["json"] = map[string]string{"version": "1"}
|
||||
c.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user