From ab82985bdf6b4ed5670ddd61470525499403f408 Mon Sep 17 00:00:00 2001 From: ditatompel Date: Mon, 27 May 2024 06:38:11 +0700 Subject: [PATCH] Rename `MoneroLogQueryParams` to `QueryLogs` The reason is same with commits reference 99a367f04b --- handler/response.go | 2 +- internal/monero/monero.go | 45 +++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/handler/response.go b/handler/response.go index 6179cbf..4ea209d 100644 --- a/handler/response.go +++ b/handler/response.go @@ -75,7 +75,7 @@ func MoneroNodes(c *fiber.Ctx) error { func ProbeLogs(c *fiber.Ctx) error { moneroRepo := monero.New() - query := monero.MoneroLogQueryParams{ + query := monero.QueryLogs{ RowsPerPage: c.QueryInt("limit", 10), Page: c.QueryInt("page", 1), SortBy: c.Query("sort_by", "id"), diff --git a/internal/monero/monero.go b/internal/monero/monero.go index bfb9547..29f591b 100644 --- a/internal/monero/monero.go +++ b/internal/monero/monero.go @@ -25,7 +25,7 @@ type MoneroRepository interface { ProcessJob(report ProbeReport, proberId int64) error NetFee() []NetFee Countries() ([]Countries, error) - Logs(q MoneroLogQueryParams) (MoneroNodeFetchLogs, error) + Logs(QueryLogs) (FetchLogs, error) } type MoneroRepo struct { @@ -89,6 +89,7 @@ type Nodes struct { Items []*Node `json:"items"` } +// QueryNodes represents database query parameters type QueryNodes struct { Host string Nettype string @@ -104,6 +105,7 @@ type QueryNodes struct { SortDirection string } +// Get nodes from database func (repo *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) { queryParams := []interface{}{} whereQueries := []string{} @@ -264,7 +266,7 @@ func (repo *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) { return nodes, nil } -type MoneroLogQueryParams struct { +type QueryLogs struct { NodeID int // 0 fpr all, >0 for specific node WorkerID int // 0 for all, >0 for specific worker Status int // -1 for all, 0 for failed, 1 for success @@ -276,7 +278,7 @@ type MoneroLogQueryParams struct { SortDirection string } -type ProbeLog struct { +type FetchLog struct { ID int `db:"id" json:"id,omitempty"` NodeID int `db:"node_id" json:"node_id"` ProberID int `db:"prober_id" json:"prober_id"` @@ -291,13 +293,14 @@ type ProbeLog struct { FetchRuntime float64 `db:"fetch_runtime" json:"fetch_runtime"` } -type MoneroNodeFetchLogs struct { +type FetchLogs struct { TotalRows int `json:"total_rows"` RowsPerPage int `json:"rows_per_page"` - Items []*ProbeLog `json:"items"` + Items []*FetchLog `json:"items"` } -func (repo *MoneroRepo) Logs(q MoneroLogQueryParams) (MoneroNodeFetchLogs, error) { +// Logs returns list of fetched log result for given query +func (repo *MoneroRepo) Logs(q QueryLogs) (FetchLogs, error) { queryParams := []interface{}{} whereQueries := []string{} where := "" @@ -319,7 +322,7 @@ func (repo *MoneroRepo) Logs(q MoneroLogQueryParams) (MoneroNodeFetchLogs, error where = "WHERE " + strings.Join(whereQueries, " AND ") } - fetchLogs := MoneroNodeFetchLogs{} + var fetchLogs FetchLogs queryTotalRows := fmt.Sprintf("SELECT COUNT(id) FROM tbl_probe_log %s", where) err := repo.db.QueryRow(queryTotalRows, queryParams...).Scan(&fetchLogs.TotalRows) @@ -370,25 +373,25 @@ func (repo *MoneroRepo) Logs(q MoneroLogQueryParams) (MoneroNodeFetchLogs, error fetchLogs.RowsPerPage = q.RowsPerPage for row.Next() { - probeLog := ProbeLog{} + var fl FetchLog err = row.Scan( - &probeLog.ID, - &probeLog.NodeID, - &probeLog.ProberID, - &probeLog.Status, - &probeLog.Height, - &probeLog.AdjustedTime, - &probeLog.DatabaseSize, - &probeLog.Difficulty, - &probeLog.EstimateFee, - &probeLog.DateChecked, - &probeLog.FailedReason, - &probeLog.FetchRuntime) + &fl.ID, + &fl.NodeID, + &fl.ProberID, + &fl.Status, + &fl.Height, + &fl.AdjustedTime, + &fl.DatabaseSize, + &fl.Difficulty, + &fl.EstimateFee, + &fl.DateChecked, + &fl.FailedReason, + &fl.FetchRuntime) if err != nil { return fetchLogs, err } - fetchLogs.Items = append(fetchLogs.Items, &probeLog) + fetchLogs.Items = append(fetchLogs.Items, &fl) } return fetchLogs, nil