Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c4390742b3 | |||
| 0efc3629b0 | |||
| a77d57603f |
@@ -39,6 +39,7 @@ function onTextAreaFocus() {
|
|||||||
</div>
|
</div>
|
||||||
<VRating
|
<VRating
|
||||||
half-increments
|
half-increments
|
||||||
|
clearable
|
||||||
hover
|
hover
|
||||||
:length="5"
|
:length="5"
|
||||||
size="x-large"
|
size="x-large"
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ AuthenticationSuccess = "Authentication was a success."
|
|||||||
ValidationRequired = "This field is required."
|
ValidationRequired = "This field is required."
|
||||||
ValidationTooShort = "This field is too short. It should be at least %s characters."
|
ValidationTooShort = "This field is too short. It should be at least %s characters."
|
||||||
ValidationTooLong = "This field is too long. It should be under %s characters."
|
ValidationTooLong = "This field is too long. It should be under %s characters."
|
||||||
|
ValidationLowerThan = "This field should be lower than %s."
|
||||||
|
ValidationGreaterThan = "This field should be greater than %s."
|
||||||
ValidationPropertyFail = "Validation failed for '%s' property."
|
ValidationPropertyFail = "Validation failed for '%s' property."
|
||||||
RegistrationDisabled = "Registration has been disabled on this instance."
|
RegistrationDisabled = "Registration has been disabled on this instance."
|
||||||
UserAlreadyExists = "An user with this name already exists."
|
UserAlreadyExists = "An user with this name already exists."
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ AuthenticationSuccess = "Connexion réussie."
|
|||||||
ValidationRequired = "Ce champ est requis."
|
ValidationRequired = "Ce champ est requis."
|
||||||
ValidationTooShort = "Ce champ est trop court. Il devrait contenir au moins %s caractères."
|
ValidationTooShort = "Ce champ est trop court. Il devrait contenir au moins %s caractères."
|
||||||
ValidationTooLong = "Ce champ est trop long. Il ne devrait pas dépasser %s caractères."
|
ValidationTooLong = "Ce champ est trop long. Il ne devrait pas dépasser %s caractères."
|
||||||
|
ValidationLowerThan = "Ce champ devrait être inférieur à %s."
|
||||||
|
ValidationGreaterThan = "Ce champ devrait être supérieur à %s."
|
||||||
ValidationPropertyFail = "La validation a échoué pour la propriété '%s'."
|
ValidationPropertyFail = "La validation a échoué pour la propriété '%s'."
|
||||||
RegistrationDisabled = "La création de nouveaux comptes a été désactivée sur cette instance."
|
RegistrationDisabled = "La création de nouveaux comptes a été désactivée sur cette instance."
|
||||||
UserAlreadyExists = "Un utilisateur avec le même nom existe déjà."
|
UserAlreadyExists = "Un utilisateur avec le même nom existe déjà."
|
||||||
|
|||||||
@@ -41,15 +41,18 @@ func ValidateId(db *gorm.DB, id uint, value any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ReturnErrorsAsJsonResponse(ac *appcontext.AppContext, err error) {
|
func ReturnErrorsAsJsonResponse(ac *appcontext.AppContext, err error) {
|
||||||
var httpError HttpError
|
|
||||||
var ve validator.ValidationErrors
|
ve, isValidationErrors := errors.AsType[validator.ValidationErrors](err)
|
||||||
if errors.As(err, &ve) {
|
if isValidationErrors {
|
||||||
ac.C.JSON(http.StatusBadRequest, getValidationErrors(ac, &ve))
|
ac.C.JSON(http.StatusBadRequest, getValidationErrors(ac, &ve))
|
||||||
} else if errors.As(err, &httpError) {
|
return
|
||||||
ac.C.JSON(httpError.StatusCode, gin.H{"error": httpError.Err.Error()})
|
|
||||||
} else {
|
|
||||||
ac.C.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
||||||
}
|
}
|
||||||
|
httpError, isHttpError := errors.AsType[HttpError](err)
|
||||||
|
if isHttpError {
|
||||||
|
ac.C.JSON(httpError.StatusCode, gin.H{"error": httpError.Err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ac.C.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HttpError) Error() string {
|
func (h HttpError) Error() string {
|
||||||
@@ -79,10 +82,12 @@ func computeValidationMessage(ac *appcontext.AppContext, fe *validator.FieldErro
|
|||||||
return i18nresource.GetTranslatedMessage(ac, "ValidationRequired")
|
return i18nresource.GetTranslatedMessage(ac, "ValidationRequired")
|
||||||
case "min":
|
case "min":
|
||||||
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationTooShort"), (*fe).Param())
|
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationTooShort"), (*fe).Param())
|
||||||
case "gte":
|
|
||||||
return fmt.Sprintf("Should be greater than %s", (*fe).Param())
|
|
||||||
case "max":
|
case "max":
|
||||||
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationTooLong"), (*fe).Param())
|
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationTooLong"), (*fe).Param())
|
||||||
|
case "lte":
|
||||||
|
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationLowerThan"), (*fe).Param())
|
||||||
|
case "gte":
|
||||||
|
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationGreaterThan"), (*fe).Param())
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationPropertyFail"), tag)
|
return fmt.Sprintf(i18nresource.GetTranslatedMessage(ac, "ValidationPropertyFail"), tag)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ func PutUserBookHandler(ac appcontext.AppContext) {
|
|||||||
err = validateRating(*userBookPut.Rating)
|
err = validateRating(*userBookPut.Rating)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
updateRating(&userbook, &userBookPut)
|
updateRating(&userbook, &userBookPut)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user