From f91cf5dc09a6aacb490213255fd8285b8ef5eefe Mon Sep 17 00:00:00 2001 From: RahmanTaghizade <99033051+RahmanTaghizade@users.noreply.github.com> Date: Wed, 20 Nov 2024 22:43:00 +0400 Subject: [PATCH] Remove deposit functionality from user API --- backend/cmd/main.go | 1 - backend/pkg/api/handlers.go | 46 ------------------------------------- frontend/profile.html | 35 ++-------------------------- frontend/styles/profile.css | 5 ++-- 4 files changed, 4 insertions(+), 83 deletions(-) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 1e3c530..688e8d4 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -38,7 +38,6 @@ func main() { r.Group(func(r chi.Router) { r.Use(middleware.JWTAuth) r.Get("/api/user", api.GetUser) - r.Post("/api/user/deposit", api.Deposit) r.Get("/api/leaderboard", api.GetLeaderboard) r.Post("/api/roulette", api.PlaceBet) }) diff --git a/backend/pkg/api/handlers.go b/backend/pkg/api/handlers.go index 622efde..7e0c5e0 100644 --- a/backend/pkg/api/handlers.go +++ b/backend/pkg/api/handlers.go @@ -29,10 +29,6 @@ type RegisterRequest struct { Avatar string `json:"avatar,omitempty"` } -type DepositRequest struct { - Amount int `json:"amount"` -} - type BetRequest struct { BetAmount int `json:"bet_amount"` BetType string `json:"bet_type"` @@ -146,48 +142,6 @@ func Register(w http.ResponseWriter, r *http.Request) { }) } -func Deposit(w http.ResponseWriter, r *http.Request) { - username, ok := r.Context().Value(middleware.UsernameKey).(string) - if !ok || username == "" { - http.Error(w, "Unauthenticated user", http.StatusUnauthorized) - return - } - - var deposit DepositRequest - err := json.NewDecoder(r.Body).Decode(&deposit) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - if deposit.Amount <= 0 { - http.Error(w, "Invalid deposit amount", http.StatusBadRequest) - return - } - - var user models.User - err = db.DB.Where("username = ?", username).First(&user).Error - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - http.Error(w, "User not found", http.StatusNotFound) - return - } else { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } else { - user.Balance += deposit.Amount - if err := db.DB.Save(&user).Error; err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - json.NewEncoder(w).Encode(user) -} - func PlaceBet(w http.ResponseWriter, r *http.Request) { username, ok := r.Context().Value(middleware.UsernameKey).(string) if !ok || username == "" { diff --git a/frontend/profile.html b/frontend/profile.html index f5ed5df..14d6ebb 100644 --- a/frontend/profile.html +++ b/frontend/profile.html @@ -53,7 +53,8 @@
User Avatar
-

Username

+

Username

+

Email

@@ -63,12 +64,6 @@ Soul Icon
-
- - - -
@@ -99,32 +94,6 @@ }) .then(data => this.user = data); }, - deposit() { - const depositAmount = parseInt(this.depositAmount); - fetch('/api/user/deposit', { - method: 'POST', - headers: { - 'Authorization': `Bearer ${this.authToken}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ amount: depositAmount }) - }) - .then(response => { - if (response.status === 401) { - alert('Invalid auth token. Please log in again.'); - window.location.href = '/register'; - } - return response.json(); - }) - .then(data => { - if (data.balance) { - this.user.balance = data.balance; - } else { - alert('Deposit failed!'); - console.error(data); - } - }); - }, logout() { localStorage.removeItem('authToken'); window.location.href = '/register.html'; diff --git a/frontend/styles/profile.css b/frontend/styles/profile.css index b54b850..720e4d8 100644 --- a/frontend/styles/profile.css +++ b/frontend/styles/profile.css @@ -12,10 +12,9 @@ justify-content: space-between; align-items: center; gap: 40px; - width: 80%; margin-top: 20px; padding: 20px; - background-color: #FFF0B3; + background-color: #ffda46; border-radius: 12px; box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.2); } @@ -36,7 +35,7 @@ border: 4px solid #3F1B12; } -.big-username { +.user-text { font-size: 20px; font-weight: bold; color: #3F1B12;