1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | {-# LANGUAGE DeriveGeneric #-} module Models ( Character(..) , Comment(..) , User(..) , UserAuth(..) , Session(..) , Story(..) , StoriesLimit(..) , StoryResp(..) ) where import Database.SQLite.Simple (FromRow, fromRow, ToRow, toRow, field) import Data.Time.Clock import Data.Text import GHC.Generics (Generic) import Data.Aeson (ToJSON, FromJSON) data Character = Character { id :: Text , userId :: Text , name :: Text , description :: Text , createdAt :: UTCTime } instance FromRow Character where fromRow = Character <$> field <*> field <*> field <*> field <*> field data StoryResp = StoryResp { title :: Text , summary :: Text , story :: Text } deriving (Generic) instance ToJSON StoryResp where instance FromJSON StoryResp where data Story = Story { id :: Text , promptId :: Text , userId :: Text , title :: Text , summary :: Text , story :: Text , createdAt :: UTCTime } instance FromRow Story where fromRow = Story <$> field <*> field <*> field <*> field <*> field <*> field <*> field data StoriesLimit = StoriesLimit { count :: Int } instance FromRow StoriesLimit where fromRow = StoriesLimit <$> field data Comment = Comment { id :: Text , author :: Text , storyId :: Text , text :: Text , createdAt :: UTCTime } instance FromRow Comment where fromRow = Comment <$> field <*> field <*> field <*> field <*> field data User = User { id :: Text , username :: Text , hashPass :: Text , paid :: Bool , createdAt :: UTCTime } instance FromRow User where fromRow = User <$> field <*> field <*> field <*> field <*> field instance ToRow User where toRow user = toRow (user.id, user.username, user.hashPass, user.createdAt) data UserAuth = UserAuth { id :: Text , hashPass :: Text } instance FromRow UserAuth where fromRow = UserAuth <$> field <*> field data Session = Session { token :: Text , userId :: Text , createdAt :: UTCTime } instance FromRow Session where fromRow = Session <$> field <*> field <*> field instance ToRow Session where toRow session = toRow (session.token, session.userId, session.createdAt) |