validations

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyCardBack = errors.New("card has empty back value")

ErrEmptyCardBack is a corresponding error for NotEmptyCardBack

View Source
var ErrEmptyCardFront = errors.New("card has empty front value")

ErrEmptyCardFront is a corresponding error for NotEmptyCardFront

View Source
var ErrEmptyDeckName = errors.New("deck has empty name")

ErrEmptyDeckName is a corresponding error for NotEmptyDeckName.

View Source
var ErrNotUniqueDeckName = errors.New("deck name is not unique")

ErrNotUniqueDeckName is corrseponding error for UniqueDeckName.

View Source
var NotEmptyCardBack valdy.ValidationFunc[value.Card] = func(card value.Card) error {
	if card.Back == "" {
		return valdy.ErrorFrom(ErrEmptyCardBack).Wrap(
			fmt.Errorf("card's back value should not be empty"),
		)
	}
	return nil
}

NotEmptyCardBack is a rule that checks back's non-emptyness.

View Source
var NotEmptyCardFront valdy.ValidationFunc[value.Card] = func(card value.Card) error {
	if card.Front == "" {
		return valdy.ErrorFrom(ErrEmptyCardFront).Wrap(
			fmt.Errorf("card's front value should not be empty"),
		)
	}
	return nil
}

NotEmptyCardFront is a rule that checks front's non-emptyness.

View Source
var NotEmptyDeckName valdy.ValidationFunc[value.Deck] = func(deck value.Deck) error {
	if deck.Name == "" {
		return valdy.ErrorFrom(ErrEmptyDeckName).Wrap(
			fmt.Errorf("deck's(ID=%s) name should not be empty", deck.ID),
		)
	}
	return nil
}

NotEmptyDeckName is a rule that checks deck's name non-emptyness.

View Source
var UniqueDeckName = func(deckService service.DeckService) valdy.ValidationFunc[value.Deck] {
	return func(deck value.Deck) error {
		d, _ := deckService.FindDeckByName(deck.Name)
		if d != nil {
			return valdy.ErrorFrom(ErrNotUniqueDeckName).Wrap(
				fmt.Errorf("deck name=%s should be unique", deck.Name),
			)
		}
		return nil
	}
}

UniqueDeckName is a rule that check deck's name uniqueness.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL