Initial commit. Working login, example UI with prototype and demo, connections to DB and DAV, local and prod setups.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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.DB.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)
|
||||
}
|
||||
Reference in New Issue
Block a user