2022-10-03 05:19:33 +00:00
|
|
|
package domain
|
|
|
|
|
2022-10-23 06:20:48 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
2022-10-10 05:16:40 +00:00
|
|
|
|
2023-06-27 12:00:35 +00:00
|
|
|
var ErrNothingToUpdate = errors.New("nothing to update")
|
2022-10-03 05:19:33 +00:00
|
|
|
|
2023-06-27 12:00:35 +00:00
|
|
|
type TranslatableError interface {
|
2022-10-03 05:19:33 +00:00
|
|
|
error
|
2023-06-27 12:00:35 +00:00
|
|
|
Slug() string
|
|
|
|
Params() map[string]any
|
2022-10-03 05:19:33 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 12:00:35 +00:00
|
|
|
type RequiredError struct {
|
2022-10-03 05:19:33 +00:00
|
|
|
Field string
|
2022-10-23 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 12:00:35 +00:00
|
|
|
var _ TranslatableError = RequiredError{}
|
2022-10-23 06:20:48 +00:00
|
|
|
|
2023-06-27 12:00:35 +00:00
|
|
|
func (e RequiredError) Error() string {
|
|
|
|
return fmt.Sprintf("%s can't be blank", e.Field)
|
2022-10-23 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 12:00:35 +00:00
|
|
|
func (e RequiredError) Slug() string {
|
|
|
|
return "required"
|
2022-10-23 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 12:00:35 +00:00
|
|
|
func (e RequiredError) Params() map[string]any {
|
|
|
|
return map[string]any{
|
|
|
|
"Field": e.Field,
|
|
|
|
}
|
2022-10-23 06:20:48 +00:00
|
|
|
}
|
2023-07-13 04:22:52 +00:00
|
|
|
|
|
|
|
type GreaterEqualThanError struct {
|
|
|
|
Field string
|
|
|
|
Threshold int
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ TranslatableError = GreaterEqualThanError{}
|
|
|
|
|
|
|
|
func (e GreaterEqualThanError) Error() string {
|
|
|
|
return fmt.Sprintf("%s must be no less than %d", e.Field, e.Threshold)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e GreaterEqualThanError) Slug() string {
|
|
|
|
return "greater-equal-than"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e GreaterEqualThanError) Params() map[string]any {
|
|
|
|
return map[string]any{
|
|
|
|
"Field": e.Field,
|
|
|
|
"Threshold": e.Threshold,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type LessEqualThanError struct {
|
|
|
|
Field string
|
|
|
|
Threshold int
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ TranslatableError = LessEqualThanError{}
|
|
|
|
|
|
|
|
func (e LessEqualThanError) Error() string {
|
|
|
|
return fmt.Sprintf("%s must be no no greater than %d", e.Field, e.Threshold)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e LessEqualThanError) Slug() string {
|
|
|
|
return "less-equal-than"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e LessEqualThanError) Params() map[string]any {
|
|
|
|
return map[string]any{
|
|
|
|
"Field": e.Field,
|
|
|
|
"Threshold": e.Threshold,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type LengthTooShortError struct {
|
|
|
|
Field string
|
|
|
|
Threshold int
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ TranslatableError = LengthTooShortError{}
|
|
|
|
|
|
|
|
func (e LengthTooShortError) Error() string {
|
|
|
|
return fmt.Sprintf("%s: the length must be no less than %d", e.Field, e.Threshold)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e LengthTooShortError) Slug() string {
|
|
|
|
return "length-too-short"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e LengthTooShortError) Params() map[string]any {
|
|
|
|
return map[string]any{
|
|
|
|
"Field": e.Field,
|
|
|
|
"Threshold": e.Threshold,
|
|
|
|
}
|
|
|
|
}
|