Skip to content

Commit

Permalink
more better types
Browse files Browse the repository at this point in the history
  • Loading branch information
zachary822 committed Nov 29, 2023
1 parent fd5c565 commit 67b3485
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions app/Lib/Types.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Lib.Types where

import Control.Monad.Trans.Reader
import Data.Bifunctor
import Data.Pool
import Data.Text (Text)
import Data.Time.Calendar.Month
import Data.Time.Clock
import Database.MongoDB
import Database.MongoDB hiding (Oid)
import Database.MongoDB qualified as M
import GHC.Generics
import Web.Scotty.Trans
Expand All @@ -23,8 +23,10 @@ type ConfigReader = ReaderT Config IO
type ScottyM = ScottyT ConfigReader
type ActionM = ActionT ConfigReader

instance Parsable ObjectId where
parseParam = readEither
newtype Oid = Oid ObjectId

instance Parsable Oid where
parseParam = second Oid . readEither

class FromDocument a where
fromDocument :: Document -> a
Expand Down
4 changes: 2 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Data.Text qualified as T
import Data.Time.Calendar.Month
import Data.Time.Format
import Data.Time.Format.ISO8601
import Database.MongoDB
import Database.MongoDB hiding (Oid)
import Database.MongoDB qualified as M
import Lib.Blaze
import Lib.Database
Expand Down Expand Up @@ -261,7 +261,7 @@ main = do
$ fromString (show o)

get "/posts/:pid" $ do
pid :: ObjectId <- captureParam "pid"
Oid pid <- captureParam "pid"

runDb
"blog"
Expand Down

0 comments on commit 67b3485

Please sign in to comment.