mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-08 05:52:10 +07:00
chore: Renamed MoneroQueryParams
The `MoneroQueryParams` renamed to `QueryNodes`. It become much more readable when calling it. Also added some comment in some functions.
This commit is contained in:
parent
dc1a3b2b92
commit
99a367f04b
2 changed files with 15 additions and 10 deletions
|
@ -45,7 +45,7 @@ func MoneroNode(c *fiber.Ctx) error {
|
||||||
|
|
||||||
func MoneroNodes(c *fiber.Ctx) error {
|
func MoneroNodes(c *fiber.Ctx) error {
|
||||||
moneroRepo := monero.NewMoneroRepo(database.GetDB())
|
moneroRepo := monero.NewMoneroRepo(database.GetDB())
|
||||||
query := monero.MoneroQueryParams{
|
query := monero.QueryNodes{
|
||||||
RowsPerPage: c.QueryInt("limit", 10),
|
RowsPerPage: c.QueryInt("limit", 10),
|
||||||
Page: c.QueryInt("page", 1),
|
Page: c.QueryInt("page", 1),
|
||||||
SortBy: c.Query("sort_by", "id"),
|
SortBy: c.Query("sort_by", "id"),
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
type MoneroRepository interface {
|
type MoneroRepository interface {
|
||||||
Node(id int) (Node, error)
|
Node(id int) (Node, error)
|
||||||
Add(protocol string, host string, port uint) error
|
Add(protocol string, host string, port uint) error
|
||||||
Nodes(q MoneroQueryParams) (Nodes, error)
|
Nodes(QueryNodes) (Nodes, error)
|
||||||
GiveJob(acceptTor int) (Node, error)
|
GiveJob(acceptTor int) (Node, error)
|
||||||
ProcessJob(report ProbeReport, proberId int64) error
|
ProcessJob(report ProbeReport, proberId int64) error
|
||||||
NetFee() []NetFee
|
NetFee() []NetFee
|
||||||
|
@ -36,6 +36,7 @@ func NewMoneroRepo(db *database.DB) MoneroRepository {
|
||||||
return &MoneroRepo{db}
|
return &MoneroRepo{db}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Node represents a single remote node
|
||||||
type Node struct {
|
type Node struct {
|
||||||
ID uint `json:"id,omitempty" db:"id"`
|
ID uint `json:"id,omitempty" db:"id"`
|
||||||
Hostname string `json:"hostname" db:"hostname"`
|
Hostname string `json:"hostname" db:"hostname"`
|
||||||
|
@ -67,6 +68,7 @@ type Node struct {
|
||||||
CORSCapable bool `json:"cors" db:"cors_capable"`
|
CORSCapable bool `json:"cors" db:"cors_capable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get node from database by id
|
||||||
func (repo *MoneroRepo) Node(id int) (Node, error) {
|
func (repo *MoneroRepo) Node(id int) (Node, error) {
|
||||||
var node Node
|
var node Node
|
||||||
err := repo.db.Get(&node, `SELECT * FROM tbl_node WHERE id = ?`, id)
|
err := repo.db.Get(&node, `SELECT * FROM tbl_node WHERE id = ?`, id)
|
||||||
|
@ -80,26 +82,29 @@ func (repo *MoneroRepo) Node(id int) (Node, error) {
|
||||||
return node, err
|
return node, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nodes represents a list of nodes
|
||||||
type Nodes struct {
|
type Nodes struct {
|
||||||
TotalRows int `json:"total_rows"`
|
TotalRows int `json:"total_rows"`
|
||||||
RowsPerPage int `json:"rows_per_page"`
|
RowsPerPage int `json:"rows_per_page"`
|
||||||
Items []*Node `json:"items"`
|
Items []*Node `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MoneroQueryParams struct {
|
type QueryNodes struct {
|
||||||
Host string
|
Host string
|
||||||
Nettype string
|
Nettype string
|
||||||
Protocol string
|
Protocol string
|
||||||
CC string // 2 letter country code
|
CC string // 2 letter country code
|
||||||
Status int
|
Status int
|
||||||
CORS int
|
CORS int
|
||||||
|
|
||||||
|
// pagination
|
||||||
RowsPerPage int
|
RowsPerPage int
|
||||||
Page int
|
Page int
|
||||||
SortBy string
|
SortBy string
|
||||||
SortDirection string
|
SortDirection string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *MoneroRepo) Nodes(q MoneroQueryParams) (Nodes, error) {
|
func (repo *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) {
|
||||||
queryParams := []interface{}{}
|
queryParams := []interface{}{}
|
||||||
whereQueries := []string{}
|
whereQueries := []string{}
|
||||||
where := ""
|
where := ""
|
||||||
|
|
Loading…
Reference in a new issue