Add orders route

This commit is contained in:
2022-09-21 23:40:06 +02:00
parent 6763d3ffa1
commit 98ef505453
3 changed files with 42 additions and 3 deletions
+20 -2
View File
@@ -11,6 +11,7 @@ import Data.Aeson (FromJSON(parseJSON), Options(fieldLabelModifier), ToJSON(toJS
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import Data.Time.Calendar (Day)
import Data.Time.LocalTime (ZonedTime)
import GHC.Generics (Generic)
import Network.HTTP.Req (Option, Scheme(..), POST(..), ReqBodyJson(..), Url, defaultHttpConfig, header, http, port, jsonResponse, responseBody, req, runReq)
@@ -102,6 +103,13 @@ instance FromJSON Documents where
parseJSON = withObject "Documents" $ \v -> Documents
<$> ((v .: "documents") >>= (.: "results"))
data Orders = Orders { unOrders :: [Order] }
deriving (Show)
instance FromJSON Orders where
parseJSON = withObject "Orders" $ \v -> Orders
<$> ((v .: "orders") >>= (.: "results"))
-- | Helper for automatically writing 'FromJSON' instances.
--
-- >>> removePrefixModifier "document" "documentId"
@@ -182,12 +190,20 @@ getDocumentsByLectureId :: (SqueakCtx m, MonadIO m) => Text -> m (Either SqueakE
getDocumentsByLectureId lecture = fmap unDocuments <$> joinErrors <$> mkQueryWithVars
(object ["lecture" .= lecture])
"query DocumentsByLectureId($lecture: LectureId!) \
\ { documents(filters: [{ lectures: [$lecture] }]) \
\{ documents(filters: [{ lectures: [$lecture] }]) \
\ { results \
\ { id date semester publicComment downloadable faculty { id displayName } lectures { id displayName aliases } type numPages } \
\ } \
\}"
getAllPendingOrders :: (SqueakCtx m, MonadIO m) => m (Either SqueakError [Order])
getAllPendingOrders = fmap unOrders <$> joinErrors <$> mkQuery
"{ orders(filters: {state: PENDING}) \
\ { results \
\ { id created numPages price tag } \
\ } \
\}"
-- Mutations
data LoginResult = LoginResult { unLoginResult :: SqueakErrorOr Credentials }
@@ -255,8 +271,10 @@ instance (FromJSON CreateOrderResult) where
data Order = Order
{ orderId :: Text
, orderTag :: Text
, orderCreated :: ZonedTime
, orderNumPages :: Int
, orderPrice :: Double
, orderTag :: Text
}
deriving (Generic, Show)