add hub function
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package httpRequest
|
||||
|
||||
import (
|
||||
json2 "encoding/json"
|
||||
"encoding/json"
|
||||
"maps"
|
||||
"net/http"
|
||||
"slices"
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func HandleUserNewToken(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(&response, request, normal) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,18 +70,18 @@ func HandleUserNewToken(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json2.Marshal(types.LoginReturn{Token: token, UserId: user.Id})
|
||||
data, err := json.Marshal(types.LoginResponse{Token: token, UserId: user.Id})
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
response.WriteHeader(http.StatusCreated)
|
||||
response.Write(json)
|
||||
response.Write(data)
|
||||
}
|
||||
|
||||
func HandleUserNew(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(&response, request, normal) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func HandleUserNew(response http.ResponseWriter, request *http.Request) {
|
||||
newUser := &types.User{
|
||||
Name: username,
|
||||
PasswordHash: hashedPassword,
|
||||
Color: types.Rgba{}.GetRandom(),
|
||||
Color: types.RandomRgba(),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ func HandleUserNew(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
err = postgresql.UserSave(ctx, newUser)
|
||||
if err != nil {
|
||||
http.Error(response, "name taken", http.StatusUnauthorized)
|
||||
http.Error(response, "name taken", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func HandleUserNew(response http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
func HandleUserDelete(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(&response, request, normal) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
ctx := request.Context()
|
||||
@@ -144,7 +144,7 @@ func HandleUserDelete(response http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
func HandleUserModProfile(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(&response, request, normal) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func HandleUserModProfile(response http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
func HandleUserGetUser(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(&response, request, normal) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
ctx := request.Context()
|
||||
@@ -234,21 +234,21 @@ func HandleUserGetUser(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
targetId, err := convertions.StringToUuid(request.URL.Query().Get("targetid"))
|
||||
if err != nil {
|
||||
http.Error(response, "invalid userid", http.StatusUnauthorized)
|
||||
http.Error(response, "invalid userid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
target, err := getUserById(ctx, targetId)
|
||||
if err != nil {
|
||||
http.Error(response, "invalid userid", http.StatusUnauthorized)
|
||||
http.Error(response, "user not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json2.Marshal(target)
|
||||
userData, err := json.Marshal(target)
|
||||
if err != nil {
|
||||
http.Error(response, "json parse error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
response.Write(json)
|
||||
response.Write(userData)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user