mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-08 05:52:10 +07:00
Add details node by ID endpoint
This commit is contained in:
parent
6e96a95ccd
commit
d04473a807
3 changed files with 51 additions and 0 deletions
|
@ -115,6 +115,41 @@ func Prober(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
func MoneroNode(c *fiber.Ctx) error {
|
||||
nodeId, err := c.ParamsInt("id", 0)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
||||
"status": "error",
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
if nodeId == 0 {
|
||||
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
||||
"status": "error",
|
||||
"message": "Invalid node id",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
moneroRepo := repo.NewMoneroRepo(database.GetDB())
|
||||
node, err := moneroRepo.Node(nodeId)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"status": "error",
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "ok",
|
||||
"message": "Success",
|
||||
"data": node,
|
||||
})
|
||||
}
|
||||
|
||||
func MoneroNodes(c *fiber.Ctx) error {
|
||||
moneroRepo := repo.NewMoneroRepo(database.GetDB())
|
||||
query := repo.MoneroQueryParams{
|
||||
|
|
|
@ -16,6 +16,7 @@ func V1Api(app *fiber.App) {
|
|||
v1.Post("/prober", Prober)
|
||||
v1.Get("/nodes", MoneroNodes)
|
||||
v1.Post("/nodes", AddNode)
|
||||
v1.Get("/nodes/id/:id", MoneroNode)
|
||||
v1.Get("/nodes/logs", ProbeLogs)
|
||||
v1.Get("/fees", NetFee)
|
||||
v1.Get("/countries", Countries)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -16,6 +17,7 @@ import (
|
|||
)
|
||||
|
||||
type MoneroRepository interface {
|
||||
Node(id int) (MoneroNode, error)
|
||||
Add(protocol string, host string, port uint) error
|
||||
Nodes(q MoneroQueryParams) (MoneroNodes, error)
|
||||
GiveJob(acceptTor int) (MoneroNode, error)
|
||||
|
@ -64,6 +66,19 @@ type MoneroNode struct {
|
|||
CorsCapable bool `json:"cors" db:"cors_capable"`
|
||||
}
|
||||
|
||||
func (repo *MoneroRepo) Node(id int) (MoneroNode, error) {
|
||||
node := MoneroNode{}
|
||||
err := repo.db.Get(&node, `SELECT * FROM tbl_node WHERE id = ?`, id)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
fmt.Println("WARN:", err)
|
||||
return node, errors.New("Can't get node information")
|
||||
}
|
||||
if err == sql.ErrNoRows {
|
||||
return node, errors.New("Node not found")
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
type MoneroNodes struct {
|
||||
TotalRows int `json:"total_rows"`
|
||||
RowsPerPage int `json:"rows_per_page"`
|
||||
|
|
Loading…
Reference in a new issue