diff --git a/src/Lisa.hs b/src/Lisa.hs index de3194d..2722b2e 100644 --- a/src/Lisa.hs +++ b/src/Lisa.hs @@ -4,8 +4,13 @@ module Lisa ( app ) where -import Web.Scotty (ScottyM, get, html) +import Data.Maybe (fromMaybe) +import Web.Scotty (ScottyM, get, html, param, rescue) app :: ScottyM () -app = get "/" $ do - html "

It works!

" +app = do + get "/" $ do + html "

It works!

" + get "/lectures/search" $ do + query <- param "query" + html $ "
" diff --git a/src/Lisa/Squeak.hs b/src/Lisa/Squeak.hs index 44fff66..06f332e 100644 --- a/src/Lisa/Squeak.hs +++ b/src/Lisa/Squeak.hs @@ -74,9 +74,17 @@ instance FromJSON Faculty where <$> v .: "id" <*> v .: "displayName" +data Lectures = Lectures { unLectures :: [Lecture] } + deriving (Show) + +instance FromJSON Lectures where + parseJSON = withObject "Lectures" $ \v -> Lectures + <$> v .: "lectures" + data Lecture = Lecture { lectureId :: Text , lectureDisplayName :: Text + , lectureAliases :: [Text] } deriving (Show) @@ -84,9 +92,14 @@ instance FromJSON Lecture where parseJSON = withObject "Lecture" $ \v -> Lecture <$> v .: "id" <*> v .: "displayName" + <*> v .: "aliases" serverUrl = https "api.squeak-test.fsmi.uni-karlsruhe.de" +getLectures :: Req (GQLReply Lectures) +getLectures = responseBody <$> req POST serverUrl (ReqBodyJson $ GQLQuery q) jsonResponse mempty + where q = "{ lectures { id displayName aliases } }" + getDocuments :: Req (GQLReply Documents) getDocuments = responseBody <$> req POST serverUrl (ReqBodyJson $ GQLQuery q) jsonResponse mempty where q = "{ documents(filters: []) { results { id date semester publicComment downloadable faculty { id displayName } lectures { id displayName } } } }"