aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/Model/Payment.hs36
-rw-r--r--src/server/Model/User.hs12
2 files changed, 37 insertions, 11 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs
index 5b576c5..3893850 100644
--- a/src/server/Model/Payment.hs
+++ b/src/server/Model/Payment.hs
@@ -15,6 +15,7 @@ module Model.Payment
import Data.Maybe (listToMaybe)
import Data.Text (Text)
+import qualified Data.Text as T
import Data.Time (UTCTime)
import Data.Time.Calendar (Day)
import Data.Time.Clock (getCurrentTime)
@@ -76,7 +77,12 @@ listMonthly =
Query (\conn ->
SQLite.query
conn
- "SELECT * FROM payment WHERE deleted_at IS NULL AND frequency = ? ORDER BY name DESC"
+ (SQLite.Query $ T.intercalate " "
+ [ "SELECT *"
+ , "FROM payment"
+ , "WHERE deleted_at IS NULL AND frequency = ?"
+ , "ORDER BY name DESC"
+ ])
(Only Monthly)
)
@@ -86,7 +92,10 @@ create userId paymentName paymentCost paymentDate paymentFrequency =
now <- getCurrentTime
SQLite.execute
conn
- "INSERT INTO payment (user_id, name, cost, date, frequency, created_at) VALUES (?, ?, ?, ?, ?, ?)"
+ (SQLite.Query $ T.intercalate " "
+ [ "INSERT INTO payment (user_id, name, cost, date, frequency, created_at)"
+ , "VALUES (?, ?, ?, ?, ?, ?)"
+ ])
(userId, paymentName, paymentCost, paymentDate, paymentFrequency, now)
SQLite.lastInsertRowId conn
)
@@ -96,7 +105,10 @@ createMany payments =
Query (\conn ->
SQLite.executeMany
conn
- "INSERT INTO payment (user_id, name, cost, date, frequency, created_at) VALUES (?, ?, ?, ?, ?, ?)"
+ (SQLite.Query $ T.intercalate ""
+ [ "INSERT INTO payment (user_id, name, cost, date, frequency, created_at)"
+ , "VALUES (?, ?, ?, ?, ?, ?)"
+ ])
payments
)
@@ -112,7 +124,15 @@ editOwn userId paymentId paymentName paymentCost paymentDate paymentFrequency =
now <- getCurrentTime
SQLite.execute
conn
- "UPDATE payment SET edited_at = ?, name = ?, cost = ?, date = ?, frequency = ? WHERE id = ?"
+ (SQLite.Query $ T.intercalate " "
+ [ "UPDATE payment"
+ , "SET edited_at = ?,"
+ , " name = ?,"
+ , " cost = ?,"
+ , " date = ?,"
+ , " frequency = ?"
+ , "WHERE id = ?"
+ ])
(now, paymentName, paymentCost, paymentDate, paymentFrequency, paymentId)
return True
else
@@ -147,6 +167,12 @@ modifiedDuring start end =
Query (\conn ->
SQLite.query
conn
- "SELECT * FROM payment WHERE (created_at >= ? AND created_at <= ?) OR (edited_at >= ? AND edited_at <= ?) OR (deleted_at >= ? AND deleted_at <= ?)"
+ (SQLite.Query $ T.intercalate " "
+ [ "SELECT *"
+ , "FROM payment"
+ , "WHERE (created_at >= ? AND created_at <= ?)"
+ , " OR (edited_at >= ? AND edited_at <= ?)"
+ , " OR (deleted_at >= ? AND deleted_at <= ?)"
+ ])
(start, end, start, end, start, end)
)
diff --git a/src/server/Model/User.hs b/src/server/Model/User.hs
index eb78a69..e14fcef 100644
--- a/src/server/Model/User.hs
+++ b/src/server/Model/User.hs
@@ -4,8 +4,8 @@
module Model.User
( list
, get
- , createUser
- , deleteUser
+ , create
+ , delete
) where
import Data.Maybe (listToMaybe)
@@ -31,8 +31,8 @@ get userEmail =
SQLite.query conn "SELECT * FROM user WHERE email = ? LIMIT 1" (Only userEmail)
)
-createUser :: Text -> Text -> Query UserId
-createUser userEmail userName =
+create :: Text -> Text -> Query UserId
+create userEmail userName =
Query (\conn -> do
now <- getCurrentTime
SQLite.execute
@@ -42,8 +42,8 @@ createUser userEmail userName =
SQLite.lastInsertRowId conn
)
-deleteUser :: Text -> Query ()
-deleteUser userEmail =
+delete :: Text -> Query ()
+delete userEmail =
Query (\conn ->
SQLite.execute conn "DELETE FROM user WHERE email = ?" (Only userEmail)
)