add control for partner ship

This commit is contained in:
mr 2024-10-15 16:55:29 +02:00
parent a6f546ceee
commit bafadee9d5
7 changed files with 190 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/models/peer"
beego "github.com/beego/beego/v2/server/web"
)
@ -59,3 +60,42 @@ func (o *PeerController) Get() {
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.PEER), id)
o.ServeJSON()
}
// @Title Partner
// @Description add partner peer by peerid
// @Param id path string true "the peer id you want to partner"
// @Success 200 {peer} models.peer
// @router /:id/partner [post]
func (o *PeerController) Partner() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.PEER), map[string]interface{}{
"state": peer.PARTNER,
}, id)
o.ServeJSON()
}
// @Title Blacklist
// @Description add blacklist peer by peerid
// @Param id path string true "the peer id you want to blacklist"
// @Success 200 {peer} models.peer
// @router /:id/blacklist [post]
func (o *PeerController) Blacklist() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.PEER), map[string]interface{}{
"state": peer.BLACKLIST,
}, id)
o.ServeJSON()
}
// @Title DeleteState
// @Description delete state peer by peerid
// @Param id path string true "the peer id you want to delete state"
// @Success 200 {peer} models.peer
// @router /:id/undo_state [post]
func (o *PeerController) DeleteState() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.PEER), map[string]interface{}{
"state": peer.NONE,
}, id)
o.ServeJSON()
}

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.4
require (
cloud.o-forge.io/core/oc-lib v0.0.0-20241015083538-9f5e6d60185a
cloud.o-forge.io/core/oc-lib v0.0.0-20241015143718-73602b6c3dad
github.com/beego/beego/v2 v2.3.1
github.com/smartystreets/goconvey v1.7.2
)

2
go.sum
View File

@ -6,6 +6,8 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20241015082307-62705cc9b93e h1:auncAXo/J15Dc
cloud.o-forge.io/core/oc-lib v0.0.0-20241015082307-62705cc9b93e/go.mod h1:t+zpCTVKVdHH/BImwtMYY2QIWLMXKgY4n/JhFm3Vpu8=
cloud.o-forge.io/core/oc-lib v0.0.0-20241015083538-9f5e6d60185a h1:2mBMc36WKh1/Dpomktx9dVXGxK0agFr7RdgvHTtyn2w=
cloud.o-forge.io/core/oc-lib v0.0.0-20241015083538-9f5e6d60185a/go.mod h1:t+zpCTVKVdHH/BImwtMYY2QIWLMXKgY4n/JhFm3Vpu8=
cloud.o-forge.io/core/oc-lib v0.0.0-20241015143718-73602b6c3dad h1:XkuDc4v2XpTS+w6N9ovbzJdXs/78y2sH36tkQf4LW+E=
cloud.o-forge.io/core/oc-lib v0.0.0-20241015143718-73602b6c3dad/go.mod h1:t+zpCTVKVdHH/BImwtMYY2QIWLMXKgY4n/JhFm3Vpu8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I=
github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo=

BIN
oc-peer

Binary file not shown.

View File

@ -34,6 +34,33 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-peer/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peer/controllers:PeerController"],
beego.ControllerComments{
Method: "Blacklist",
Router: `/:id/blacklist`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-peer/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peer/controllers:PeerController"],
beego.ControllerComments{
Method: "Partner",
Router: `/:id/partner`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-peer/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peer/controllers:PeerController"],
beego.ControllerComments{
Method: "DeleteState",
Router: `/:id/undo_state`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-peer/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peer/controllers:PeerController"],
beego.ControllerComments{
Method: "Search",

View File

@ -145,6 +145,75 @@
}
}
}
},
"/{id}/blacklist": {
"post": {
"tags": [
"oc-peer/controllersPeerController"
],
"description": "add blacklist peer by peerid\n\u003cbr\u003e",
"operationId": "PeerController.Blacklist",
"parameters": [
{
"in": "path",
"name": "id",
"description": "the peer id you want to blacklist",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "{peer} models.peer"
}
}
}
},
"/{id}/partner": {
"post": {
"tags": [
"oc-peer/controllersPeerController"
],
"description": "add partner peer by peerid\n\u003cbr\u003e",
"operationId": "PeerController.Partner",
"parameters": [
{
"in": "path",
"name": "id",
"description": "the peer id you want to partner",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "{peer} models.peer"
}
}
}
},
"/{id}/undo_state": {
"post": {
"tags": [
"oc-peer/controllersPeerController"
],
"description": "delete state peer by peerid\n\u003cbr\u003e",
"operationId": "PeerController.DeleteState",
"parameters": [
{
"in": "path",
"name": "id",
"description": "the peer id you want to delete state",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "{peer} models.peer"
}
}
}
}
},
"definitions": {

View File

@ -64,6 +64,57 @@ paths:
description: ""
schema:
$ref: '#/definitions/models.peer'
/{id}/blacklist:
post:
tags:
- oc-peer/controllersPeerController
description: |-
add blacklist peer by peerid
<br>
operationId: PeerController.Blacklist
parameters:
- in: path
name: id
description: the peer id you want to blacklist
required: true
type: string
responses:
"200":
description: '{peer} models.peer'
/{id}/partner:
post:
tags:
- oc-peer/controllersPeerController
description: |-
add partner peer by peerid
<br>
operationId: PeerController.Partner
parameters:
- in: path
name: id
description: the peer id you want to partner
required: true
type: string
responses:
"200":
description: '{peer} models.peer'
/{id}/undo_state:
post:
tags:
- oc-peer/controllersPeerController
description: |-
delete state peer by peerid
<br>
operationId: PeerController.DeleteState
parameters:
- in: path
name: id
description: the peer id you want to delete state
required: true
type: string
responses:
"200":
description: '{peer} models.peer'
/search/{search}:
get:
tags: