diff options
author | Joris | 2021-01-03 13:40:40 +0100 |
---|---|---|
committer | Joris | 2021-01-03 13:54:20 +0100 |
commit | 11052951b74b9ad4b6a9412ae490086235f9154b (patch) | |
tree | 64526ac926c1bf470ea113f6cac8a33158684e8d /server/src/Model | |
parent | 371449b0e312a03162b78797b83dee9d81706669 (diff) |
Rewrite in Rust
Diffstat (limited to 'server/src/Model')
-rw-r--r-- | server/src/Model/CreateCategory.hs | 10 | ||||
-rw-r--r-- | server/src/Model/CreateIncome.hs | 10 | ||||
-rw-r--r-- | server/src/Model/CreatePayment.hs | 16 | ||||
-rw-r--r-- | server/src/Model/EditCategory.hs | 13 | ||||
-rw-r--r-- | server/src/Model/EditIncome.hs | 13 | ||||
-rw-r--r-- | server/src/Model/EditPayment.hs | 17 | ||||
-rw-r--r-- | server/src/Model/HashedPassword.hs | 27 | ||||
-rw-r--r-- | server/src/Model/IncomeResource.hs | 15 | ||||
-rw-r--r-- | server/src/Model/Mail.hs | 12 | ||||
-rw-r--r-- | server/src/Model/PaymentResource.hs | 15 | ||||
-rw-r--r-- | server/src/Model/Query.hs | 32 | ||||
-rw-r--r-- | server/src/Model/SignIn.hs | 10 | ||||
-rw-r--r-- | server/src/Model/UUID.hs | 10 |
13 files changed, 0 insertions, 200 deletions
diff --git a/server/src/Model/CreateCategory.hs b/server/src/Model/CreateCategory.hs deleted file mode 100644 index dae061b..0000000 --- a/server/src/Model/CreateCategory.hs +++ /dev/null @@ -1,10 +0,0 @@ -module Model.CreateCategory - ( CreateCategory(..) - ) where - -import Data.Text (Text) - -data CreateCategory = CreateCategory - { _createCategory_name :: Text - , _createCategory_color :: Text - } deriving (Show) diff --git a/server/src/Model/CreateIncome.hs b/server/src/Model/CreateIncome.hs deleted file mode 100644 index 82451d2..0000000 --- a/server/src/Model/CreateIncome.hs +++ /dev/null @@ -1,10 +0,0 @@ -module Model.CreateIncome - ( CreateIncome(..) - ) where - -import Data.Time.Calendar (Day) - -data CreateIncome = CreateIncome - { _createIncome_amount :: Int - , _createIncome_date :: Day - } deriving (Show) diff --git a/server/src/Model/CreatePayment.hs b/server/src/Model/CreatePayment.hs deleted file mode 100644 index b25d2a4..0000000 --- a/server/src/Model/CreatePayment.hs +++ /dev/null @@ -1,16 +0,0 @@ -module Model.CreatePayment - ( CreatePayment(..) - ) where - -import Data.Text (Text) -import Data.Time.Calendar (Day) - -import Common.Model (CategoryId, Frequency) - -data CreatePayment = CreatePayment - { _createPayment_name :: Text - , _createPayment_cost :: Int - , _createPayment_date :: Day - , _createPayment_category :: CategoryId - , _createPayment_frequency :: Frequency - } deriving (Show) diff --git a/server/src/Model/EditCategory.hs b/server/src/Model/EditCategory.hs deleted file mode 100644 index 8ee26ac..0000000 --- a/server/src/Model/EditCategory.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Model.EditCategory - ( EditCategory(..) - ) where - -import Data.Text (Text) - -import Common.Model (CategoryId) - -data EditCategory = EditCategory - { _editCategory_id :: CategoryId - , _editCategory_name :: Text - , _editCategory_color :: Text - } deriving (Show) diff --git a/server/src/Model/EditIncome.hs b/server/src/Model/EditIncome.hs deleted file mode 100644 index ac3d311..0000000 --- a/server/src/Model/EditIncome.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Model.EditIncome - ( EditIncome(..) - ) where - -import Data.Time.Calendar (Day) - -import Common.Model (IncomeId) - -data EditIncome = EditIncome - { _editIncome_id :: IncomeId - , _editIncome_amount :: Int - , _editIncome_date :: Day - } deriving (Show) diff --git a/server/src/Model/EditPayment.hs b/server/src/Model/EditPayment.hs deleted file mode 100644 index ac4c906..0000000 --- a/server/src/Model/EditPayment.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Model.EditPayment - ( EditPayment(..) - ) where - -import Data.Text (Text) -import Data.Time.Calendar (Day) - -import Common.Model (CategoryId, Frequency, PaymentId) - -data EditPayment = EditPayment - { _editPayment_id :: PaymentId - , _editPayment_name :: Text - , _editPayment_cost :: Int - , _editPayment_date :: Day - , _editPayment_category :: CategoryId - , _editPayment_frequency :: Frequency - } deriving (Show) diff --git a/server/src/Model/HashedPassword.hs b/server/src/Model/HashedPassword.hs deleted file mode 100644 index c71e372..0000000 --- a/server/src/Model/HashedPassword.hs +++ /dev/null @@ -1,27 +0,0 @@ -module Model.HashedPassword - ( hash - , check - , HashedPassword(..) - ) where - -import qualified Crypto.BCrypt as BCrypt -import Data.Text (Text) -import qualified Data.Text.Encoding as TE - -import Common.Model.Password (Password (..)) - -newtype HashedPassword = HashedPassword Text deriving (Show) - -hash :: Password -> IO (Maybe HashedPassword) -hash (Password p) = do - hashed <- BCrypt.hashPasswordUsingPolicy BCrypt.slowerBcryptHashingPolicy (TE.encodeUtf8 p) - case hashed of - Nothing -> - return Nothing - - Just h -> - return . Just . HashedPassword . TE.decodeUtf8 $ h - -check :: Password -> HashedPassword -> Bool -check (Password p) (HashedPassword h) = - BCrypt.validatePassword (TE.encodeUtf8 h) (TE.encodeUtf8 p) diff --git a/server/src/Model/IncomeResource.hs b/server/src/Model/IncomeResource.hs deleted file mode 100644 index 6ab5f18..0000000 --- a/server/src/Model/IncomeResource.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Model.IncomeResource - ( IncomeResource(..) - ) where - -import Common.Model (Income (..)) - -import Resource (Resource, resourceCreatedAt, resourceDeletedAt, - resourceEditedAt) - -newtype IncomeResource = IncomeResource Income - -instance Resource IncomeResource where - resourceCreatedAt (IncomeResource i) = _income_createdAt i - resourceEditedAt (IncomeResource i) = _income_editedAt i - resourceDeletedAt (IncomeResource i) = _income_deletedAt i diff --git a/server/src/Model/Mail.hs b/server/src/Model/Mail.hs deleted file mode 100644 index 780efcc..0000000 --- a/server/src/Model/Mail.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Model.Mail - ( Mail(..) - ) where - -import Data.Text (Text) - -data Mail = Mail - { from :: Text - , to :: [Text] - , subject :: Text - , body :: Text - } deriving (Eq, Show) diff --git a/server/src/Model/PaymentResource.hs b/server/src/Model/PaymentResource.hs deleted file mode 100644 index 1ea978c..0000000 --- a/server/src/Model/PaymentResource.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Model.PaymentResource - ( PaymentResource(..) - ) where - -import Common.Model (Payment (..)) - -import Resource (Resource, resourceCreatedAt, resourceDeletedAt, - resourceEditedAt) - -newtype PaymentResource = PaymentResource Payment - -instance Resource PaymentResource where - resourceCreatedAt (PaymentResource p) = _payment_createdAt p - resourceEditedAt (PaymentResource p) = _payment_editedAt p - resourceDeletedAt (PaymentResource p) = _payment_deletedAt p diff --git a/server/src/Model/Query.hs b/server/src/Model/Query.hs deleted file mode 100644 index 22ae95b..0000000 --- a/server/src/Model/Query.hs +++ /dev/null @@ -1,32 +0,0 @@ -module Model.Query - ( Query(..) - , run - ) where - -import Data.Functor (Functor) -import Database.SQLite.Simple (Connection) -import qualified Database.SQLite.Simple as SQLite - -data Query a = Query (Connection -> IO a) - -instance Functor Query where - fmap f (Query call) = Query (fmap f . call) - -instance Applicative Query where - pure x = Query (const $ return x) - (Query callF) <*> (Query callX) = Query (\conn -> do - x <- callX conn - f <- callF conn - return (f x)) - -instance Monad Query where - (Query callX) >>= f = Query (\conn -> do - x <- callX conn - case f x of Query callY -> callY conn) - -run :: Query a -> IO a -run (Query call) = do - conn <- SQLite.open "database" - result <- call conn - _ <- SQLite.close conn - return result diff --git a/server/src/Model/SignIn.hs b/server/src/Model/SignIn.hs deleted file mode 100644 index a217bae..0000000 --- a/server/src/Model/SignIn.hs +++ /dev/null @@ -1,10 +0,0 @@ -module Model.SignIn - ( SignIn(..) - ) where - -import Common.Model (Email, Password) - -data SignIn = SignIn - { _signIn_email :: Email - , _signIn_password :: Password - } deriving Show diff --git a/server/src/Model/UUID.hs b/server/src/Model/UUID.hs deleted file mode 100644 index 0959a8e..0000000 --- a/server/src/Model/UUID.hs +++ /dev/null @@ -1,10 +0,0 @@ -module Model.UUID - ( generateUUID - ) where - -import Data.Text (Text, pack) -import Data.UUID (toString) -import Data.UUID.V4 (nextRandom) - -generateUUID :: IO Text -generateUUID = pack . toString <$> nextRandom |