Files
Crussell/backend/handlers/user/loyalty.go
T
popertotsandSisyphus ed9cb1489c fix: resolve golangci-lint violations (errcheck, unused, gosimple, ineffassign)
errcheck: add proper error handling with slog.Error for tx.Rollback, key generation, and s3/dav operations. Add nolint comments for intentionally discarded DB scan errors and HTTP write errors.
unused: remove dead code (svcRow type, processImage, nonDepositPaymentType, generateSecureCode, colorBold, nGreen, nRed)
gosimple S1021: merge var declaration with assignment in manage.go
ineffassign: remove dead assignments in settings.go, till.go, images.go

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-07-09 18:53:51 +01:00

35 lines
676 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
}
_ = json.NewEncoder(w).Encode(loyalty)
}