Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
157
Issues
157
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
a372e1c6
Commit
a372e1c6
authored
Mar 11, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SERVER AUTH MONAD] question: how to simplify the type.
parent
18127e38
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
19 deletions
+17
-19
Foundation.hs
src/Gargantext/API/Foundation.hs
+17
-19
No files found.
src/Gargantext/API/Foundation.hs
View file @
a372e1c6
...
...
@@ -46,6 +46,7 @@ import Control.Monad.Trans.Resource
-- import Control.Natural ((:~>))
import
Data.Maybe
import
Data.Text
(
Text
)
-- import Database.PostgreSQL.Simple
import
Servant
...
...
@@ -100,36 +101,33 @@ runDB _ = undefined {- access pool from env, run action -}
-- | very basic Example for testing purpose
-- type MyAPI = TeamAPI -- :<|> UserAPI :<|> ...
type
TeamAPI
=
GetUserRoute
-- :<|>
type
GetUserRoute
=
"
team"
:>
Capture
"teamkey"
Int
:>
Get
'[
J
SON
]
In
t
--type GetTeamRoute = "team" :> Capture "teamkey" TeamKey :> Get '[JSON] Team
type
TeamAPI
=
GetUserRoute
:<|>
GetTeamRoute
type
GetUserRoute
=
"
user"
:>
Capture
"userkey"
Int
:>
Get
'[
J
SON
]
Tex
t
type
GetTeamRoute
=
"team"
:>
Capture
"teamkey"
Int
:>
Get
'[
J
SON
]
Int
myServerAPI
::
Proxy
TeamAPI
myServerAPI
=
Proxy
--gargServer' :: ServerT MyAPI MyServer
--gargServer' = teamServer
teamServer
::
ServerT
TeamAPI
MyServer
teamServer
=
get
TeamR
-- :<|> createTeamR :<|> updateTeamR :<|> getAllTeamsR
teamServer
=
get
UserR
:<|>
getTeamR
getTeamR
::
Int
->
MyServer
Int
getTeamR
_
=
do
pure
1
getUserR
::
Int
->
MyServer
Text
getUserR
_
=
pure
"name"
---- Note that @type MyAPIWithAuth = JwtAuthHeader :> MyAPI@ so that
---- @Server MyAPIWithAuth@ expands to @Maybe UnverifiedJwtToken -> Server MyAPI@.
--myServerWithAuth :: Env -> Server MyAPIWithAuth
----myServerWithAuth env unverifiedJwt = enter (myServerNat env unverifiedJwt) myServer
--myServerWithAuth :: forall a. Env -> Maybe UnverifiedJwtToken -> ServerT (MyServer a) Handler
getTeamR
::
Int
->
MyServer
Int
getTeamR
_
=
pure
1
myServerWithAuth
::
Env
->
Maybe
UnverifiedJwtToken
->
Int
->
Handler
Int
-- Question: how to simplify the type here (and automatically generate it) ?
myServerWithAuth
::
Env
->
Maybe
UnverifiedJwtToken
->
(
Int
->
ExceptT
ServantErr
IO
Text
)
:<|>
(
Int
->
ExceptT
ServantErr
IO
Int
)
myServerWithAuth
env
unverifiedJwt
=
hoistServer
myServerAPI
(
nt
env
unverifiedJwt
)
teamServer
-- nt :: Applicative f => Env -> p -> MyServer a -> f (ExceptT ServantErr IO a)
nt
::
Env
->
Maybe
UnverifiedJwtToken
->
MyServer
a
->
Handler
(
ExceptT
ServantErr
IO
a
)
nt
env
_
s
=
pure
$
runResourceT
(
runReaderT
(
myServerM
s
)
(
env
,
mtoken'
))
nt
::
Env
->
Maybe
UnverifiedJwtToken
->
MyServer
a
->
ExceptT
ServantErr
IO
a
nt
env
_
s
=
runResourceT
(
runReaderT
(
myServerM
s
)
(
env
,
mtoken'
))
where
mtoken'
::
Maybe
Token
mtoken'
=
undefined
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment