Skip to content

Commit

Permalink
Move Types to Wallhaven directory (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 authored Jan 22, 2023
1 parent faacc3e commit 3d43e90
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/Wallhaven/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Wallhaven.CLI (runCLIApp) where

import Control.Monad.Reader (ReaderT (runReaderT))
import Options.Applicative
import Types
import Wallhaven.Action (syncAllWallpapers)
import Wallhaven.Env (Config (Config), Env (Env))
import Wallhaven.Types

defaultWallpaperDir :: FilePath
defaultWallpaperDir = "/Users/home/wallpapers"
Expand Down
13 changes: 12 additions & 1 deletion app/Wallhaven/Env.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
module Wallhaven.Env (Env (..), Config (..)) where

import Control.Monad.Reader (ReaderT, asks)
import qualified Types
import UnliftIO (MonadUnliftIO)
import qualified Wallhaven.Implementation.API as API
import qualified Wallhaven.Implementation.FileSystemDB as FileSystemDB
import Wallhaven.Monad
( HasDebug (..),
HasDeleteUnliked (..),
HasLog (..),
HasSyncParallelization (..),
MonadDeleteWallpaper (..),
MonadDownloadWallpaper (..),
MonadGetCollectionURLs (..),
MonadGetDownloadedWallpapers (..),
MonadInitDB (..),
MonadSaveWallpaper (..),
)
import qualified Wallhaven.Types as Types
import Prelude hiding (log)

-- Environment record
Expand Down
14 changes: 7 additions & 7 deletions src/Wallhaven/API/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ module Wallhaven.API.Action (getAllCollectionURLs, getFullWallpaper) where
import Data.Bifunctor (first)
import Data.ByteString (ByteString)
import Network.HTTP.Simple (Request, parseRequest_)
import Types
( CollectionID,
FullWallpaperURL,
Label,
NumParallelDownloads,
Username,
)
import UnliftIO (MonadUnliftIO)
import UnliftIO.Exception (catch, fromEither, throwIO)
import Util.Batch (batchedM)
Expand All @@ -25,6 +18,13 @@ import Wallhaven.API.Logic
wallhavenCollectionsRequest,
)
import Wallhaven.API.Types (APIKey, Page)
import Wallhaven.Types
( CollectionID,
FullWallpaperURL,
Label,
NumParallelDownloads,
Username,
)

getAllCollectionURLs ::
(MonadUnliftIO m) => APIKey -> Username -> Label -> m [FullWallpaperURL]
Expand Down
2 changes: 1 addition & 1 deletion src/Wallhaven/API/Exception.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Wallhaven.API.Exception where

import qualified Network.HTTP.Simple as HTTP
import Types (CollectionID, Label)
import UnliftIO.Exception (Exception, Typeable)
import Wallhaven.API.Types (Page)
import Wallhaven.Types (CollectionID, Label)

type JSONParseError = String

Expand Down
7 changes: 6 additions & 1 deletion src/Wallhaven/API/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BC8
import qualified Data.List as List
import qualified Network.HTTP.Simple as HTTP
import Types
import qualified Wallhaven.API.Exception as Exception
import Wallhaven.API.Types
import Wallhaven.Types
( CollectionID,
FullWallpaperURL,
Label,
Username,
)

findCollectionByLabel ::
String -> WallhavenCollectionsResponse -> Maybe WallhavenCollection
Expand Down
2 changes: 1 addition & 1 deletion src/Wallhaven/API/Types.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Wallhaven.API.Types where

import Data.Aeson (FromJSON (parseJSON), withObject, (.:))
import Types (CollectionID, FullWallpaperURL, Label)
import Wallhaven.Types (CollectionID, FullWallpaperURL, Label)

type APIKey = String

Expand Down
2 changes: 1 addition & 1 deletion src/Wallhaven/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Control.Monad.Reader (MonadReader, asks)
import qualified Data.List as List
import Data.Time (nominalDiffTimeToSeconds)
import Text.Printf (printf)
import Types (FullWallpaperURL, Label, Username, WallpaperName)
import UnliftIO
import UnliftIO.Concurrent (threadDelay)
import Util.Batch (batchedM_)
Expand All @@ -30,6 +29,7 @@ import Wallhaven.Monad
getSyncParallelization,
saveWallpaper,
)
import Wallhaven.Types (FullWallpaperURL, Label, Username, WallpaperName)
import Prelude hiding (log, writeFile)

type AppM env m =
Expand Down
7 changes: 6 additions & 1 deletion src/Wallhaven/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ module Wallhaven.Exception
)
where

import Types
import UnliftIO (Exception, Typeable)
import Wallhaven.Types
( FullWallpaperURL,
Label,
Username,
WallpaperName,
)

type OneLineError = String

Expand Down
2 changes: 1 addition & 1 deletion src/Wallhaven/Implementation/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import Data.ByteString (ByteString)
import qualified Network.HTTP.Client.Conduit as HTTP
import qualified Network.HTTP.Simple as HTTP
import Network.HTTP.Types.Status (notFound404, unauthorized401)
import Types (FullWallpaperURL, Label, Username)
import UnliftIO (MonadUnliftIO, catch, throwIO)
import qualified Wallhaven.API.Action as WallhavenAPI
import Wallhaven.API.Exception (CollectionURLsFetchException (..))
import Wallhaven.API.Types (APIKey)
import Wallhaven.Exception
( WallhavenSyncException (CollectionFetchException, WallpaperDownloadException),
)
import Wallhaven.Types (FullWallpaperURL, Label, Username)

getCollectionURLs ::
(MonadUnliftIO m) => APIKey -> Username -> Label -> m [FullWallpaperURL]
Expand Down
2 changes: 1 addition & 1 deletion src/Wallhaven/Implementation/FileSystemDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ where

import System.FilePath ((</>))
import System.IO.Error (isPermissionError)
import Types (Wallpaper, WallpaperName)
import UnliftIO
import UnliftIO.Directory
import UnliftIO.IO.File
import Util.FileSystem (deleteFileIfExists)
import Wallhaven.Exception
import Wallhaven.Types (Wallpaper, WallpaperName)

type WallpaperDir = FilePath

Expand Down
2 changes: 1 addition & 1 deletion src/Wallhaven/Logic.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Wallhaven.Logic (wallpaperName) where

import qualified Data.List.Split as List
import Types
import Wallhaven.Types (FullWallpaperURL, WallpaperName)

wallpaperName :: FullWallpaperURL -> WallpaperName
wallpaperName = last . List.splitOn "/"
8 changes: 7 additions & 1 deletion src/Wallhaven/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ module Wallhaven.Monad
where

import Data.ByteString (ByteString)
import Types
import Wallhaven.Types
( FullWallpaperURL,
Label,
Username,
Wallpaper,
WallpaperName,
)

class HasDebug a where
getDebug :: a -> Bool
Expand Down
2 changes: 1 addition & 1 deletion src/Types.hs → src/Wallhaven/Types.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Types where
module Wallhaven.Types where

import Data.ByteString (ByteString)

Expand Down
2 changes: 1 addition & 1 deletion wallhaven-sync.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ source-repository head

library wallhaven-sync-internal
exposed-modules:
Types
Util.Time
Util.Retry
Util.List
Util.Batch
Util.HTTP
Util.FileSystem
Wallhaven.Types
Wallhaven.Logic
Wallhaven.Exception
Wallhaven.Monad
Expand Down

0 comments on commit 3d43e90

Please sign in to comment.