{-# LANGUAGE OverloadedLabels #-}

module WikiMusic.SSR.Servant.ArtistRoutes
  ( artistsRoute,
    artistRoute,
    artistCreateRoute,
    artistCreateFormRoute,
    artistLikeRoute,
    artistDislikeRoute,
  )
where

import Control.Monad.Error.Class
import Data.ByteString.Lazy qualified as BL
import Data.Text qualified as T
import Data.UUID (UUID)
import Free.AlaCarte
import Optics
import Relude
import Servant
import Servant.Multipart
import Text.Blaze.Html as Html
import WikiMusic.Interaction.Model.Artist
import WikiMusic.Model.Other
import WikiMusic.SSR.Backend.Rest ()
import WikiMusic.SSR.Free.Backend
import WikiMusic.SSR.Free.View
import WikiMusic.SSR.Model.Api
import WikiMusic.SSR.Model.Env
import WikiMusic.SSR.Servant.Utilities
import WikiMusic.SSR.View.Html ()

artistsRoute :: (MonadIO m) => Env -> Maybe Text -> Maybe Text -> Maybe Int -> Maybe Int -> m Html
artistsRoute :: forall (m :: * -> *).
MonadIO m =>
Env -> Maybe Text -> Maybe Text -> Maybe Int -> Maybe Int -> m Html
artistsRoute Env
env Maybe Text
cookie Maybe Text
givenSortOrder Maybe Int
limit Maybe Int
offset = do
  Either Text GetArtistsQueryResponse
maybeArtists <-
    IO (Either Text GetArtistsQueryResponse)
-> m (Either Text GetArtistsQueryResponse)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO (Either Text GetArtistsQueryResponse)
 -> m (Either Text GetArtistsQueryResponse))
-> IO (Either Text GetArtistsQueryResponse)
-> m (Either Text GetArtistsQueryResponse)
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @Backend
        ( Env
-> AuthToken
-> Limit
-> Offset
-> SortOrder
-> Include
-> Free Backend (Either Text GetArtistsQueryResponse)
forall (f :: * -> *).
(Backend :<: f) =>
Env
-> AuthToken
-> Limit
-> Offset
-> SortOrder
-> Include
-> Free f (Either Text GetArtistsQueryResponse)
getArtists
            Env
env
            (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars AuthToken -> AuthToken
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars AuthToken
#authToken)
            (Limit -> (Int -> Limit) -> Maybe Int -> Limit
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Int -> Limit
Limit Int
50) Int -> Limit
Limit Maybe Int
limit)
            (Offset -> (Int -> Offset) -> Maybe Int -> Offset
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Int -> Offset
Offset Int
0) Int -> Offset
Offset Maybe Int
offset)
            SortOrder
sortOrder
            (Include {$sel:value:Include :: Text
value = Text
"artworks,comments,opinions"})
        )
  Env
-> UiMode
-> Language
-> Palette
-> Either Text GetArtistsQueryResponse
-> (GetArtistsQueryResponse -> IO Html)
-> m Html
forall (m :: * -> *) t.
MonadIO m =>
Env
-> UiMode
-> Language
-> Palette
-> Either Text t
-> (t -> IO Html)
-> m Html
eitherView
    Env
