aboutsummaryrefslogtreecommitdiff
path: root/common/src/Common/Validation
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/Common/Validation')
-rw-r--r--common/src/Common/Validation/Atomic.hs61
-rw-r--r--common/src/Common/Validation/Category.hs15
-rw-r--r--common/src/Common/Validation/Income.hs17
-rw-r--r--common/src/Common/Validation/Payment.hs31
-rw-r--r--common/src/Common/Validation/SignIn.hs17
5 files changed, 0 insertions, 141 deletions
diff --git a/common/src/Common/Validation/Atomic.hs b/common/src/Common/Validation/Atomic.hs
deleted file mode 100644
index 9c21e14..0000000
--- a/common/src/Common/Validation/Atomic.hs
+++ /dev/null
@@ -1,61 +0,0 @@
-module Common.Validation.Atomic
- ( color
- , day
- , minLength
- , nonEmpty
- , nonNullNumber
- , number
- , password
- ) where
-
-import qualified Data.Char as Char
-import Data.Text (Text)
-import qualified Data.Text as T
-import Data.Time.Calendar (Day)
-import Data.Validation (Validation)
-import qualified Data.Validation as V
-import qualified Text.Read as T
-
-import qualified Common.Msg as Msg
-import qualified Common.Util.Time as Time
-
-minLength :: Int -> Text -> Validation Text Text
-minLength l =
- V.validate
- (Msg.get (Msg.Form_MinChars l))
- (\t -> if T.length t >= l then Just t else Nothing)
-
-nonEmpty :: Text -> Validation Text Text
-nonEmpty =
- V.validate
- (Msg.get Msg.Form_NonEmpty)
- (\t -> if (not . T.null $ t) then Just t else Nothing)
-
-number :: Text -> Validation Text Int
-number input =
- case (T.readMaybe . T.unpack $ input) of
- Just n -> V.Success n
- _ -> V.Failure (Msg.get Msg.Form_InvalidInt)
-
-nonNullNumber :: Int -> Validation Text Int
-nonNullNumber =
- V.validate
- (Msg.get Msg.Form_NonNullNumber)
- (\n -> if n /= 0 then Just n else Nothing)
-
-day :: Text -> Validation Text Day
-day str =
- case Time.parseDay str of
- Just d -> V.Success d
- Nothing -> V.Failure $ Msg.get Msg.Form_InvalidDate
-
-color :: Text -> Validation Text Text
-color str =
- if T.take 1 str == "#" && T.all Char.isHexDigit (T.drop 1 str) then
- V.Success str
-
- else
- V.Failure (Msg.get Msg.Form_InvalidColor)
-
-password :: Text -> Validation Text Text
-password = minLength 8
diff --git a/common/src/Common/Validation/Category.hs b/common/src/Common/Validation/Category.hs
deleted file mode 100644
index f9e6ab4..0000000
--- a/common/src/Common/Validation/Category.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-module Common.Validation.Category
- ( name
- , color
- ) where
-
-import Data.Text (Text)
-import Data.Validation (Validation)
-
-import qualified Common.Validation.Atomic as Atomic
-
-name :: Text -> Validation Text Text
-name = Atomic.nonEmpty
-
-color :: Text -> Validation Text Text
-color = Atomic.color
diff --git a/common/src/Common/Validation/Income.hs b/common/src/Common/Validation/Income.hs
deleted file mode 100644
index 7a58bab..0000000
--- a/common/src/Common/Validation/Income.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Common.Validation.Income
- ( amount
- , date
- ) where
-
-import Data.Text (Text)
-import Data.Time.Calendar (Day)
-import Data.Validation (Validation)
-import qualified Data.Validation as V
-
-import qualified Common.Validation.Atomic as Atomic
-
-amount :: Text -> Validation Text Int
-amount input = V.bindValidation (Atomic.number input) Atomic.nonNullNumber
-
-date :: Text -> Validation Text Day
-date = Atomic.day
diff --git a/common/src/Common/Validation/Payment.hs b/common/src/Common/Validation/Payment.hs
deleted file mode 100644
index e3c447a..0000000
--- a/common/src/Common/Validation/Payment.hs
+++ /dev/null
@@ -1,31 +0,0 @@
-module Common.Validation.Payment
- ( name
- , cost
- , date
- , category
- ) where
-
-import Data.Text (Text)
-import Data.Time.Calendar (Day)
-import Data.Validation (Validation)
-import qualified Data.Validation as V
-
-import Common.Model (CategoryId)
-import qualified Common.Msg as Msg
-import qualified Common.Validation.Atomic as Atomic
-
-name :: Text -> Validation Text Text
-name = Atomic.nonEmpty
-
-cost :: Text -> Validation Text Int
-cost input = V.bindValidation (Atomic.number input) Atomic.nonNullNumber
-
-date :: Text -> Validation Text Day
-date = Atomic.day
-
-category :: [CategoryId] -> CategoryId -> Validation Text CategoryId
-category cs c =
- if elem c cs then
- V.Success c
- else
- V.Failure $ Msg.get Msg.Form_InvalidCategory
diff --git a/common/src/Common/Validation/SignIn.hs b/common/src/Common/Validation/SignIn.hs
deleted file mode 100644
index ac9cc37..0000000
--- a/common/src/Common/Validation/SignIn.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Common.Validation.SignIn
- ( email
- , password
- ) where
-
-import Data.Text (Text)
-import Data.Validation (Validation)
-
-import Common.Model.Email (Email (..))
-import Common.Model.Password (Password (..))
-import qualified Common.Validation.Atomic as Atomic
-
-email :: Text -> Validation Text Email
-email = fmap Email . Atomic.minLength 5
-
-password :: Text -> Validation Text Password
-password = fmap Password . Atomic.minLength 8