Update: Few issues to resolve see readme
this push will conclude the majority of pulls. this repos will now, not be actively be managed or any further code pushes will not be frequent.
This commit is contained in:
31
app/internal/models/data_storage.go
Normal file
31
app/internal/models/data_storage.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetCurrentUserID(w http.ResponseWriter, r *http.Request)(int){
|
||||
currentUserID := r.Context().Value("user_id").(int)
|
||||
return currentUserID
|
||||
}
|
||||
|
||||
func GetCurrentUserName(r *http.Request) (string, error) {
|
||||
currentUserID, ok := r.Context().Value("user_id").(int)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("user_id not found in context")
|
||||
}
|
||||
|
||||
var currentUserName string
|
||||
err := DB.QueryRow(`
|
||||
SELECT first_name
|
||||
FROM users
|
||||
WHERE user_id = $1
|
||||
`, currentUserID).Scan(¤tUserName)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return currentUserName, nil
|
||||
}
|
||||
Reference in New Issue
Block a user