fix: concurrency
This commit is contained in:
Binary file not shown.
@@ -3,7 +3,6 @@ package middleware
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -44,7 +43,7 @@ func TokenIsNotExpired(access_token string) bool {
|
||||
func GetUserProfile(context *gin.Context) {
|
||||
|
||||
session := sessions.Default(context)
|
||||
access_token := session.Get("access_token")
|
||||
/* access_token := session.Get("access_token")
|
||||
user_profile_client := http.Client{}
|
||||
|
||||
user_profile_url, err := url.Parse("https://" + os.Getenv("AUTH0_DOMAIN") + os.Getenv("AUTH0_USER_INFO_ENDPOINT"))
|
||||
@@ -71,10 +70,15 @@ func GetUserProfile(context *gin.Context) {
|
||||
}
|
||||
|
||||
defer user_profile_response.Body.Close()
|
||||
user_profile_bytes, _ := io.ReadAll(user_profile_response.Body)
|
||||
|
||||
user_profile_bytes, _ := io.ReadAll(user_profile_response.Body) */
|
||||
var user_profile dto.UserProfileResponse
|
||||
json.Unmarshal(user_profile_bytes, &user_profile)
|
||||
profile_session := session.Get("profile").(map[string]interface{})
|
||||
user_profile.Sub = profile_session["sub"].(string)
|
||||
user_profile.Email = profile_session["email"].(string)
|
||||
user_profile.Verified = profile_session["email_verified"].(bool)
|
||||
user_profile.PictureUrl = profile_session["picture"].(string)
|
||||
user_profile.Nickname = profile_session["nickname"].(string)
|
||||
user_profile.Updated_at = profile_session["updated_at"].(string)
|
||||
context.Set("user_profile", user_profile)
|
||||
context.Next()
|
||||
}
|
||||
|
||||
@@ -181,6 +181,8 @@ func GetCurrentAuthenticatedUser(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
|
||||
user_profile, _ := ctx.Get("user_profile")
|
||||
|
||||
log.Printf("%s", user_profile.(dto.UserProfileResponse).Sub)
|
||||
|
||||
sub_id := user_profile.(dto.UserProfileResponse).Sub
|
||||
|
||||
var user dto.UserResponse
|
||||
|
||||
@@ -3,9 +3,9 @@ package dto
|
||||
// User response for exposing to the front-end
|
||||
// :3
|
||||
type UserResponse struct {
|
||||
Id int `json: "id"`
|
||||
Name string `json: "name"`
|
||||
JobPosition string `json: "job_position"`
|
||||
Active bool `json: "active"`
|
||||
Admin bool `json: "admin"`
|
||||
Id int
|
||||
Name string
|
||||
JobPosition string
|
||||
Active bool
|
||||
Admin bool
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ require (
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
|
||||
@@ -135,6 +135,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
|
||||
@@ -99,6 +99,7 @@ func main() {
|
||||
router.GET("/item/history", corsmiddleware.CORSMiddleware, user_authenticated, middleware.GetUserProfile, user_in_db, user_active, user_is_admin, controllers.GetItemHistory(pool))
|
||||
router.POST("/position/create", corsmiddleware.CORSMiddleware, user_authenticated, middleware.GetUserProfile, user_in_db, user_active, user_is_admin, controllers.CreatePosition(pool))
|
||||
router.POST("/item/create", corsmiddleware.CORSMiddleware, user_authenticated, middleware.GetUserProfile, user_in_db, user_active, user_is_admin, controllers.CreateItem(pool))
|
||||
router.OPTIONS("/item/create", corsmiddleware.CORSMiddleware)
|
||||
router.POST("/order/create", corsmiddleware.CORSMiddleware, user_authenticated, middleware.GetUserProfile, user_in_db, user_active, controllers.CreateOrder(pool))
|
||||
router.OPTIONS("/order/create", corsmiddleware.CORSMiddleware)
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ FROM
|
||||
ordr_user
|
||||
LEFT JOIN ordr_position
|
||||
ON job_position = ordr_position.id
|
||||
AND ordr_user.sub_id = $1;
|
||||
WHERE
|
||||
ordr_user.sub_id = $1;
|
||||
`
|
||||
|
||||
const USER_SET_POSITION string = `
|
||||
|
||||
Reference in New Issue
Block a user