Files
Crussell/backend/handlers/user/loyalty.go
T
popertotsandSisyphus 3d0e2afc4c refactor(backend): migrate db.DB to db.Conn PoolProxy across all handlers
Replace direct *pgxpool.Pool usage with PoolProxy wrapper across the entire backend:

- db.DB renamed to db.Conn (*pgxpool.Pool -> *PoolProxy)
- JWT functions now accept context.Context instead of using context.Background()
- Handler DB calls route through PoolProxy for per-test transaction support
- Fixture/helper/testdb functions accept Querier interface for decoupling
- Query ordering fixed in bookings handlers: COUNT after data query to avoid pgx conn busy
- Time truncation fixed: time.Date instead of Truncate(24*time.Hour) for week start calc
- testmain_test.go files updated with SeedBaseline and NewPoolProxy

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-06-21 19:28:54 +01:00

35 lines
723 B
Go

package user
import (
"encoding/json"
"net/http"
"crussell/db"
"crussell/mw"
)
type LoyaltyResponse struct {
Stamps int `json:"stamps"`
ReferralCode string `json:"referralCode"`
}
// GET /api/user/loyalty
func GetLoyaltyHandler(w http.ResponseWriter, r *http.Request) {
userID, _ := mw.GetUserID(r.Context())
var loyalty LoyaltyResponse
err := db.Conn.QueryRow(r.Context(), `
SELECT loyalty_stamps, referral_code
FROM users
WHERE id = $1
`, userID).Scan(&loyalty.Stamps, &loyalty.ReferralCode)
if err != nil {
http.Error(w, "failed to get loyalty info", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(loyalty)
}