Remove HEAD support, change sql query name

This commit is contained in:
ppeb 2024-09-16 01:17:31 -05:00
parent 64e007631f
commit e12944ccab
No known key found for this signature in database
GPG Key ID: CC147AD1B3D318D0
6 changed files with 11 additions and 25 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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 {