Skip to content

Commit

Permalink
Use new instances
Browse files Browse the repository at this point in the history
  • Loading branch information
tchoutri committed Jan 30, 2025
1 parent 4140e42 commit a1a2ab2
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/web/FloraWeb/Pages/Routes/Sessions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module FloraWeb.Pages.Routes.Sessions where

import Data.Text
import Generics.SOP (I (..), NP (..), NS (..))
import Generics.SOP qualified as GSOP
import Lucid
import Servant.API
import Servant.API.ContentTypes.Lucid
Expand All @@ -14,6 +15,10 @@ import Web.FormUrlEncoded

import Flora.Model.PersistentSession

instance AsConstructor '[r] (WithHeaders hs r (RespondEmpty code desc)) where
toConstructor x = I x :* Nil
fromConstructor (I x :* Nil) = x

type Routes = NamedRoutes Routes'

type NewSession =
Expand All @@ -39,17 +44,24 @@ data NewSessionResult
| AuthenticationRequired (Html ())
deriving stock (Generic)

instance AsUnion NewSessionResponses NewSessionResult where
toUnion (AlreadyAuthenticated location) = Z (I ((), location))
toUnion (AuthenticationRequired response) = S (Z (I response))
instance GSOP.Generic NewSessionResult

deriving via

Check failure on line 49 in src/web/FloraWeb/Pages/Routes/Sessions.hs

View workflow job for this annotation

GitHub Actions / Backend_tests (9.6.6, ubuntu-22.04)

• No instance for ‘AsConstructor

Check failure on line 49 in src/web/FloraWeb/Pages/Routes/Sessions.hs

View workflow job for this annotation

GitHub Actions / Backend_tests (9.6.6, ubuntu-22.04)

• No instance for ‘AsConstructor
GenericAsUnion NewSessionResponses NewSessionResult
instance
AsUnion NewSessionResponses NewSessionResult

fromUnion (Z (I ((), location))) = AlreadyAuthenticated location
fromUnion (S (Z (I response))) = AuthenticationRequired response
fromUnion (S (S x)) = case x of {}
-- instance AsUnion NewSessionResponses NewSessionResult where
-- toUnion (AlreadyAuthenticated location) = Z (I ((), location))
-- toUnion (AuthenticationRequired response) = S (Z (I response))
--
-- fromUnion (Z (I ((), location))) = AlreadyAuthenticated location
-- fromUnion (S (Z (I response))) = AuthenticationRequired response
-- fromUnion (S (S x)) = case x of {}

instance AsHeaders '[Text, SetCookie] () (Text, SetCookie) where
toHeaders (location, cookie) = (I location :* I cookie :* Nil, ())
fromHeaders (I location :* I cookie :* Nil, ()) = (location, cookie)
-- instance AsHeaders '[Text, SetCookie] () (Text, SetCookie) where
-- toHeaders (location, cookie) = (I location :* I cookie :* Nil, ())
-- fromHeaders (I location :* I cookie :* Nil, ()) = (location, cookie)

type CreateSession =
"new"
Expand All @@ -75,13 +87,12 @@ data CreateSessionResult
| AuthenticationSuccess (Text, SetCookie)
deriving stock (Generic)

instance AsUnion CreateSessionResponses CreateSessionResult where
toUnion (AuthenticationFailure body) = Z (I body)
toUnion (AuthenticationSuccess (location, cookie)) = S (Z (I (location, cookie)))
instance GSOP.Generic CreateSessionResult

fromUnion (Z (I body)) = AuthenticationFailure body
fromUnion (S (Z (I headers))) = AuthenticationSuccess headers
fromUnion (S (S x)) = case x of {}
deriving via
GenericAsUnion CreateSessionResponses CreateSessionResult
instance
AsUnion CreateSessionResponses CreateSessionResult

type DeleteSession =
"delete"
Expand Down

0 comments on commit a1a2ab2

Please sign in to comment.