limit the max and min value of amount
This commit is contained in:
+28
-6
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
func PrintSuccessResult(c *core.Context, result interface{}) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"result": result,
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,10 +35,10 @@ func PrintErrorResult(c *core.Context, err *errs.Error) {
|
||||
}
|
||||
|
||||
c.AbortWithStatusJSON(err.HttpStatusCode, gin.H{
|
||||
"success": false,
|
||||
"errorCode": err.Code(),
|
||||
"success": false,
|
||||
"errorCode": err.Code(),
|
||||
"errorMessage": errorMessage,
|
||||
"path": c.Request.URL.Path,
|
||||
"path": c.Request.URL.Path,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,9 +49,17 @@ func getValidationErrorText(err validator.FieldError) string {
|
||||
case "required":
|
||||
return errs.GetParameterIsRequiredMessage(fieldName)
|
||||
case "max":
|
||||
return errs.GetParameterMustLessThanMessage(fieldName, err.Param())
|
||||
if isIntegerParameter(err.Kind()) {
|
||||
return errs.GetParameterMustLessThanMessage(fieldName, err.Param())
|
||||
} else if isStringParameter(err.Kind()) {
|
||||
return errs.GetParameterMustLessThanCharsMessage(fieldName, err.Param())
|
||||
}
|
||||
case "min":
|
||||
return errs.GetParameterMustMoreThanMessage(fieldName, err.Param())
|
||||
if isIntegerParameter(err.Kind()) {
|
||||
return errs.GetParameterMustMoreThanMessage(fieldName, err.Param())
|
||||
} else if isStringParameter(err.Kind()) {
|
||||
return errs.GetParameterMustMoreThanCharsMessage(fieldName, err.Param())
|
||||
}
|
||||
case "len":
|
||||
return errs.GetParameterLengthNotEqualMessage(fieldName, err.Param())
|
||||
case "notBlank":
|
||||
@@ -67,3 +76,16 @@ func getValidationErrorText(err validator.FieldError) string {
|
||||
|
||||
return errs.GetParameterInvalidMessage(fieldName)
|
||||
}
|
||||
|
||||
func isIntegerParameter(kind reflect.Kind) bool {
|
||||
switch kind {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isStringParameter(kind reflect.Kind) bool {
|
||||
return kind == reflect.String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user