added additional tests for parent id

This commit is contained in:
$(pass /github/name)
2024-07-12 18:58:32 +02:00
parent 0b2ad57864
commit ac037b12e0
2 changed files with 14 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
package controllers
import (
"fmt"
"GoMembership/internal/models"
"GoMembership/internal/services"
@@ -45,7 +47,7 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
id, token, err := uc.Service.RegisterUser(&regData.User)
if err != nil {
logger.Error.Printf("Couldn't register User: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Couldn't register User"})
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Couldn't register User: %v", err)})
return
}
regData.User.ID = id
@@ -85,7 +87,6 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
logger.Error.Printf("Failed to notify admin of new user registration: %v", err)
// Proceed without returning error since user registration is successful
}
c.JSON(http.StatusCreated, gin.H{
"status": "success",
"id": regData.User.ID,

View File

@@ -68,6 +68,17 @@ func ValidateRequiredMembershipField(fl validator.FieldLevel) bool {
// Get the value of the field specified by RequiredMembershipField
fieldValue := reflect.ValueOf(membership).FieldByName(fieldName)
// Check if the fieldValue is valid
if !fieldValue.IsValid() {
return false
}
// Check if the fieldValue is a nil pointer
if fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil() {
return false
}
// Ensure that the fieldValue is an int64
var fieldInt64 int64
if fieldValue.Kind() == reflect.Int64 {