{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module WikiMusic.Sqlite.ArtistCommand () where

import Data.Map qualified as Map
import Data.UUID qualified as UUID
import Database.Beam
import Database.Beam.Sqlite
import Relude
import WikiMusic.Beam.Artist
import WikiMusic.Beam.Database
import WikiMusic.Free.ArtistCommand
import WikiMusic.Interaction.Model.Artist
import WikiMusic.Model.Artist
import WikiMusic.Model.Artwork
import WikiMusic.Model.Comment
import WikiMusic.Model.Opinion
import WikiMusic.Protolude

insertArtists' :: (MonadIO m) => Env -> [Artist] -> m ()
insertArtists' :: forall (m :: * -> *). MonadIO m => Env -> [Artist] -> m ()
insertArtists' Env
env [Artist]
artists = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any)) -> IO ())
-> SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite ArtistT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite ArtistT -> SqliteM ())
-> (SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any))
    -> SqlInsert Sqlite ArtistT)
-> SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any))
-> SqlInsert Sqlite ArtistT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any)) -> m ())
-> SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any)) -> m ()
forall a b. (a -> b) -> a -> b
$ [ArtistT Identity]
-> SqlInsertValues Sqlite (ArtistT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((Artist -> ArtistT Identity) -> [Artist] -> [ArtistT Identity]
forall a b. (a -> b) -> [a] -> [b]
map Artist -> ArtistT Identity
toPersistenceArtist [Artist]
artists)

  [ArtistExternalSourcesT Identity]
externalContents <-
    (Artist -> m (ArtistExternalSourcesT Identity))
-> [Artist] -> m [ArtistExternalSourcesT Identity]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM
      ( \Artist
s -> do
          UUID
newIdentifier <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
          ArtistExternalSourcesT Identity
-> m (ArtistExternalSourcesT Identity)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ArtistExternalSourcesT Identity
 -> m (ArtistExternalSourcesT Identity))
-> ArtistExternalSourcesT Identity
-> m (ArtistExternalSourcesT Identity)
forall a b. (a -> b) -> a -> b
$ Artist -> UUID -> ArtistExternalSourcesT Identity
toPersistenceArtistExternalContents Artist
s UUID
newIdentifier
      )
      [Artist]
artists
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues
      Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlInsertValues
      Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite ArtistExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite ArtistExternalSourcesT -> SqliteM ())
-> (SqlInsertValues
      Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
    -> SqlInsert Sqlite ArtistExternalSourcesT)
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> SqlInsert Sqlite ArtistExternalSourcesT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
#artistExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
 -> m ())
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [ArtistExternalSourcesT Identity]
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues [ArtistExternalSourcesT Identity]
externalContents

insertArtistComments' :: (MonadIO m) => Env -> [ArtistComment] -> m ()
insertArtistComments' :: forall (m :: * -> *). MonadIO m => Env -> [ArtistComment] -> m ()
insertArtistComments' Env
env [ArtistComment]
comments = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite ArtistCommentT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite ArtistCommentT -> SqliteM ())
-> (SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
    -> SqlInsert Sqlite ArtistCommentT)
-> SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
-> SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
-> SqlInsert Sqlite ArtistCommentT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
#artistComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
 -> m ())
-> SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [ArtistCommentT Identity]
-> SqlInsertValues Sqlite (ArtistCommentT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((ArtistComment -> ArtistCommentT Identity)
-> [ArtistComment] -> [ArtistCommentT Identity]
forall a b. (a -> b) -> [a] -> [b]
map ArtistComment -> ArtistCommentT Identity
toPersistenceArtistComment [ArtistComment]
comments)

insertArtistExternalSources' :: (MonadIO m) => Env -> [ArtistExternalSources] -> m (Map UUID ArtistExternalSources)
insertArtistExternalSources' :: forall (m :: * -> *).
MonadIO m =>
Env
-> [ArtistExternalSources] -> m (Map UUID ArtistExternalSources)
insertArtistExternalSources' Env
env [ArtistExternalSources]
externalSources = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues
      Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlInsertValues
      Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite ArtistExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite ArtistExternalSourcesT -> SqliteM ())
-> (SqlInsertValues
      Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
    -> SqlInsert Sqlite ArtistExternalSourcesT)
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> SqlInsert Sqlite ArtistExternalSourcesT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
#artistExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
 -> m ())
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [ArtistExternalSourcesT Identity]
-> SqlInsertValues
     Sqlite (ArtistExternalSourcesT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((ArtistExternalSources -> ArtistExternalSourcesT Identity)
-> [ArtistExternalSources] -> [ArtistExternalSourcesT Identity]
forall a b. (a -> b) -> [a] -> [b]
map ArtistExternalSources -> ArtistExternalSourcesT Identity
mkArtistExSourcesP [ArtistExternalSources]
externalSources)
  Map UUID ArtistExternalSources
-> m (Map UUID ArtistExternalSources)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID ArtistExternalSources
forall k a. Map k a
Map.empty

insertArtistArtworks' :: (MonadIO m) => Env -> [ArtistArtwork] -> m (Map UUID ArtistArtwork)
insertArtistArtworks' :: forall (m :: * -> *).
MonadIO m =>
Env -> [ArtistArtwork] -> m (Map UUID ArtistArtwork)
insertArtistArtworks' Env
env [ArtistArtwork]
artworks = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite ArtistArtworkT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite ArtistArtworkT -> SqliteM ())
-> (SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
    -> SqlInsert Sqlite ArtistArtworkT)
-> SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
-> SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
-> SqlInsert Sqlite ArtistArtworkT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
#artistArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
 -> m ())
-> SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [ArtistArtworkT Identity]
-> SqlInsertValues Sqlite (ArtistArtworkT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((ArtistArtwork -> ArtistArtworkT Identity)
-> [ArtistArtwork] -> [ArtistArtworkT Identity]
forall a b. (a -> b) -> [a] -> [b]
map ArtistArtwork -> ArtistArtworkT Identity
mkArtistArtworkP [ArtistArtwork]
artworks)
  Map UUID ArtistArtwork -> m (Map UUID ArtistArtwork)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID ArtistArtwork
forall k a. Map k a
Map.empty

upsertArtistOpinions' :: (MonadIO m) => Env -> [ArtistOpinion] -> m (Map UUID ArtistOpinion)
upsertArtistOpinions' :: forall (m :: * -> *).
MonadIO m =>
Env -> [ArtistOpinion] -> m (Map UUID ArtistOpinion)
upsertArtistOpinions' Env
env [ArtistOpinion]
opinions = do
  (ArtistOpinion -> m ()) -> [ArtistOpinion] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
    ( \ArtistOpinion
o -> do
        Maybe (ArtistOpinionT Identity)
exOpinion <- IO (Maybe (ArtistOpinionT Identity))
-> m (Maybe (ArtistOpinionT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (ArtistOpinionT Identity))
 -> m (Maybe (ArtistOpinionT Identity)))
-> IO (Maybe (ArtistOpinionT Identity))
-> m (Maybe (ArtistOpinionT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (ArtistOpinionT Identity))
-> IO (Maybe (ArtistOpinionT Identity))
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM (Maybe (ArtistOpinionT Identity))
 -> IO (Maybe (ArtistOpinionT Identity)))
-> SqliteM (Maybe (ArtistOpinionT Identity))
-> IO (Maybe (ArtistOpinionT Identity))
forall a b. (a -> b) -> a -> b
$ do
          SqlSelect Sqlite (ArtistOpinionT Identity)
-> SqliteM (Maybe (ArtistOpinionT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (ArtistOpinionT Identity)
 -> SqliteM (Maybe (ArtistOpinionT Identity)))
-> SqlSelect Sqlite (ArtistOpinionT Identity)
-> SqliteM (Maybe (ArtistOpinionT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistOpinionT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (ArtistOpinionT (QExpr Sqlite QBaseScope)))
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistOpinionT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite
      (QExprToIdentity (ArtistOpinionT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (ArtistOpinionT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
            (ArtistOpinionT (QExpr Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_
              ( \ArtistOpinionT (QExpr Sqlite QBaseScope)
s ->
                  (ArtistOpinionT (QExpr Sqlite QBaseScope)
s ArtistOpinionT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
     (PrimaryKey ArtistT (QExpr Sqlite QBaseScope))
-> PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistOpinionT (QExpr Sqlite QBaseScope))
  (PrimaryKey ArtistT (QExpr Sqlite QBaseScope))
#artistIdentifier)
                    PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
-> PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QExpr Sqlite QBaseScope))
-> PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Columnar Identity Text -> PrimaryKey ArtistT Identity)
-> Columnar Identity Text -> PrimaryKey ArtistT Identity
forall a b. (a -> b) -> a -> b
$ UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ ArtistOpinion
o ArtistOpinion -> Optic' A_Lens NoIx ArtistOpinion UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ArtistOpinion UUID
#artistIdentifier)
                    QExpr Sqlite QBaseScope Bool
-> QExpr Sqlite QBaseScope Bool -> QExpr Sqlite QBaseScope Bool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s Bool
-> QGenExpr context be s Bool -> QGenExpr context be s Bool
&&. (ArtistOpinionT (QExpr Sqlite QBaseScope)
s ArtistOpinionT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
     (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistOpinionT (QExpr Sqlite QBaseScope))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#createdBy)
                    QGenExpr QValueContext Sqlite QBaseScope Text
-> QGenExpr QValueContext Sqlite QBaseScope Text
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ ArtistOpinion
o ArtistOpinion -> Optic' A_Lens NoIx ArtistOpinion UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx ArtistOpinion ArtistOpinion Opinion Opinion
#opinion Optic A_Lens NoIx ArtistOpinion ArtistOpinion Opinion Opinion
-> Optic A_Lens NoIx Opinion Opinion UUID UUID
-> Optic' A_Lens NoIx ArtistOpinion UUID
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Lens NoIx Opinion Opinion UUID UUID
#createdBy)
              )
              (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistOpinionT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistOpinionT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QExpr Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
#artistOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        case Maybe (ArtistOpinionT Identity)
exOpinion of
          Maybe (ArtistOpinionT Identity)
Nothing ->
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
              (IO () -> m ())
-> (SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
              (SqliteM () -> IO ())
-> (SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite ArtistOpinionT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
              (SqlInsert Sqlite ArtistOpinionT -> SqliteM ())
-> (SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
    -> SqlInsert Sqlite ArtistOpinionT)
-> SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
-> SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
-> SqlInsert Sqlite ArtistOpinionT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
#artistOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
              (SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
 -> m ())
-> SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [ArtistOpinionT Identity]
-> SqlInsertValues Sqlite (ArtistOpinionT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues [ArtistOpinion -> ArtistOpinionT Identity
mkArtistOpinionP ArtistOpinion
o]
          Just ArtistOpinionT Identity
oo -> do
            let newO :: ArtistOpinionT Identity
newO =
                  ( ArtistOpinionT Identity
oo
                      { isLike = o ^. #opinion % #isLike,
                        isDislike = o ^. #opinion % #isDislike,
                        lastEditedAt = o ^. #opinion % #lastEditedAt
                      }
                  ) ::
                    ArtistOpinion'
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
              (IO () -> m ())
-> (SqlUpdate Sqlite ArtistOpinionT -> IO ())
-> SqlUpdate Sqlite ArtistOpinionT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
              (SqliteM () -> IO ())
-> (SqlUpdate Sqlite ArtistOpinionT -> SqliteM ())
-> SqlUpdate Sqlite ArtistOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite ArtistOpinionT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate
              (SqlUpdate Sqlite ArtistOpinionT -> m ())
-> SqlUpdate Sqlite ArtistOpinionT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
-> ArtistOpinionT Identity -> SqlUpdate Sqlite ArtistOpinionT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
#artistOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) ArtistOpinionT Identity
newO
        () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
    )
    [ArtistOpinion]
opinions

  Map UUID ArtistOpinion -> m (Map UUID ArtistOpinion)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID ArtistOpinion
forall k a. Map k a
Map.empty

deleteArtists' :: (MonadIO m) => Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtists' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtists' Env
env [UUID]
identifiers = do
  Either ArtistCommandError ()
deleteArtworksOfArtistsResult <- IO (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> (Free ArtistCommand (Either ArtistCommandError ())
    -> IO (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistCommand (Free ArtistCommand (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free ArtistCommand (Either ArtistCommandError ())
forall (f :: * -> *).
(ArtistCommand :<: f) =>
Env -> [UUID] -> Free f (Either ArtistCommandError ())
deleteArtworksOfArtists Env
env [UUID]
identifiers
  Either ArtistCommandError ()
deleteOpinionsOfArtistsResult <- IO (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> (Free ArtistCommand (Either ArtistCommandError ())
    -> IO (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistCommand (Free ArtistCommand (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free ArtistCommand (Either ArtistCommandError ())
forall (f :: * -> *).
(ArtistCommand :<: f) =>
Env -> [UUID] -> Free f (Either ArtistCommandError ())
deleteOpinionsOfArtists Env
env [UUID]
identifiers
  Either ArtistCommandError ()
deleteCommentsOfArtistsResult <- IO (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> (Free ArtistCommand (Either ArtistCommandError ())
    -> IO (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistCommand (Free ArtistCommand (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free ArtistCommand (Either ArtistCommandError ())
forall (f :: * -> *).
(ArtistCommand :<: f) =>
Env -> [UUID] -> Free f (Either ArtistCommandError ())
deleteCommentsOfArtists Env
env [UUID]
identifiers
  Either ArtistCommandError ()
deleteArtistExternalSourcesResult <- IO (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> (Free ArtistCommand (Either ArtistCommandError ())
    -> IO (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistCommand (Free ArtistCommand (Either ArtistCommandError ())
 -> m (Either ArtistCommandError ()))
-> Free ArtistCommand (Either ArtistCommandError ())
-> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free ArtistCommand (Either ArtistCommandError ())
forall (f :: * -> *).
(ArtistCommand :<: f) =>
Env -> [UUID] -> Free f (Either ArtistCommandError ())
deleteArtistExternalSources Env
env [UUID]
identifiers
  Either ArtistCommandError ()
deleteArtistsResult <- Env -> [UUID] -> m (Either ArtistCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
doDeleteArtists' Env
env [UUID]
identifiers
  Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (Either ArtistCommandError () -> m (Either ArtistCommandError ()))
-> Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ Either ArtistCommandError ()
deleteArtworksOfArtistsResult
    Either ArtistCommandError ()
-> Either ArtistCommandError () -> Either ArtistCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either ArtistCommandError ()
deleteOpinionsOfArtistsResult
    Either ArtistCommandError ()
-> Either ArtistCommandError () -> Either ArtistCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either ArtistCommandError ()
deleteArtistExternalSourcesResult
    Either ArtistCommandError ()
-> Either ArtistCommandError () -> Either ArtistCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either ArtistCommandError ()
deleteCommentsOfArtistsResult
    Either ArtistCommandError ()
-> Either ArtistCommandError () -> Either ArtistCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either ArtistCommandError ()
deleteArtistsResult

doDeleteArtists' :: (MonadIO m) => Env -> [UUID] -> m (Either ArtistCommandError ())
doDeleteArtists' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
doDeleteArtists' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite ArtistT -> IO ())
-> SqlDelete Sqlite ArtistT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistT -> SqliteM ())
-> SqlDelete Sqlite ArtistT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite ArtistT -> m ())
-> SqlDelete Sqlite ArtistT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> (forall s.
    (forall s'. ArtistT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. ArtistT (QExpr Sqlite s')
c -> (ArtistT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistT (QExpr Sqlite s')
c ArtistT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ArtistCommandError () -> m (Either ArtistCommandError ()))
-> (() -> Either ArtistCommandError ())
-> ()
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either ArtistCommandError ()))
-> () -> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

updateArtistArtworkOrder' :: (MonadIO m) => Env -> [ArtistArtworkOrderUpdate] -> m (Either a ())
updateArtistArtworkOrder' :: forall (m :: * -> *) a.
MonadIO m =>
Env -> [ArtistArtworkOrderUpdate] -> m (Either a ())
updateArtistArtworkOrder' Env
env [ArtistArtworkOrderUpdate]
orderUpdates = do
  (ArtistArtworkOrderUpdate -> m ())
-> [ArtistArtworkOrderUpdate] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
    ( \ArtistArtworkOrderUpdate
ou -> do
        Maybe (ArtistArtworkT Identity)
art <- IO (Maybe (ArtistArtworkT Identity))
-> m (Maybe (ArtistArtworkT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (ArtistArtworkT Identity))
 -> m (Maybe (ArtistArtworkT Identity)))
-> IO (Maybe (ArtistArtworkT Identity))
-> m (Maybe (ArtistArtworkT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (ArtistArtworkT Identity))
-> IO (Maybe (ArtistArtworkT Identity))
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM (Maybe (ArtistArtworkT Identity))
 -> IO (Maybe (ArtistArtworkT Identity)))
-> SqliteM (Maybe (ArtistArtworkT Identity))
-> IO (Maybe (ArtistArtworkT Identity))
forall a b. (a -> b) -> a -> b
$ do
          SqlSelect Sqlite (ArtistArtworkT Identity)
-> SqliteM (Maybe (ArtistArtworkT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (ArtistArtworkT Identity)
 -> SqliteM (Maybe (ArtistArtworkT Identity)))
-> SqlSelect Sqlite (ArtistArtworkT Identity)
-> SqliteM (Maybe (ArtistArtworkT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistArtworkT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (ArtistArtworkT (QExpr Sqlite QBaseScope)))
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistArtworkT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite
      (QExprToIdentity (ArtistArtworkT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistArtworkT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (ArtistArtworkT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
            (ArtistArtworkT (QExpr Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistArtworkT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistArtworkT (QExpr Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_
              (\ArtistArtworkT (QExpr Sqlite QBaseScope)
s -> (ArtistArtworkT (QExpr Sqlite QBaseScope)
s ArtistArtworkT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistArtworkT (QExpr Sqlite QBaseScope))
     (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistArtworkT (QExpr Sqlite QBaseScope))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#identifier) QGenExpr QValueContext Sqlite QBaseScope Text
-> QGenExpr QValueContext Sqlite QBaseScope Text
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ ArtistArtworkOrderUpdate
ou ArtistArtworkOrderUpdate
-> Optic' A_Lens NoIx ArtistArtworkOrderUpdate UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ArtistArtworkOrderUpdate UUID
#identifier))
              (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistArtworkT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistArtworkT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistArtworkT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistArtworkT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistArtworkT (QExpr Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
#artistArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        case Maybe (ArtistArtworkT Identity)
art of
          Maybe (ArtistArtworkT Identity)
Nothing -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
          Just ArtistArtworkT Identity
foundArt -> do
            let a :: ArtistArtworkT Identity
a = ArtistArtworkT Identity
foundArt {orderValue = fromIntegral $ ou ^. #orderValue} :: ArtistArtwork'
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> (ArtistArtworkT Identity -> IO ())
-> ArtistArtworkT Identity
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM () -> IO ())
-> (ArtistArtworkT Identity -> SqliteM ())
-> ArtistArtworkT Identity
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite ArtistArtworkT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate (SqlUpdate Sqlite ArtistArtworkT -> SqliteM ())
-> (ArtistArtworkT Identity -> SqlUpdate Sqlite ArtistArtworkT)
-> ArtistArtworkT Identity
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
-> ArtistArtworkT Identity -> SqlUpdate Sqlite ArtistArtworkT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
#artistArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (ArtistArtworkT Identity -> m ())
-> ArtistArtworkT Identity -> m ()
forall a b. (a -> b) -> a -> b
$ ArtistArtworkT Identity
a
    )
    [ArtistArtworkOrderUpdate]
orderUpdates
  Either a () -> m (Either a ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either a () -> m (Either a ()))
-> (() -> Either a ()) -> () -> m (Either a ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either a ()
forall a b. b -> Either a b
Right (() -> m (Either a ())) -> () -> m (Either a ())
forall a b. (a -> b) -> a -> b
$ ()

updateArtists' :: (MonadIO m) => Env -> Map UUID (Artist, Maybe ArtistDelta) -> m (Either Text ())
updateArtists' :: forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Artist, Maybe ArtistDelta) -> m (Either Text ())
updateArtists' Env
env Map UUID (Artist, Maybe ArtistDelta)
deltas = do
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ((Artist, Maybe ArtistDelta) -> m ())
-> [(Artist, Maybe ArtistDelta)] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (ArtistT Identity -> m ()
save'' (ArtistT Identity -> m ())
-> ((Artist, Maybe ArtistDelta) -> ArtistT Identity)
-> (Artist, Maybe ArtistDelta)
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Artist -> ArtistT Identity
toPersistenceArtist (Artist -> ArtistT Identity)
-> ((Artist, Maybe ArtistDelta) -> Artist)
-> (Artist, Maybe ArtistDelta)
-> ArtistT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> (Artist, Maybe ArtistDelta) -> Artist
forall {k} {k} {s}.
(Is k A_Getter, Is k A_Getter,
 LabelOptic "description" k s s (Maybe Text) (Maybe Text),
 LabelOptic "displayName" k s s (Maybe Text) (Maybe Text)) =>
UTCTime -> (Artist, Maybe s) -> Artist
doDelta UTCTime
now) (Map UUID (Artist, Maybe ArtistDelta)
-> [(Artist, Maybe ArtistDelta)]
forall k a. Map k a -> [a]
Map.elems Map UUID (Artist, Maybe ArtistDelta)
deltas)
  Either Text ()
exUpdate <- IO (Either Text ()) -> m (Either Text ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either Text ()) -> m (Either Text ()))
-> IO (Either Text ()) -> m (Either Text ())
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistCommand (Free ArtistCommand (Either Text ()) -> IO (Either Text ()))
-> Free ArtistCommand (Either Text ()) -> IO (Either Text ())
forall a b. (a -> b) -> a -> b
$ Env
-> Map UUID (Artist, Maybe ArtistDelta)
-> Free ArtistCommand (Either Text ())
forall (f :: * -> *).
(ArtistCommand :<: f) =>
Env
-> Map UUID (Artist, Maybe ArtistDelta) -> Free f (Either Text ())
updateArtistExternalSources Env
env Map UUID (Artist, Maybe ArtistDelta)
deltas
  Either Text () -> m (Either Text ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text () -> m (Either Text ()))
-> Either Text () -> m (Either Text ())
forall a b. (a -> b) -> a -> b
$ Either Text ()
exUpdate Either Text () -> Either Text () -> Either Text ()
forall a. Semigroup a => a -> a -> a
<> () -> Either Text ()
forall a b. b -> Either a b
Right ()
  where
    save'' :: ArtistT Identity -> m ()
save'' ArtistT Identity
x = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> (SqlUpdate Sqlite ArtistT -> IO ())
-> SqlUpdate Sqlite ArtistT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM () -> IO ())
-> (SqlUpdate Sqlite ArtistT -> SqliteM ())
-> SqlUpdate Sqlite ArtistT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite ArtistT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate (SqlUpdate Sqlite ArtistT -> m ())
-> SqlUpdate Sqlite ArtistT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> ArtistT Identity -> SqlUpdate Sqlite ArtistT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) ArtistT Identity
x
    doDelta :: UTCTime -> (Artist, Maybe s) -> Artist
doDelta UTCTime
now (Artist
x, Maybe s
xDelta') =
      case Maybe s
xDelta' of
        Maybe s
Nothing -> Artist
x
        Just s
xDelta ->
          Artist
x
            { displayName = fromMaybe (x ^. #displayName) (xDelta ^. #displayName),
              description = xDelta ^. #description,
              lastEditedAt = Just now
            } ::
            Artist

updateArtistExternalSources' :: (MonadIO m) => Env -> Map UUID (Artist, Maybe ArtistDelta) -> m (Either Text ())
updateArtistExternalSources' :: forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Artist, Maybe ArtistDelta) -> m (Either Text ())
updateArtistExternalSources' Env
env Map UUID (Artist, Maybe ArtistDelta)
deltas = do
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ((Artist, Maybe ArtistDelta) -> m ())
-> Map UUID (Artist, Maybe ArtistDelta) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
    ( \(Artist
artist, Maybe ArtistDelta
xDelta) -> do
        Maybe (ArtistExternalSourcesT Identity)
ex <- IO (Maybe (ArtistExternalSourcesT Identity))
-> m (Maybe (ArtistExternalSourcesT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (ArtistExternalSourcesT Identity))
 -> m (Maybe (ArtistExternalSourcesT Identity)))
-> IO (Maybe (ArtistExternalSourcesT Identity))
-> m (Maybe (ArtistExternalSourcesT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (ArtistExternalSourcesT Identity))
-> IO (Maybe (ArtistExternalSourcesT Identity))
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM (Maybe (ArtistExternalSourcesT Identity))
 -> IO (Maybe (ArtistExternalSourcesT Identity)))
-> SqliteM (Maybe (ArtistExternalSourcesT Identity))
-> IO (Maybe (ArtistExternalSourcesT Identity))
forall a b. (a -> b) -> a -> b
$ do
          SqlSelect Sqlite (ArtistExternalSourcesT Identity)
-> SqliteM (Maybe (ArtistExternalSourcesT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (ArtistExternalSourcesT Identity)
 -> SqliteM (Maybe (ArtistExternalSourcesT Identity)))
-> SqlSelect Sqlite (ArtistExternalSourcesT Identity)
-> SqliteM (Maybe (ArtistExternalSourcesT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistExternalSourcesT (QExpr Sqlite QBaseScope)))
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite
      (QExprToIdentity
         (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistExternalSourcesT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
            (ArtistExternalSourcesT (QExpr Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_
              (\ArtistExternalSourcesT (QExpr Sqlite QBaseScope)
s -> (ArtistExternalSourcesT (QExpr Sqlite QBaseScope)
s ArtistExternalSourcesT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
     (PrimaryKey ArtistT (QExpr Sqlite QBaseScope))
-> PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
  (PrimaryKey ArtistT (QExpr Sqlite QBaseScope))
#artistIdentifier) PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
-> PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QExpr Sqlite QBaseScope))
-> PrimaryKey ArtistT (QExpr Sqlite QBaseScope)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Columnar Identity Text -> PrimaryKey ArtistT Identity)
-> Columnar Identity Text -> PrimaryKey ArtistT Identity
forall a b. (a -> b) -> a -> b
$ UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ Artist
artist Artist -> Optic' A_Lens NoIx Artist UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Artist UUID
#identifier))
              (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistExternalSourcesT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QExpr Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
#artistExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        case Maybe (ArtistExternalSourcesT Identity)
ex of
          Maybe (ArtistExternalSourcesT Identity)
Nothing -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
          Just ArtistExternalSourcesT Identity
foundEx -> do
            let a :: ArtistExternalSourcesT Identity
a =
                  ArtistExternalSourcesT Identity
foundEx
                    { spotifyUrl = (^. #spotifyUrl) =<< xDelta,
                      wikipediaUrl = (^. #wikipediaUrl) =<< xDelta,
                      soundcloudUrl = (^. #soundcloudUrl) =<< xDelta,
                      youtubeUrl = (^. #youtubeUrl) =<< xDelta,
                      lastEditedAt = Just now
                    } ::
                    ArtistExternalSources'
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> (ArtistExternalSourcesT Identity -> IO ())
-> ArtistExternalSourcesT Identity
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM () -> IO ())
-> (ArtistExternalSourcesT Identity -> SqliteM ())
-> ArtistExternalSourcesT Identity
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite ArtistExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate (SqlUpdate Sqlite ArtistExternalSourcesT -> SqliteM ())
-> (ArtistExternalSourcesT Identity
    -> SqlUpdate Sqlite ArtistExternalSourcesT)
-> ArtistExternalSourcesT Identity
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
-> ArtistExternalSourcesT Identity
-> SqlUpdate Sqlite ArtistExternalSourcesT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
#artistExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (ArtistExternalSourcesT Identity -> m ())
-> ArtistExternalSourcesT Identity -> m ()
forall a b. (a -> b) -> a -> b
$ ArtistExternalSourcesT Identity
a
    )
    Map UUID (Artist, Maybe ArtistDelta)
deltas
  Either Text () -> m (Either Text ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text () -> m (Either Text ()))
-> (() -> Either Text ()) -> () -> m (Either Text ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either Text ()
forall a b. b -> Either a b
Right (() -> m (Either Text ())) -> () -> m (Either Text ())
forall a b. (a -> b) -> a -> b
$ ()

newArtistArtworkFromRequest' :: (MonadIO m) => UUID -> InsertArtistArtworksRequestItem -> m ArtistArtwork
newArtistArtworkFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistArtworksRequestItem -> m ArtistArtwork
newArtistArtworkFromRequest' UUID
createdBy InsertArtistArtworksRequestItem
req = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ArtistArtwork -> m ArtistArtwork
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (ArtistArtwork -> m ArtistArtwork)
-> ArtistArtwork -> m ArtistArtwork
forall a b. (a -> b) -> a -> b
$ ArtistArtwork
      { $sel:artistIdentifier:ArtistArtwork :: UUID
artistIdentifier = InsertArtistArtworksRequestItem
req InsertArtistArtworksRequestItem
-> Optic' A_Lens NoIx InsertArtistArtworksRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistArtworksRequestItem UUID
#artistIdentifier,
        $sel:artwork:ArtistArtwork :: Artwork
artwork =
          Artwork
            { $sel:identifier:Artwork :: UUID
identifier = UUID
newUUID,
              $sel:createdBy:Artwork :: UUID
createdBy = UUID
createdBy,
              $sel:contentUrl:Artwork :: Text
contentUrl = InsertArtistArtworksRequestItem
req InsertArtistArtworksRequestItem
-> Optic' A_Lens NoIx InsertArtistArtworksRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistArtworksRequestItem Text
#contentUrl,
              $sel:contentCaption:Artwork :: Maybe Text
contentCaption = InsertArtistArtworksRequestItem
req InsertArtistArtworksRequestItem
-> Optic' A_Lens NoIx InsertArtistArtworksRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistArtworksRequestItem (Maybe Text)
#contentCaption,
              $sel:createdAt:Artwork :: UTCTime
createdAt = UTCTime
now,
              $sel:lastEditedAt:Artwork :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing,
              $sel:visibilityStatus:Artwork :: Int
visibilityStatus = Int
0,
              $sel:approvedBy:Artwork :: Maybe UUID
approvedBy = Maybe UUID
forall a. Maybe a
Nothing,
              $sel:orderValue:Artwork :: Int
orderValue = InsertArtistArtworksRequestItem
req InsertArtistArtworksRequestItem
-> Optic' A_Lens NoIx InsertArtistArtworksRequestItem Int -> Int
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistArtworksRequestItem Int
#orderValue
            }
      }

newArtistOpinionFromRequest' :: (MonadIO m) => UUID -> UpsertArtistOpinionsRequestItem -> m ArtistOpinion
newArtistOpinionFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> UpsertArtistOpinionsRequestItem -> m ArtistOpinion
newArtistOpinionFromRequest' UUID
createdBy UpsertArtistOpinionsRequestItem
req = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ArtistOpinion -> m ArtistOpinion
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (ArtistOpinion -> m ArtistOpinion)
-> ArtistOpinion -> m ArtistOpinion
forall a b. (a -> b) -> a -> b
$ ArtistOpinion
      { $sel:artistIdentifier:ArtistOpinion :: UUID
artistIdentifier = UpsertArtistOpinionsRequestItem
req UpsertArtistOpinionsRequestItem
-> Optic' A_Lens NoIx UpsertArtistOpinionsRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx UpsertArtistOpinionsRequestItem UUID
#artistIdentifier,
        $sel:opinion:ArtistOpinion :: Opinion
opinion =
          Opinion
            { $sel:identifier:Opinion :: UUID
identifier = UUID
newUUID,
              $sel:createdBy:Opinion :: UUID
createdBy = UUID
createdBy,
              $sel:isLike:Opinion :: Bool
isLike = UpsertArtistOpinionsRequestItem
req UpsertArtistOpinionsRequestItem
-> Optic' A_Lens NoIx UpsertArtistOpinionsRequestItem Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx UpsertArtistOpinionsRequestItem Bool
#isLike,
              $sel:isDislike:Opinion :: Bool
isDislike = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ UpsertArtistOpinionsRequestItem
req UpsertArtistOpinionsRequestItem
-> Optic' A_Lens NoIx UpsertArtistOpinionsRequestItem Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx UpsertArtistOpinionsRequestItem Bool
#isLike,
              $sel:createdAt:Opinion :: UTCTime
createdAt = UTCTime
now,
              $sel:lastEditedAt:Opinion :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing
            }
      }

newArtistFromRequest' :: (MonadIO m) => UUID -> InsertArtistsRequestItem -> m Artist
newArtistFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistsRequestItem -> m Artist
newArtistFromRequest' UUID
createdBy InsertArtistsRequestItem
req = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  Artist -> m Artist
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (Artist -> m Artist) -> Artist -> m Artist
forall a b. (a -> b) -> a -> b
$ Artist
      { $sel:identifier:Artist :: UUID
identifier = UUID
newUUID,
        $sel:displayName:Artist :: Text
displayName = InsertArtistsRequestItem
req InsertArtistsRequestItem
-> Optic' A_Lens NoIx InsertArtistsRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsRequestItem Text
#displayName,
        $sel:createdBy:Artist :: UUID
createdBy = UUID
createdBy,
        $sel:visibilityStatus:Artist :: Int
visibilityStatus = Int
0,
        $sel:approvedBy:Artist :: Maybe UUID
approvedBy = Maybe UUID
forall a. Maybe a
Nothing,
        $sel:createdAt:Artist :: UTCTime
createdAt = UTCTime
now,
        $sel:lastEditedAt:Artist :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing,
        $sel:artworks:Artist :: Map UUID ArtistArtwork
artworks = [Item (Map UUID ArtistArtwork)] -> Map UUID ArtistArtwork
forall l. IsList l => [Item l] -> l
fromList [],
        $sel:comments:Artist :: [ThreadRender ArtistComment]
comments = [],
        $sel:opinions:Artist :: Map UUID ArtistOpinion
opinions = [Item (Map UUID ArtistOpinion)] -> Map UUID ArtistOpinion
forall l. IsList l => [Item l] -> l
fromList [],
        $sel:spotifyUrl:Artist :: Maybe Text
spotifyUrl = InsertArtistsRequestItem
req InsertArtistsRequestItem
-> Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
#spotifyUrl,
        $sel:youtubeUrl:Artist :: Maybe Text
youtubeUrl = InsertArtistsRequestItem
req InsertArtistsRequestItem
-> Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
#youtubeUrl,
        $sel:soundcloudUrl:Artist :: Maybe Text
soundcloudUrl = InsertArtistsRequestItem
req InsertArtistsRequestItem
-> Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
#soundcloudUrl,
        $sel:wikipediaUrl:Artist :: Maybe Text
wikipediaUrl = InsertArtistsRequestItem
req InsertArtistsRequestItem
-> Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
#wikipediaUrl,
        $sel:viewCount:Artist :: Int
viewCount = Int
0,
        $sel:description:Artist :: Maybe Text
description = InsertArtistsRequestItem
req InsertArtistsRequestItem
-> Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsRequestItem (Maybe Text)
#description
      }

newArtistCommentFromRequest' :: (MonadIO m) => UUID -> InsertArtistCommentsRequestItem -> m ArtistComment
newArtistCommentFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistCommentsRequestItem -> m ArtistComment
newArtistCommentFromRequest' UUID
createdBy InsertArtistCommentsRequestItem
x = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ArtistComment -> m ArtistComment
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (ArtistComment -> m ArtistComment)
-> ArtistComment -> m ArtistComment
forall a b. (a -> b) -> a -> b
$ ArtistComment
      { $sel:artistIdentifier:ArtistComment :: UUID
artistIdentifier = InsertArtistCommentsRequestItem
x InsertArtistCommentsRequestItem
-> Optic' A_Lens NoIx InsertArtistCommentsRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistCommentsRequestItem UUID
#artistIdentifier,
        $sel:comment:ArtistComment :: Comment
comment =
          Comment
            { $sel:identifier:Comment :: UUID
identifier = UUID
newUUID,
              $sel:parentIdentifier:Comment :: Maybe UUID
parentIdentifier = InsertArtistCommentsRequestItem
x InsertArtistCommentsRequestItem
-> Optic' A_Lens NoIx InsertArtistCommentsRequestItem (Maybe UUID)
-> Maybe UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistCommentsRequestItem (Maybe UUID)
#parentIdentifier,
              $sel:createdBy:Comment :: UUID
createdBy = UUID
createdBy,
              $sel:visibilityStatus:Comment :: Int
visibilityStatus = Int
0,
              $sel:contents:Comment :: Text
contents = InsertArtistCommentsRequestItem
x InsertArtistCommentsRequestItem
-> Optic' A_Lens NoIx InsertArtistCommentsRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistCommentsRequestItem Text
#contents,
              $sel:approvedBy:Comment :: Maybe UUID
approvedBy = Maybe UUID
forall a. Maybe a
Nothing,
              $sel:createdAt:Comment :: UTCTime
createdAt = UTCTime
now,
              $sel:lastEditedAt:Comment :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing
            }
      }

deleteArtistComments' :: (MonadIO m) => Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistComments' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistComments' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite ArtistCommentT -> IO ())
-> SqlDelete Sqlite ArtistCommentT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistCommentT -> SqliteM ())
-> SqlDelete Sqlite ArtistCommentT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistCommentT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite ArtistCommentT -> m ())
-> SqlDelete Sqlite ArtistCommentT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
-> (forall s.
    (forall s'. ArtistCommentT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistCommentT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
#artistComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. ArtistCommentT (QExpr Sqlite s')
c -> (ArtistCommentT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistCommentT (QExpr Sqlite s')
c ArtistCommentT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistCommentT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistCommentT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ArtistCommandError () -> m (Either ArtistCommandError ()))
-> (() -> Either ArtistCommandError ())
-> ()
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either ArtistCommandError ()))
-> () -> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

deleteArtistArtworks' :: (MonadIO m) => Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistArtworks' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistArtworks' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite ArtistArtworkT -> IO ())
-> SqlDelete Sqlite ArtistArtworkT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistArtworkT -> SqliteM ())
-> SqlDelete Sqlite ArtistArtworkT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistArtworkT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite ArtistArtworkT -> m ())
-> SqlDelete Sqlite ArtistArtworkT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
-> (forall s.
    (forall s'. ArtistArtworkT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistArtworkT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
#artistArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. ArtistArtworkT (QExpr Sqlite s')
c -> (ArtistArtworkT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistArtworkT (QExpr Sqlite s')
c ArtistArtworkT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistArtworkT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistArtworkT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ArtistCommandError () -> m (Either ArtistCommandError ()))
-> (() -> Either ArtistCommandError ())
-> ()
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either ArtistCommandError ()))
-> () -> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

deleteArtistOpinions' :: (MonadIO m) => Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistOpinions' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistOpinions' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite ArtistOpinionT -> IO ())
-> SqlDelete Sqlite ArtistOpinionT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistOpinionT -> SqliteM ())
-> SqlDelete Sqlite ArtistOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistOpinionT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite ArtistOpinionT -> m ())
-> SqlDelete Sqlite ArtistOpinionT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
-> (forall s.
    (forall s'. ArtistOpinionT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistOpinionT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
#artistOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. ArtistOpinionT (QExpr Sqlite s')
c -> (ArtistOpinionT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistOpinionT (QExpr Sqlite s')
c ArtistOpinionT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistOpinionT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistOpinionT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ArtistCommandError () -> m (Either ArtistCommandError ()))
-> (() -> Either ArtistCommandError ())
-> ()
-> m (Either ArtistCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either ArtistCommandError ()))
-> () -> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

incrementViewsByOne' :: (MonadIO m) => Env -> [UUID] -> m (Either ArtistCommandError ())
incrementViewsByOne' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
incrementViewsByOne' Env
env [UUID]
identifiers = do
  (UUID -> m ()) -> [UUID] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ UUID -> m ()
doUpdate [UUID]
identifiers
  Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ArtistCommandError () -> m (Either ArtistCommandError ()))
-> Either ArtistCommandError () -> m (Either ArtistCommandError ())
forall a b. (a -> b) -> a -> b
$ () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right ()
  where
    doUpdate :: UUID -> m ()
doUpdate UUID
x = do
      Maybe (ArtistT Identity)
ex <- IO (Maybe (ArtistT Identity)) -> m (Maybe (ArtistT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (ArtistT Identity)) -> m (Maybe (ArtistT Identity)))
-> IO (Maybe (ArtistT Identity)) -> m (Maybe (ArtistT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (ArtistT Identity))
-> IO (Maybe (ArtistT Identity))
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM (Maybe (ArtistT Identity))
 -> IO (Maybe (ArtistT Identity)))
-> SqliteM (Maybe (ArtistT Identity))
-> IO (Maybe (ArtistT Identity))
forall a b. (a -> b) -> a -> b
$ do
        SqlSelect Sqlite (ArtistT Identity)
-> SqliteM (Maybe (ArtistT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (ArtistT Identity)
 -> SqliteM (Maybe (ArtistT Identity)))
-> SqlSelect Sqlite (ArtistT Identity)
-> SqliteM (Maybe (ArtistT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (ArtistT (QExpr Sqlite QBaseScope)))
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite (QExprToIdentity (ArtistT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (ArtistT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
          (ArtistT (QExpr Sqlite QBaseScope) -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QExpr Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_
            (\ArtistT (QExpr Sqlite QBaseScope)
s -> (ArtistT (QExpr Sqlite QBaseScope)
s ArtistT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistT (QExpr Sqlite QBaseScope))
     (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistT (QExpr Sqlite QBaseScope))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#identifier) QGenExpr QValueContext Sqlite QBaseScope Text
-> QGenExpr QValueContext Sqlite QBaseScope Text
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. (Text -> QGenExpr QValueContext Sqlite QBaseScope Text
HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> (UUID -> Text)
-> UUID
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText (UUID -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> UUID -> QGenExpr QValueContext Sqlite QBaseScope Text
forall a b. (a -> b) -> a -> b
$ UUID
x))
            (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QExpr Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      case Maybe (ArtistT Identity)
ex of
        Maybe (ArtistT Identity)
Nothing -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
        Just ArtistT Identity
foundEx -> do
          let a :: ArtistT Identity
a =
                ArtistT Identity
foundEx
                  { viewCount = (foundEx ^. #viewCount) + 1
                  } ::
                  Artist'
          IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> (ArtistT Identity -> IO ()) -> ArtistT Identity -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM () -> IO ())
-> (ArtistT Identity -> SqliteM ()) -> ArtistT Identity -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite ArtistT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate (SqlUpdate Sqlite ArtistT -> SqliteM ())
-> (ArtistT Identity -> SqlUpdate Sqlite ArtistT)
-> ArtistT Identity
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> ArtistT Identity -> SqlUpdate Sqlite ArtistT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (ArtistT Identity -> m ()) -> ArtistT Identity -> m ()
forall a b. (a -> b) -> a -> b
$ ArtistT Identity
a

instance Exec ArtistCommand where
  execAlgebra :: forall a. ArtistCommand (IO a) -> IO a
execAlgebra (IncrementViewsByOne Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) =
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> IO (Either ArtistCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either ArtistCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
incrementViewsByOne' Env
env [UUID]
identifiers
  execAlgebra (InsertArtists Env
env [Artist]
artists () -> IO a
next) =
    () -> IO a
next (() -> IO a) -> IO () -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [Artist] -> IO ()
forall (m :: * -> *). MonadIO m => Env -> [Artist] -> m ()
insertArtists' Env
env [Artist]
artists
  execAlgebra (InsertArtistComments Env
env [ArtistComment]
comments () -> IO a
next) =
    () -> IO a
next (() -> IO a) -> IO () -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [ArtistComment] -> IO ()
forall (m :: * -> *). MonadIO m => Env -> [ArtistComment] -> m ()
insertArtistComments' Env
env [ArtistComment]
comments
  execAlgebra (InsertArtistExternalSources Env
env [ArtistExternalSources]
externalSources Map UUID ArtistExternalSources -> IO a
next) =
    Map UUID ArtistExternalSources -> IO a
next (Map UUID ArtistExternalSources -> IO a)
-> IO (Map UUID ArtistExternalSources) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env
-> [ArtistExternalSources] -> IO (Map UUID ArtistExternalSources)
forall (m :: * -> *).
MonadIO m =>
Env
-> [ArtistExternalSources] -> m (Map UUID ArtistExternalSources)
insertArtistExternalSources' Env
env [ArtistExternalSources]
externalSources
  execAlgebra (InsertArtistArtworks Env
env [ArtistArtwork]
artworks Map UUID ArtistArtwork -> IO a
next) =
    Map UUID ArtistArtwork -> IO a
next (Map UUID ArtistArtwork -> IO a)
-> IO (Map UUID ArtistArtwork) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [ArtistArtwork] -> IO (Map UUID ArtistArtwork)
forall (m :: * -> *).
MonadIO m =>
Env -> [ArtistArtwork] -> m (Map UUID ArtistArtwork)
insertArtistArtworks' Env
env [ArtistArtwork]
artworks
  execAlgebra (UpsertArtistOpinions Env
env [ArtistOpinion]
opinions Map UUID ArtistOpinion -> IO a
next) =
    Map UUID ArtistOpinion -> IO a
next (Map UUID ArtistOpinion -> IO a)
-> IO (Map UUID ArtistOpinion) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [ArtistOpinion] -> IO (Map UUID ArtistOpinion)
forall (m :: * -> *).
MonadIO m =>
Env -> [ArtistOpinion] -> m (Map UUID ArtistOpinion)
upsertArtistOpinions' Env
env [ArtistOpinion]
opinions
  execAlgebra (DeleteArtists Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) =
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> IO (Either ArtistCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either ArtistCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtists' Env
env [UUID]
identifiers
  execAlgebra (DeleteArtistComments Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) = do
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> IO (Either ArtistCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either ArtistCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistComments' Env
env [UUID]
identifiers
  execAlgebra (DeleteArtistArtworks Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) = do
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> IO (Either ArtistCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either ArtistCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistArtworks' Env
env [UUID]
identifiers
  execAlgebra (DeleteArtistOpinions Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) = do
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> IO (Either ArtistCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either ArtistCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either ArtistCommandError ())
deleteArtistOpinions' Env
env [UUID]
identifiers
  execAlgebra (DeleteCommentsOfArtists Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) = do
    let ids :: [Text]
ids = (UUID -> Text) -> [UUID] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map UUID -> Text
UUID.toText [UUID]
identifiers

    (Text -> IO ()) -> [Text] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
      ( \Text
y ->
          (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
            (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistCommentT -> SqliteM ())
-> SqlDelete Sqlite ArtistCommentT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistCommentT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
            (SqlDelete Sqlite ArtistCommentT -> IO ())
-> SqlDelete Sqlite ArtistCommentT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
-> (forall s.
    (forall s'. ArtistCommentT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistCommentT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
#artistComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (\forall s'. ArtistCommentT (QExpr Sqlite s')
c -> ArtistCommentT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistCommentT (QExpr Sqlite s')
c ArtistCommentT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistCommentT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistCommentT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
#artistIdentifier PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. (PrimaryKey ArtistT Identity
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey ArtistT Identity
 -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> (Text -> PrimaryKey ArtistT Identity)
-> Text
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey ArtistT Identity
Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Text -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> Text -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall a b. (a -> b) -> a -> b
$ Text
y))
      )
      [Text]
ids

    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> Either ArtistCommandError () -> IO a
forall a b. (a -> b) -> a -> b
$ () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right ()
  execAlgebra (DeleteArtistExternalSources Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite ArtistExternalSourcesT -> IO ())
-> SqlDelete Sqlite ArtistExternalSourcesT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
      (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistExternalSourcesT -> SqliteM ())
-> SqlDelete Sqlite ArtistExternalSourcesT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite ArtistExternalSourcesT -> IO ())
-> SqlDelete Sqlite ArtistExternalSourcesT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
-> (forall s.
    (forall s'. ArtistExternalSourcesT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistExternalSourcesT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
#artistExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. ArtistExternalSourcesT (QExpr Sqlite s')
c -> (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistExternalSourcesT (QExpr Sqlite s')
c ArtistExternalSourcesT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
#artistIdentifier) PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey ArtistT Identity
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey ArtistT Identity
 -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey ArtistT Identity)
-> UUID
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey ArtistT Identity
Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Text -> PrimaryKey ArtistT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey ArtistT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> (() -> Either ArtistCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (DeleteArtworksOfArtists Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite ArtistArtworkT -> IO ())
-> SqlDelete Sqlite ArtistArtworkT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
      (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistArtworkT -> SqliteM ())
-> SqlDelete Sqlite ArtistArtworkT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistArtworkT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite ArtistArtworkT -> IO ())
-> SqlDelete Sqlite ArtistArtworkT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
-> (forall s.
    (forall s'. ArtistArtworkT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistArtworkT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
#artistArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. ArtistArtworkT (QExpr Sqlite s')
c -> (ArtistArtworkT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistArtworkT (QExpr Sqlite s')
c ArtistArtworkT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistArtworkT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistArtworkT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
#artistIdentifier) PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey ArtistT Identity
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey ArtistT Identity
 -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey ArtistT Identity)
-> UUID
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey ArtistT Identity
Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Text -> PrimaryKey ArtistT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey ArtistT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> (() -> Either ArtistCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (DeleteOpinionsOfArtists Env
env [UUID]
identifiers Either ArtistCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite ArtistOpinionT -> IO ())
-> SqlDelete Sqlite ArtistOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
      (SqliteM () -> IO ())
-> (SqlDelete Sqlite ArtistOpinionT -> SqliteM ())
-> SqlDelete Sqlite ArtistOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite ArtistOpinionT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite ArtistOpinionT -> IO ())
-> SqlDelete Sqlite ArtistOpinionT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
-> (forall s.
    (forall s'. ArtistOpinionT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite ArtistOpinionT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
#artistOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. ArtistOpinionT (QExpr Sqlite s')
c -> (ArtistOpinionT (QGenExpr QValueContext Sqlite s)
forall s'. ArtistOpinionT (QExpr Sqlite s')
c ArtistOpinionT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (ArtistOpinionT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistOpinionT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
#artistIdentifier) PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey ArtistT Identity
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey ArtistT Identity
 -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey ArtistT Identity)
-> UUID
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey ArtistT Identity
Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Text -> PrimaryKey ArtistT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey ArtistT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either ArtistCommandError () -> IO a
next (Either ArtistCommandError () -> IO a)
-> (() -> Either ArtistCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either ArtistCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (UpdateArtistArtworkOrder Env
env [ArtistArtworkOrderUpdate]
orderUpdates Either Text () -> IO a
next) =
    Either Text () -> IO a
next (Either Text () -> IO a) -> IO (Either Text ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [ArtistArtworkOrderUpdate] -> IO (Either Text ())
forall (m :: * -> *) a.
MonadIO m =>
Env -> [ArtistArtworkOrderUpdate] -> m (Either a ())
updateArtistArtworkOrder' Env
env [ArtistArtworkOrderUpdate]
orderUpdates
  execAlgebra (UpdateArtists Env
env Map UUID (Artist, Maybe ArtistDelta)
deltas Either Text () -> IO a
next) =
    Either Text () -> IO a
next (Either Text () -> IO a) -> IO (Either Text ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> Map UUID (Artist, Maybe ArtistDelta) -> IO (Either Text ())
forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Artist, Maybe ArtistDelta) -> m (Either Text ())
updateArtists' Env
env Map UUID (Artist, Maybe ArtistDelta)
deltas
  execAlgebra (UpdateArtistExternalSources Env
env Map UUID (Artist, Maybe ArtistDelta)
deltas Either Text () -> IO a
next) =
    Either Text () -> IO a
next (Either Text () -> IO a) -> IO (Either Text ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> Map UUID (Artist, Maybe ArtistDelta) -> IO (Either Text ())
forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Artist, Maybe ArtistDelta) -> m (Either Text ())
updateArtistExternalSources' Env
env Map UUID (Artist, Maybe ArtistDelta)
deltas
  execAlgebra (NewArtistFromRequest UUID
createdBy InsertArtistsRequestItem
req Artist -> IO a
next) =
    Artist -> IO a
next (Artist -> IO a) -> IO Artist -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertArtistsRequestItem -> IO Artist
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistsRequestItem -> m Artist
newArtistFromRequest' UUID
createdBy InsertArtistsRequestItem
req
  execAlgebra (NewArtistCommentFromRequest UUID
createdBy InsertArtistCommentsRequestItem
req ArtistComment -> IO a
next) =
    ArtistComment -> IO a
next (ArtistComment -> IO a) -> IO ArtistComment -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertArtistCommentsRequestItem -> IO ArtistComment
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistCommentsRequestItem -> m ArtistComment
newArtistCommentFromRequest' UUID
createdBy InsertArtistCommentsRequestItem
req
  execAlgebra (NewArtistOpinionFromRequest UUID
createdBy UpsertArtistOpinionsRequestItem
req ArtistOpinion -> IO a
next) =
    ArtistOpinion -> IO a
next (ArtistOpinion -> IO a) -> IO ArtistOpinion -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> UpsertArtistOpinionsRequestItem -> IO ArtistOpinion
forall (m :: * -> *).
MonadIO m =>
UUID -> UpsertArtistOpinionsRequestItem -> m ArtistOpinion
newArtistOpinionFromRequest' UUID
createdBy UpsertArtistOpinionsRequestItem
req
  execAlgebra (NewArtistArtworkFromRequest UUID
createdBy InsertArtistArtworksRequestItem
req ArtistArtwork -> IO a
next) =
    ArtistArtwork -> IO a
next (ArtistArtwork -> IO a) -> IO ArtistArtwork -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertArtistArtworksRequestItem -> IO ArtistArtwork
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistArtworksRequestItem -> m ArtistArtwork
newArtistArtworkFromRequest' UUID
createdBy InsertArtistArtworksRequestItem
req