Apply clock.Now() migration, transaction wrapping, and minor refactors across admin, scheduling, today, user, auth handler, notifications, webhooks, services, portfolio, ratelimit, testutils, and main.go. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
35 lines
672 B
Go
35 lines
672 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)
|
|
}
|