fix: user model json handling; user_controller_test debug logging, user_controller

This commit is contained in:
$(pass /github/name)
2024-09-07 08:55:39 +02:00
parent ff7c83671f
commit 066419e546
3 changed files with 136 additions and 22 deletions

View File

@@ -24,17 +24,19 @@ type UserController struct {
}
type RegistrationData struct {
User models.User `json:"user"`
User models.User `json:"user"`
Password string `json:"password"`
}
func (uc *UserController) CurrentUserHandler(c *gin.Context) {
userID, err := middlewares.GetUserIDFromContext(c)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Failed to authenticate user"})
c.Abort()
return
userIDString, ok := c.Get("user_id")
if !ok || userIDString == nil {
logger.Error.Printf("Error getting user_id from header")
}
user, err := uc.Service.GetUserByID(userID)
userID := userIDString.(float64)
logger.Error.Printf("UserIDINt64: %v", userID)
logger.Error.Printf("c.Get Value: %v", userIDString)
user, err := uc.Service.GetUserByID(int64(userID))
if err != nil {
logger.Error.Printf("Error retrieving valid user: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error retrieving user."})
@@ -124,6 +126,7 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
// logger.Info.Printf("REGISTERING user: %#v", regData.User)
regData.User.RoleID = constants.Roles.Member
regData.User.Password = regData.Password
// Register User
id, token, err := uc.Service.RegisterUser(&regData.User)