Add monero country list endpoint (backend)

This commit is contained in:
ditatompel 2024-05-06 13:35:15 +07:00
parent 1ceb00543b
commit 59b368d91e
No known key found for this signature in database
GPG key ID: 31D3D06D77950979
3 changed files with 32 additions and 0 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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
}