env
    (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars UiMode -> UiMode
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars UiMode
#uiMode)
    (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Language -> Language
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Language
#locale)
    (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Palette -> Palette
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Palette
#palette)
    Either Text GetArtistsQueryResponse
maybeArtists
    (forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @View (Free View Html -> IO Html)
-> (GetArtistsQueryResponse -> Free View Html)
-> GetArtistsQueryResponse
-> IO Html
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Env
-> UiMode
-> Language
-> Palette
-> SortOrder
-> GetArtistsQueryResponse
-> Free View Html
forall (f :: * -> *).
(View :<: f) =>
Env
-> UiMode
-> Language
-> Palette
-> SortOrder
-> GetArtistsQueryResponse
-> Free f Html
artistListPage Env
env (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars UiMode -> UiMode
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars UiMode
#uiMode) (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Language -> Language
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Language
#locale) (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Palette -> Palette
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Palette
#palette) SortOrder
sortOrder)
  where
    viewVars :: ViewVars
viewVars = Maybe Text -> ViewVars
viewVarsFromCookies Maybe Text
cookie
    sortOrder :: SortOrder
sortOrder = SortOrder -> (Text -> SortOrder) -> Maybe Text -> SortOrder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars SortOrder -> SortOrder
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars SortOrder
#artistSorting) Text -> SortOrder
SortOrder Maybe Text
givenSortOrder

artistRoute :: (MonadIO m) => Env -> Maybe Text -> UUID -> m Html
artistRoute :: forall (m :: * -> *).
MonadIO m =>
Env -> Maybe Text -> UUID -> m Html
artistRoute Env
env Maybe Text
cookie UUID
identifier = do
  Either Text GetArtistsQueryResponse
maybeArtists <-
    IO (Either Text GetArtistsQueryResponse)
-> m (Either Text GetArtistsQueryResponse)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO (Either Text GetArtistsQueryResponse)
 -> m (Either Text GetArtistsQueryResponse))
-> IO (Either Text GetArtistsQueryResponse)
-> m (Either Text GetArtistsQueryResponse)
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @Backend
        ( Env
-> AuthToken
-> UUID
-> Include
-> Free Backend (Either Text GetArtistsQueryResponse)
forall (f :: * -> *).
(Backend :<: f) =>
Env
-> AuthToken
-> UUID
-> Include
-> Free f (Either Text GetArtistsQueryResponse)
getArtist
            Env
env
            (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars AuthToken -> AuthToken
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars AuthToken
#authToken)
            UUID
identifier
            (Include {$sel:value:Include :: Text
value = Text
"artworks,comments,opinions"})
        )
  Env
-> UiMode
-> Language
-> Palette
-> Either Text GetArtistsQueryResponse
-> (GetArtistsQueryResponse -> IO Html)
-> m Html
forall (m :: * -> *) t.
MonadIO m =>
Env
-> UiMode
-> Language
-> Palette
-> Either Text t
-> (t -> IO Html)
-> m Html
eitherView
    Env
env
    (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars UiMode -> UiMode
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars UiMode
#uiMode)
    (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Language -> Language
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Language
#locale)
    (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Palette -> Palette
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Palette
#palette)
    Either Text GetArtistsQueryResponse
maybeArtists
    (forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @View (Free View Html -> IO Html)
-> (GetArtistsQueryResponse -> Free View Html)
-> GetArtistsQueryResponse
-> IO Html
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Env
-> UiMode
-> Language
-> Palette
-> GetArtistsQueryResponse
-> Free View Html
forall (f :: * -> *).
(View :<: f) =>
Env
-> UiMode
-> Language
-> Palette
-> GetArtistsQueryResponse
-> Free f Html
artistDetailPage Env
env (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars UiMode -> UiMode
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars UiMode
#uiMode) (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Language -> Language
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Language
#locale) (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Palette -> Palette
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Palette
#palette))
  where
    viewVars :: ViewVars
viewVars = Maybe Text -> ViewVars
viewVarsFromCookies Maybe Text
cookie

artistCreateRoute :: (MonadIO m) => Env -> Maybe Text -> m Html
artistCreateRoute :: forall (m :: * -> *). MonadIO m => Env -> Maybe Text -> m Html
artistCreateRoute Env
env Maybe Text
cookie = do
  IO Html -> m Html
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Html -> m Html) -> IO Html -> m Html
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @View (Env -> UiMode -> Language -> Palette -> Free View Html
forall (f :: * -> *).
(View :<: f) =>
Env -> UiMode -> Language -> Palette -> Free f Html
artistCreatePage Env
env (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars UiMode -> UiMode
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars UiMode
#uiMode) (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Language -> Language
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Language
#locale) (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars Palette -> Palette
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars Palette
#palette))
  where
    viewVars :: ViewVars
viewVars = Maybe Text -> ViewVars
viewVarsFromCookies Maybe Text
cookie

artistCreateFormRoute :: (MonadIO m, MonadError ServerError m) => Env -> Maybe Text -> MultipartData tag -> m a
artistCreateFormRoute :: forall (m :: * -> *) tag a.
(MonadIO m, MonadError ServerError m) =>
Env -> Maybe Text -> MultipartData tag -> m a
artistCreateFormRoute Env
env Maybe Text
cookie MultipartData tag
multipartData = do
  Either Text InsertArtistsCommandResponse
createResult <- IO (Either Text InsertArtistsCommandResponse)
-> m (Either Text InsertArtistsCommandResponse)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either Text InsertArtistsCommandResponse)
 -> m (Either Text InsertArtistsCommandResponse))
-> IO (Either Text InsertArtistsCommandResponse)
-> m (Either Text InsertArtistsCommandResponse)
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @Backend (Env
-> AuthToken
-> InsertArtistsRequest
-> Free Backend (Either Text InsertArtistsCommandResponse)
forall (f :: * -> *).
(Backend :<: f) =>
Env
-> AuthToken
-> InsertArtistsRequest
-> Free f (Either Text InsertArtistsCommandResponse)
createArtist Env
env (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars AuthToken -> AuthToken
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars AuthToken
#authToken) InsertArtistsRequest
r)
  ()
_ <- IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BL.putStr (String -> ByteString
forall a. IsString a => String -> a
fromString (String -> ByteString)
-> (Either Text InsertArtistsCommandResponse -> String)
-> Either Text InsertArtistsCommandResponse
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Text InsertArtistsCommandResponse -> String
forall b a. (Show a, IsString b) => a -> b
show (Either Text InsertArtistsCommandResponse -> ByteString)
-> Either Text InsertArtistsCommandResponse -> ByteString
forall a b. (a -> b) -> a -> b
$ Either Text InsertArtistsCommandResponse
createResult)
  ServerError -> m a
forall a. ServerError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
    (ServerError -> m a) -> ServerError -> m a
forall a b. (a -> b) -> a -> b
$ ServerError
      { errHTTPCode :: Int
errHTTPCode = Int
302,
        errReasonPhrase :: String
errReasonPhrase = String
"Found",
        errBody :: ByteString
errBody = ByteString
"",
        errHeaders :: [Header]
errHeaders =
          [(HeaderName
"Location", ByteString
"/artists")]
      }
  where
    viewVars :: ViewVars
viewVars = Maybe Text -> ViewVars
viewVarsFromCookies Maybe Text
cookie
    r :: InsertArtistsRequest
r =
      InsertArtistsRequest
        { $sel:artists:InsertArtistsRequest :: [InsertArtistsRequestItem]
artists =
            [ InsertArtistsRequestItem
                { $sel:displayName:InsertArtistsRequestItem :: Text
displayName = MultipartData tag -> Text -> Text -> Text
forall tag. MultipartData tag -> Text -> Text -> Text
fromForm MultipartData tag
multipartData Text
"" Text
"displayName",
                  $sel:spotifyUrl:InsertArtistsRequestItem :: Maybe Text
spotifyUrl = MultipartData tag -> Text -> Maybe Text
forall tag. MultipartData tag -> Text -> Maybe Text
maybeFromForm MultipartData tag
multipartData Text
"spotifyUrl",
                  $sel:youtubeUrl:InsertArtistsRequestItem :: Maybe Text
youtubeUrl = MultipartData tag -> Text -> Maybe Text
forall tag. MultipartData tag -> Text -> Maybe Text
maybeFromForm MultipartData tag
multipartData Text
"youtubeUrl",
                  $sel:soundcloudUrl:InsertArtistsRequestItem :: Maybe Text
soundcloudUrl = MultipartData tag -> Text -> Maybe Text
forall tag. MultipartData tag -> Text -> Maybe Text
maybeFromForm MultipartData tag
multipartData Text
"soundcloudUrl",
                  $sel:wikipediaUrl:InsertArtistsRequestItem :: Maybe Text
wikipediaUrl = MultipartData tag -> Text -> Maybe Text
forall tag. MultipartData tag -> Text -> Maybe Text
maybeFromForm MultipartData tag
multipartData Text
"wikipediaUrl",
                  $sel:description:InsertArtistsRequestItem :: Maybe Text
description = MultipartData tag -> Text -> Maybe Text
forall tag. MultipartData tag -> Text -> Maybe Text
maybeFromForm MultipartData tag
multipartData Text
"description"
                }
            ]
        }

artistLikeRoute :: (MonadIO m, MonadError ServerError m) => Env -> Maybe Text -> Maybe Text -> UUID -> m a
artistLikeRoute :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
Env -> Maybe Text -> Maybe Text -> UUID -> m a
artistLikeRoute Env
env Maybe Text
cookie Maybe Text
maybeReferer UUID
identifier = do
  Either Text UpsertArtistOpinionsCommandResponse
res <- IO (Either Text UpsertArtistOpinionsCommandResponse)
-> m (Either Text UpsertArtistOpinionsCommandResponse)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either Text UpsertArtistOpinionsCommandResponse)
 -> m (Either Text UpsertArtistOpinionsCommandResponse))
-> IO (Either Text UpsertArtistOpinionsCommandResponse)
-> m (Either Text UpsertArtistOpinionsCommandResponse)
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @Backend (Env
-> AuthToken
-> UpsertArtistOpinionsRequest
-> Free Backend (Either Text UpsertArtistOpinionsCommandResponse)
forall (f :: * -> *).
(Backend :<: f) =>
Env
-> AuthToken
-> UpsertArtistOpinionsRequest
-> Free f (Either Text UpsertArtistOpinionsCommandResponse)
upsertArtistOpinion Env
env (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars AuthToken -> AuthToken
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars AuthToken
#authToken) UpsertArtistOpinionsRequest
r)
  ()
_ <- IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BL.putStr (String -> ByteString
forall a. IsString a => String -> a
fromString (String -> ByteString)
-> (Either Text UpsertArtistOpinionsCommandResponse -> String)
-> Either Text UpsertArtistOpinionsCommandResponse
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Text UpsertArtistOpinionsCommandResponse -> String
forall b a. (Show a, IsString b) => a -> b
show (Either Text UpsertArtistOpinionsCommandResponse -> ByteString)
-> Either Text UpsertArtistOpinionsCommandResponse -> ByteString
forall a b. (a -> b) -> a -> b
$ Either Text UpsertArtistOpinionsCommandResponse
res)
  ServerError -> m a
forall a. ServerError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
    (ServerError -> m a) -> ServerError -> m a
forall a b. (a -> b) -> a -> b
$ ServerError
      { errHTTPCode :: Int
errHTTPCode = Int
302,
        errReasonPhrase :: String
errReasonPhrase = String
"Found",
        errBody :: ByteString
errBody = ByteString
"",
        errHeaders :: [Header]
errHeaders =
          [(HeaderName
"Location", String -> ByteString
forall a. IsString a => String -> a
fromString (String -> ByteString) -> (Text -> String) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"/artists" Maybe Text
maybeReferer)]
      }
  where
    viewVars :: ViewVars
viewVars = Maybe Text -> ViewVars
viewVarsFromCookies Maybe Text
cookie
    r :: UpsertArtistOpinionsRequest
r =
      UpsertArtistOpinionsRequest
        { $sel:artistOpinions:UpsertArtistOpinionsRequest :: [UpsertArtistOpinionsRequestItem]
artistOpinions =
            [ UpsertArtistOpinionsRequestItem
                { $sel:artistIdentifier:UpsertArtistOpinionsRequestItem :: UUID
artistIdentifier = UUID
identifier,
                  $sel:isLike:UpsertArtistOpinionsRequestItem :: Bool
isLike = Bool
True
                }
            ]
        }

artistDislikeRoute :: (MonadIO m, MonadError ServerError m) => Env -> Maybe Text -> Maybe Text -> UUID -> m a
artistDislikeRoute :: forall (m :: * -> *) a.
(MonadIO m, MonadError ServerError m) =>
Env -> Maybe Text -> Maybe Text -> UUID -> m a
artistDislikeRoute Env
env Maybe Text
cookie Maybe Text
maybeReferer UUID
identifier = do
  Either Text UpsertArtistOpinionsCommandResponse
res <- IO (Either Text UpsertArtistOpinionsCommandResponse)
-> m (Either Text UpsertArtistOpinionsCommandResponse)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either Text UpsertArtistOpinionsCommandResponse)
 -> m (Either Text UpsertArtistOpinionsCommandResponse))
-> IO (Either Text UpsertArtistOpinionsCommandResponse)
-> m (Either Text UpsertArtistOpinionsCommandResponse)
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @Backend (Env
-> AuthToken
-> UpsertArtistOpinionsRequest
-> Free Backend (Either Text UpsertArtistOpinionsCommandResponse)
forall (f :: * -> *).
(Backend :<: f) =>
Env
-> AuthToken
-> UpsertArtistOpinionsRequest
-> Free f (Either Text UpsertArtistOpinionsCommandResponse)
upsertArtistOpinion Env
env (ViewVars
viewVars ViewVars -> Optic' A_Lens NoIx ViewVars AuthToken -> AuthToken
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ViewVars AuthToken
#authToken) UpsertArtistOpinionsRequest
r)
  ()
_ <- IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ ByteString -> IO ()
BL.putStr (String -> ByteString
forall a. IsString a => String -> a
fromString (String -> ByteString)
-> (Either Text UpsertArtistOpinionsCommandResponse -> String)
-> Either Text UpsertArtistOpinionsCommandResponse
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Text UpsertArtistOpinionsCommandResponse -> String
forall b a. (Show a, IsString b) => a -> b
show (Either Text UpsertArtistOpinionsCommandResponse -> ByteString)
-> Either Text UpsertArtistOpinionsCommandResponse -> ByteString
forall a b. (a -> b) -> a -> b
$ Either Text UpsertArtistOpinionsCommandResponse
res)
  ServerError -> m a
forall a. ServerError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
    (ServerError -> m a) -> ServerError -> m a
forall a b. (a -> b) -> a -> b
$ ServerError
      { errHTTPCode :: Int
errHTTPCode = Int
302,
        errReasonPhrase :: String
errReasonPhrase = String
"Found",
        errBody :: ByteString
errBody = ByteString
"",
        errHeaders :: [Header]
errHeaders =
          [(HeaderName
"Location", String -> ByteString
forall a. IsString a => String -> a
fromString (String -> ByteString) -> (Text -> String) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"/artists" Maybe Text
maybeReferer)]
      }
  where
    viewVars :: ViewVars
viewVars = Maybe Text -> ViewVars
viewVarsFromCookies Maybe Text
cookie
    r :: UpsertArtistOpinionsRequest
r =
      UpsertArtistOpinionsRequest
        { $sel:artistOpinions:UpsertArtistOpinionsRequest :: [UpsertArtistOpinionsRequestItem]
artistOpinions =
            [ UpsertArtistOpinionsRequestItem
                { $sel:artistIdentifier:UpsertArtistOpinionsRequestItem :: UUID
artistIdentifier = UUID
identifier,
                  $sel:isLike:UpsertArtistOpinionsRequestItem :: Bool
isLike = Bool
False
                }
            ]
        }