mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-04-15 01:41:56 +00:00
didn't realize gin supports net.Context. Change to support Context pattern!
This commit is contained in:
@@ -10,22 +10,21 @@ import (
|
||||
"github.com/drone/drone/router/middleware/context"
|
||||
"github.com/drone/drone/router/middleware/session"
|
||||
"github.com/drone/drone/shared/token"
|
||||
"github.com/drone/drone/store"
|
||||
)
|
||||
|
||||
func GetNodes(c *gin.Context) {
|
||||
db := context.Database(c)
|
||||
nodes, err := model.GetNodeList(db)
|
||||
nodes, err := store.GetNodeList(c)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
c.String(400, err.Error())
|
||||
} else {
|
||||
c.IndentedJSON(http.StatusOK, nodes)
|
||||
c.JSON(200, nodes)
|
||||
}
|
||||
}
|
||||
|
||||
func ShowNodes(c *gin.Context) {
|
||||
db := context.Database(c)
|
||||
user := session.User(c)
|
||||
nodes, _ := model.GetNodeList(db)
|
||||
nodes, _ := store.GetNodeList(c)
|
||||
token, _ := token.New(token.CsrfToken, user.Login).Sign(user.Hash)
|
||||
c.HTML(http.StatusOK, "nodes.html", gin.H{"User": user, "Nodes": nodes, "Csrf": token})
|
||||
}
|
||||
@@ -35,7 +34,6 @@ func GetNode(c *gin.Context) {
|
||||
}
|
||||
|
||||
func PostNode(c *gin.Context) {
|
||||
db := context.Database(c)
|
||||
engine := context.Engine(c)
|
||||
|
||||
in := struct {
|
||||
@@ -64,7 +62,7 @@ func PostNode(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = model.InsertNode(db, node)
|
||||
err = store.CreateNode(c, node)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -74,16 +72,15 @@ func PostNode(c *gin.Context) {
|
||||
}
|
||||
|
||||
func DeleteNode(c *gin.Context) {
|
||||
db := context.Database(c)
|
||||
engine := context.Engine(c)
|
||||
|
||||
id, _ := strconv.Atoi(c.Param("node"))
|
||||
node, err := model.GetNode(db, int64(id))
|
||||
node, err := store.GetNode(c, int64(id))
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = model.DeleteNode(db, node)
|
||||
err = store.DeleteNode(c, node)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user