mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-12-23 03:59:25 +00:00
Add monero country list endpoint (backend)
This commit is contained in:
parent
1ceb00543b
commit
59b368d91e
3 changed files with 32 additions and 0 deletions
|
@ -180,6 +180,23 @@ func NetFee(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
func Countries(c *fiber.Ctx) error {
|
||||
moneroRepo := repo.NewMoneroRepo(database.GetDB())
|
||||
countries, err := moneroRepo.Countries()
|
||||
if err != nil {
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "error",
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "ok",
|
||||
"message": "Success",
|
||||
"data": countries,
|
||||
})
|
||||
}
|
||||
|
||||
func GiveJob(c *fiber.Ctx) error {
|
||||
acceptTor := c.QueryInt("accept_tor", 0)
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ func V1Api(app *fiber.App) {
|
|||
v1.Get("/nodes", MoneroNodes)
|
||||
v1.Post("/nodes", AddNode)
|
||||
v1.Get("/fees", NetFee)
|
||||
v1.Get("/countries", Countries)
|
||||
v1.Get("/job", CheckProber, GiveJob)
|
||||
v1.Post("/job", CheckProber, ProcessJob)
|
||||
v1.Get("/crons", Crons)
|
||||
|
|
|
@ -21,6 +21,7 @@ type MoneroRepository interface {
|
|||
GiveJob(acceptTor int) (MoneroNode, error)
|
||||
ProcessJob(report ProbeReport, proberId int64) error
|
||||
NetFee() []NetFee
|
||||
Countries() ([]MoneroCountries, error)
|
||||
}
|
||||
|
||||
type MoneroRepo struct {
|
||||
|
@ -331,3 +332,16 @@ func (repo *MoneroRepo) NetFee() []NetFee {
|
|||
|
||||
return netFees
|
||||
}
|
||||
|
||||
type MoneroCountries struct {
|
||||
TotalNodes int `json:"total_nodes" db:"total_nodes"`
|
||||
Cc string `json:"cc" db:"country"`
|
||||
Name string `json:"name" db:"country_name"`
|
||||
}
|
||||
|
||||
func (repo *MoneroRepo) Countries() ([]MoneroCountries, error) {
|
||||
countries := []MoneroCountries{}
|
||||
|
||||
err := repo.db.Select(&countries, `SELECT COUNT(id) AS total_nodes, country, country_name FROM tbl_node GROUP BY country ORDER BY country ASC`)
|
||||
return countries, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue