Portfolio frontend, various fixes

This commit is contained in:
2025-11-28 18:03:06 +00:00
parent c1548c503f
commit 7bc2129422
7 changed files with 501 additions and 336 deletions
+21 -19
View File
@@ -20,16 +20,17 @@ import (
var titleCaser = cases.Title(language.English)
type UserProfile struct {
ID string `json:"id"`
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Phone *string `json:"phone,omitempty"`
DateOfBirth *string `json:"dateOfBirth,omitempty"`
Role string `json:"role"`
LoyaltyStamps int `json:"loyaltyStamps"`
ReferralCode string `json:"referralCode"`
ProfilePicURL *string `json:"profilePicUrl,omitempty"`
ID string `json:"id"`
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Phone *string `json:"phone,omitempty"`
DateOfBirth *string `json:"dateOfBirth,omitempty"`
Role string `json:"role"`
LoyaltyStamps int `json:"loyaltyStamps"`
ReferralCode string `json:"referralCode"`
ReferralCodeUses int `json:"referralCodeUses"`
ProfilePicURL *string `json:"profilePicUrl,omitempty"`
}
type UpdateProfileRequest struct {
@@ -48,16 +49,17 @@ func GetProfileHandler(w http.ResponseWriter, r *http.Request) {
var user UserProfile
err := db.DB.QueryRow(r.Context(), `
SELECT
id, email, n_first_name, n_last_name, phone,
date_of_birth::text, account_role, loyalty_stamps,
referral_code, profile_pic_url
FROM users
WHERE id = $1
`, userID).Scan(
SELECT
id, email, n_first_name, n_last_name, phone,
date_of_birth::text, account_role, loyalty_stamps,
referral_code, profile_pic_url,
(SELECT COUNT(*) FROM user_referrals WHERE referrer_id = users.id AND claimed_booking_id IS NOT NULL) AS referral_code_uses
FROM users
WHERE id = $1
`, userID).Scan(
&user.ID, &user.Email, &user.FirstName, &user.LastName,
&user.Phone, &user.DateOfBirth, &user.Role,
&user.LoyaltyStamps, &user.ReferralCode, &user.ProfilePicURL,
&user.LoyaltyStamps, &user.ReferralCode, &user.ProfilePicURL, &user.ReferralCodeUses,
)
if err != nil {
@@ -187,7 +189,7 @@ func UpdateProfileHandler(w http.ResponseWriter, r *http.Request) {
// Update DB
_, err = db.DB.Exec(r.Context(), `
UPDATE users
UPDATE users
SET n_first_name = $1, n_last_name = $2, phone = $3, updated_at = NOW()
WHERE id = $4
`, req.FirstName, req.LastName, req.Phone, userID)