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:
ditatompel 2024-05-27 05:13:03 +07:00
parent dc1a3b2b92
commit 99a367f04b
No known key found for this signature in database
GPG key ID: 31D3D06D77950979
2 changed files with 15 additions and 10 deletions

View file

@ -45,7 +45,7 @@ func MoneroNode(c *fiber.Ctx) error {
func MoneroNodes(c *fiber.Ctx) error {
moneroRepo := monero.NewMoneroRepo(database.GetDB())
query := monero.MoneroQueryParams{
query := monero.QueryNodes{
RowsPerPage: c.QueryInt("limit", 10),
Page: c.QueryInt("page", 1),
SortBy: c.Query("sort_by", "id"),

View file

@ -20,7 +20,7 @@ import (
type MoneroRepository interface {
Node(id int) (Node, error)
Add(protocol string, host string, port uint) error
Nodes(q MoneroQueryParams) (Nodes, error)
Nodes(QueryNodes) (Nodes, error)
GiveJob(acceptTor int) (Node, error)
ProcessJob(report ProbeReport, proberId int64) error
NetFee() []NetFee
@ -36,6 +36,7 @@ func NewMoneroRepo(db *database.DB) MoneroRepository {
return &MoneroRepo{db}
}
// Node represents a single remote node
type Node struct {
ID uint `json:"id,omitempty" db:"id"`
Hostname string `json:"hostname" db:"hostname"`
@ -67,6 +68,7 @@ type Node struct {
CORSCapable bool `json:"cors" db:"cors_capable"`
}
// Get node from database by id
func (repo *MoneroRepo) Node(id int) (Node, error) {
var node Node
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
}
// Nodes represents a list of nodes
type Nodes struct {
TotalRows int `json:"total_rows"`
RowsPerPage int `json:"rows_per_page"`
Items []*Node `json:"items"`
}
type MoneroQueryParams struct {
type QueryNodes struct {
Host string
Nettype string
Protocol string
CC string // 2 letter country code
Status int
CORS int
// pagination
RowsPerPage int
Page int
SortBy string
SortDirection string
}
func (repo *MoneroRepo) Nodes(q MoneroQueryParams) (Nodes, error) {
func (repo *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) {
queryParams := []interface{}{}
whereQueries := []string{}
where := ""