Rename MoneroLogQueryParams to QueryLogs

The reason is same with commits reference 99a367f04b
This commit is contained in:
Cristian Ditaputratama 2024-05-27 06:38:11 +07:00
parent 6b5225758e
commit ab82985bdf
Signed by: ditatompel
GPG key ID: 31D3D06D77950979
2 changed files with 25 additions and 22 deletions

View file

@ -75,7 +75,7 @@ func MoneroNodes(c *fiber.Ctx) error {
func ProbeLogs(c *fiber.Ctx) error { func ProbeLogs(c *fiber.Ctx) error {
moneroRepo := monero.New() moneroRepo := monero.New()
query := monero.MoneroLogQueryParams{ query := monero.QueryLogs{
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"),

View file

@ -25,7 +25,7 @@ type MoneroRepository interface {
ProcessJob(report ProbeReport, proberId int64) error ProcessJob(report ProbeReport, proberId int64) error
NetFee() []NetFee NetFee() []NetFee
Countries() ([]Countries, error) Countries() ([]Countries, error)
Logs(q MoneroLogQueryParams) (MoneroNodeFetchLogs, error) Logs(QueryLogs) (FetchLogs, error)
} }
type MoneroRepo struct { type MoneroRepo struct {
@ -89,6 +89,7 @@ type Nodes struct {
Items []*Node `json:"items"` Items []*Node `json:"items"`
} }
// QueryNodes represents database query parameters
type QueryNodes struct { type QueryNodes struct {
Host string Host string
Nettype string Nettype string
@ -104,6 +105,7 @@ type QueryNodes struct {
SortDirection string SortDirection string
} }
// Get nodes from database
func (repo *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) { func (repo *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) {
queryParams := []interface{}{} queryParams := []interface{}{}
whereQueries := []string{} whereQueries := []string{}
@ -264,7 +266,7 @@ func (repo *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) {
return nodes, nil return nodes, nil
} }
type MoneroLogQueryParams struct { type QueryLogs struct {
NodeID int // 0 fpr all, >0 for specific node NodeID int // 0 fpr all, >0 for specific node
WorkerID int // 0 for all, >0 for specific worker WorkerID int // 0 for all, >0 for specific worker
Status int // -1 for all, 0 for failed, 1 for success Status int // -1 for all, 0 for failed, 1 for success
@ -276,7 +278,7 @@ type MoneroLogQueryParams struct {
SortDirection string SortDirection string
} }
type ProbeLog struct { type FetchLog struct {
ID int `db:"id" json:"id,omitempty"` ID int `db:"id" json:"id,omitempty"`
NodeID int `db:"node_id" json:"node_id"` NodeID int `db:"node_id" json:"node_id"`
ProberID int `db:"prober_id" json:"prober_id"` ProberID int `db:"prober_id" json:"prober_id"`
@ -291,13 +293,14 @@ type ProbeLog struct {
FetchRuntime float64 `db:"fetch_runtime" json:"fetch_runtime"` FetchRuntime float64 `db:"fetch_runtime" json:"fetch_runtime"`
} }
type MoneroNodeFetchLogs struct { type FetchLogs struct {
TotalRows int `json:"total_rows"` TotalRows int `json:"total_rows"`
RowsPerPage int `json:"rows_per_page"` 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{}{} queryParams := []interface{}{}
whereQueries := []string{} whereQueries := []string{}
where := "" where := ""
@ -319,7 +322,7 @@ func (repo *MoneroRepo) Logs(q MoneroLogQueryParams) (MoneroNodeFetchLogs, error
where = "WHERE " + strings.Join(whereQueries, " AND ") where = "WHERE " + strings.Join(whereQueries, " AND ")
} }
fetchLogs := MoneroNodeFetchLogs{} var fetchLogs FetchLogs
queryTotalRows := fmt.Sprintf("SELECT COUNT(id) FROM tbl_probe_log %s", where) queryTotalRows := fmt.Sprintf("SELECT COUNT(id) FROM tbl_probe_log %s", where)
err := repo.db.QueryRow(queryTotalRows, queryParams...).Scan(&fetchLogs.TotalRows) 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 fetchLogs.RowsPerPage = q.RowsPerPage
for row.Next() { for row.Next() {
probeLog := ProbeLog{} var fl FetchLog
err = row.Scan( err = row.Scan(
&probeLog.ID, &fl.ID,
&probeLog.NodeID, &fl.NodeID,
&probeLog.ProberID, &fl.ProberID,
&probeLog.Status, &fl.Status,
&probeLog.Height, &fl.Height,
&probeLog.AdjustedTime, &fl.AdjustedTime,
&probeLog.DatabaseSize, &fl.DatabaseSize,
&probeLog.Difficulty, &fl.Difficulty,
&probeLog.EstimateFee, &fl.EstimateFee,
&probeLog.DateChecked, &fl.DateChecked,
&probeLog.FailedReason, &fl.FailedReason,
&probeLog.FetchRuntime) &fl.FetchRuntime)
if err != nil { if err != nil {
return fetchLogs, err return fetchLogs, err
} }
fetchLogs.Items = append(fetchLogs.Items, &probeLog) fetchLogs.Items = append(fetchLogs.Items, &fl)
} }
return fetchLogs, nil return fetchLogs, nil