diff --git a/api/ban.go b/api/ban.go index e3deecd..125eab8 100644 --- a/api/ban.go +++ b/api/ban.go @@ -16,12 +16,9 @@ func HandleBan(w http.ResponseWriter, r *http.Request) { var err string var statusCode int - switch r.Method { - case http.MethodHead: - statusCode = http.StatusOK - case http.MethodPost: + if r.Method == http.MethodPost { user, success, err, statusCode = handleBanImpl(w, r) - default: + } else { err = "Incorrect request. POST or HEAD only." statusCode = http.StatusBadRequest } diff --git a/api/clear.go b/api/clear.go index 1d4b97a..77d8024 100644 --- a/api/clear.go +++ b/api/clear.go @@ -14,13 +14,10 @@ func HandleClear(w http.ResponseWriter, r *http.Request) { var err string var statusCode int - switch r.Method { - case http.MethodHead: - statusCode = http.StatusOK - case http.MethodPost: + if r.Method == http.MethodPost { user, success, err, statusCode = handleClearImpl(w, r) - default: - err = "Incorrect request. POST or HEAD only." + } else { + err = "Incorrect request. POST only." statusCode = http.StatusBadRequest } diff --git a/api/kick.go b/api/kick.go index 84cdf59..64d1e72 100644 --- a/api/kick.go +++ b/api/kick.go @@ -15,12 +15,9 @@ func HandleKick(w http.ResponseWriter, r *http.Request) { var err string var statusCode int - switch r.Method { - case http.MethodHead: - statusCode = http.StatusOK - case http.MethodPost: + if r.Method == http.MethodPost { user, success, err, statusCode = handleKickImpl(w, r) - default: + } else { err = "Incorrect request. POST or HEAD only." statusCode = http.StatusBadRequest } diff --git a/api/motd.go b/api/motd.go index 8170d3c..025b819 100644 --- a/api/motd.go +++ b/api/motd.go @@ -15,8 +15,6 @@ func HandleMotd(w http.ResponseWriter, r *http.Request) { var statusCode int switch r.Method { - case http.MethodHead: - statusCode = http.StatusOK case http.MethodGet: _motd, motdErr := gpcm.GetMessageOfTheDay() if motdErr != nil { diff --git a/api/unban.go b/api/unban.go index f91dd25..375d5c3 100644 --- a/api/unban.go +++ b/api/unban.go @@ -14,12 +14,9 @@ func HandleUnban(w http.ResponseWriter, r *http.Request) { var err string var statusCode int - switch r.Method { - case http.MethodHead: - statusCode = http.StatusOK - case http.MethodPost: + if r.Method == http.MethodPost { user, success, err, statusCode = handleUnbanImpl(w, r) - default: + } else { err = "Incorrect request. POST or HEAD only." statusCode = http.StatusBadRequest } diff --git a/database/user.go b/database/user.go index 4072a60..9bec502 100644 --- a/database/user.go +++ b/database/user.go @@ -16,7 +16,7 @@ const ( UpdateUserProfileID = `UPDATE users SET profile_id = $3 WHERE user_id = $1 AND gsbrcd = $2` UpdateUserNGDeviceID = `UPDATE users SET ng_device_id = $2 WHERE profile_id = $1` GetUser = `SELECT user_id, gsbrcd, email, unique_nick, firstname, lastname, open_host, last_ip_address, last_ingamesn FROM users WHERE profile_id = $1` - DeleteUser = `DELETE FROM users WHERE profile_id = $1 RETURNING user_id, gsbrcd, email, unique_nick, firstname, lastname, open_host, last_ip_address, last_ingamesn` + ClearProfileQuery = `DELETE FROM users WHERE profile_id = $1 RETURNING user_id, gsbrcd, email, unique_nick, firstname, lastname, open_host, last_ip_address, last_ingamesn` DoesUserExist = `SELECT EXISTS(SELECT 1 FROM users WHERE user_id = $1 AND gsbrcd = $2)` IsProfileIDInUse = `SELECT EXISTS(SELECT 1 FROM users WHERE profile_id = $1)` DeleteUserSession = `DELETE FROM sessions WHERE profile_id = $1` @@ -142,7 +142,7 @@ func GetProfile(pool *pgxpool.Pool, ctx context.Context, profileId uint32) (User func ClearProfile(pool *pgxpool.Pool, ctx context.Context, profileId uint32) (User, bool) { user := User{} - row := pool.QueryRow(ctx, DeleteUser, profileId) + row := pool.QueryRow(ctx, ClearProfileQuery, profileId) err := row.Scan(&user.UserId, &user.GsbrCode, &user.Email, &user.UniqueNick, &user.FirstName, &user.LastName, &user.OpenHost, &user.LastIPAddress, &user.LastInGameSn) if err != nil {