From 673500005069d2f571a9831d3c73b912c5ac8075 Mon Sep 17 00:00:00 2001 From: KS Jannette Date: Sun, 1 Mar 2026 19:06:32 -0500 Subject: [PATCH] webhook configs for users, changes to system --- backend-go/internal/database/postgres.go | 15 ++++++--------- backend-go/internal/domain/types.go | 12 ------------ backend-go/internal/firebase/admin.go | 3 --- backend-go/internal/handlers/address.go | 5 +---- backend-go/internal/handlers/alert_rule.go | 4 ---- 5 files changed, 7 insertions(+), 32 deletions(-) diff --git a/backend-go/internal/database/postgres.go b/backend-go/internal/database/postgres.go index d9832a2..1fc7afa 100644 --- a/backend-go/internal/database/postgres.go +++ b/backend-go/internal/database/postgres.go @@ -1,4 +1,3 @@ -// Package database manages PostgreSQL connection pools. package database import ( @@ -11,21 +10,21 @@ import ( ) const ( - // maxConnIdleSeconds is the maximum idle time for a connection. + maxConnIdleSeconds = 30 - // maxConnLifetimeMinutes is the maximum lifetime for a connection. + maxConnLifetimeMinutes = 5 - // connectTimeoutSeconds is the timeout for initial connection. + connectTimeoutSeconds = 10 - // maxConns is the maximum number of connections in the pool. + maxConns = 20 - // minConns is the minimum number of connections in the pool. + minConns = 2 ) var pool *pgxpool.Pool //nolint:gochecknoglobals -// Connect establishes a PostgreSQL connection pool using the given DSN. +// establishPostgreSQL connection pool using the given DSN. func Connect(dsn string) (*pgxpool.Pool, error) { cfg, err := pgxpool.ParseConfig(dsn) if err != nil { @@ -57,12 +56,10 @@ func Connect(dsn string) (*pgxpool.Pool, error) { return p, nil } -// Pool returns the global connection pool. func Pool() *pgxpool.Pool { return pool } -// Close closes the global connection pool. func Close() { if pool != nil { pool.Close() diff --git a/backend-go/internal/domain/types.go b/backend-go/internal/domain/types.go index 0aa65f7..e01aa64 100644 --- a/backend-go/internal/domain/types.go +++ b/backend-go/internal/domain/types.go @@ -1,9 +1,7 @@ -// Package domain defines core domain types shared across the application. package domain import "time" -// Address represents a tracked Ethereum address. type Address struct { ID int `json:"id"` UserID string `json:"user_id"` //nolint:tagliatelle @@ -12,13 +10,10 @@ type Address struct { CreatedAt time.Time `json:"created_at"` //nolint:tagliatelle } -// AlertType identifies the kind of alert rule. type AlertType string -// String implements fmt.Stringer. func (a AlertType) String() string { return string(a) } -// Alert type constants define the supported alert triggers. const ( AlertIncomingTx AlertType = "incoming_tx" AlertOutgoingTx AlertType = "outgoing_tx" @@ -26,7 +21,6 @@ const ( AlertBalanceBelow AlertType = "balance_below" ) -// ValidAlertTypes lists all alert types accepted by the API. var ValidAlertTypes = []AlertType{ //nolint:gochecknoglobals AlertIncomingTx, AlertOutgoingTx, @@ -62,7 +56,6 @@ func IsThresholdRequired(t AlertType) bool { return false } -// AlertRule represents a user-defined alert rule for an address. type AlertRule struct { ID int `json:"id"` AddressID int `json:"address_id"` //nolint:tagliatelle @@ -72,7 +65,6 @@ type AlertRule struct { CreatedAt time.Time `json:"created_at"` //nolint:tagliatelle } -// AlertEvent represents a fired alert event stored for history. type AlertEvent struct { ID int `json:"id"` AlertRuleID int `json:"alert_rule_id"` //nolint:tagliatelle @@ -82,7 +74,6 @@ type AlertEvent struct { Timestamp time.Time `json:"timestamp"` } -// AddressCheckpoint tracks the last block checked for an address. type AddressCheckpoint struct { AddressID int `json:"address_id"` //nolint:tagliatelle LastCheckedBlock int `json:"last_checked_block"` //nolint:tagliatelle @@ -121,19 +112,16 @@ type NormalizedTx struct { BlockTimestamp int64 `json:"block_timestamp"` //nolint:tagliatelle } -// Direction indicates whether a transaction is incoming or outgoing. type Direction string // String implements fmt.Stringer. func (d Direction) String() string { return string(d) } -// Direction constants indicate the flow of a transaction relative to a watched address. const ( DirectionIncoming Direction = "incoming" DirectionOutgoing Direction = "outgoing" ) -// ObservedTx is a NormalizedTx enriched with address and direction context. type ObservedTx struct { NormalizedTx AddressID int `json:"address_id"` //nolint:tagliatelle diff --git a/backend-go/internal/firebase/admin.go b/backend-go/internal/firebase/admin.go index 8997769..499ca95 100644 --- a/backend-go/internal/firebase/admin.go +++ b/backend-go/internal/firebase/admin.go @@ -1,4 +1,3 @@ -// Package firebase provides Firebase authentication integration. package firebase import ( @@ -17,7 +16,6 @@ var ( //nolint:gochecknoglobals errInit error //nolint:gochecknoglobals ) -// Init initializes the Firebase app and auth client using the given project ID. func Init(projectID string) error { once.Do(func() { ctx := context.Background() @@ -48,7 +46,6 @@ func Init(projectID string) error { return errInit } -// Auth returns the initialized Firebase auth client. func Auth() *auth.Client { return authClient } diff --git a/backend-go/internal/handlers/address.go b/backend-go/internal/handlers/address.go index 8d6cf4c..f907963 100644 --- a/backend-go/internal/handlers/address.go +++ b/backend-go/internal/handlers/address.go @@ -15,17 +15,14 @@ import ( var ethAddressRe = regexp.MustCompile(`^0x[a-fA-F0-9]{40}$`) -// AddressHandler handles HTTP requests for address management. type AddressHandler struct { addresses *models.AddressModel } -// NewAddressHandler creates a new AddressHandler. func NewAddressHandler(addresses *models.AddressModel) *AddressHandler { return &AddressHandler{addresses: addresses} } -// Create handles POST requests to add a new tracked address. func (h *AddressHandler) Create(w http.ResponseWriter, r *http.Request) { userID := middleware.GetUserID(r.Context()) @@ -92,7 +89,7 @@ func (h *AddressHandler) List(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, addresses) } -// UpdateLabel handles PATCH requests to update an address label. +// handles PATCH requests to update an address label. func (h *AddressHandler) UpdateLabel(w http.ResponseWriter, r *http.Request) { userID := middleware.GetUserID(r.Context()) addressID, ok := parseIntParam(r.PathValue("addressId")) diff --git a/backend-go/internal/handlers/alert_rule.go b/backend-go/internal/handlers/alert_rule.go index eb2888b..d726bf3 100644 --- a/backend-go/internal/handlers/alert_rule.go +++ b/backend-go/internal/handlers/alert_rule.go @@ -14,21 +14,17 @@ import ( "github.com/kjannette/koin-ping/backend-go/internal/models" ) -// errThresholdFormat is returned when the threshold JSON cannot be decoded. var errThresholdFormat = errors.New("unsupported threshold format") -// AlertRuleHandler handles HTTP requests for alert rule management. type AlertRuleHandler struct { alertRules *models.AlertRuleModel addresses *models.AddressModel } -// NewAlertRuleHandler creates a new AlertRuleHandler. func NewAlertRuleHandler(alertRules *models.AlertRuleModel, addresses *models.AddressModel) *AlertRuleHandler { return &AlertRuleHandler{alertRules: alertRules, addresses: addresses} } -// Create handles POST requests to create a new alert rule for an address. func (h *AlertRuleHandler) Create(w http.ResponseWriter, r *http.Request) { userID := middleware.GetUserID(r.Context()) addressID, ok := parseIntParam(r.PathValue("addressId"))