Skip to content

Commit

Permalink
Add resource modification functions (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
saschagrunert committed Jan 10, 2018
1 parent e1177a5 commit 00885f2
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 350 deletions.
6 changes: 3 additions & 3 deletions REQUIREMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ It should be possible, to …

1. …save the applications state persistently.
2. …work collaboratively with other Users of the application.
3. …manage a 'Team' by adding or removing 'Users'.
4. …add 'things' to certain or multiple Users of the Team.
5. …display the resource usage of certain teams and Users.
3. …manage a 'Resource'.
4. …add 'Actions' to certain or multiple 'Resources'.
5. …display the resource usage of certain 'Resources'.
6. …display the schedule for a chosen time interval.
7. …customize the actual work time slots.

Expand Down
9 changes: 4 additions & 5 deletions seer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: 035e77006fa12a97536b6a2bb08c905ddafceaed5661ee840b37ae094a6e27d7
-- hash: 3083cb96c770aef493cc59609fb03d32b4896c58465aff15871810c34b3559c7

name: seer
version: 0.1.0
Expand Down Expand Up @@ -32,10 +32,10 @@ library
exposed-modules:
Seer
Seer.Action
Seer.Entity
Seer.Git
Seer.Resource
Seer.Storage
Seer.Team
Seer.User
other-modules:
Paths_seer
hs-source-dirs:
Expand Down Expand Up @@ -66,9 +66,8 @@ test-suite seer-test
other-modules:
ActionSpec
GitSpec
ResourceSpec
StorageSpec
TeamSpec
UserSpec
Paths_seer
hs-source-dirs:
test
Expand Down
2 changes: 2 additions & 0 deletions src/Seer.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- | This module everything related to the main library interface
--
-- @since 0.1.0

module Seer (
Id,
Expand Down
15 changes: 13 additions & 2 deletions src/Seer/Action.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- | This module includes everything about a 'Action'.
--
-- @since 0.1.0

{-# LANGUAGE DeriveGeneric #-}

Expand All @@ -14,6 +16,7 @@ module Seer.Action (
import Data.Yaml (FromJSON, ToJSON)
import GHC.Generics (Generic)
import Seer (Id)
import Seer.Resource (Resources)

-- | The data representing multiple Actions
--
Expand All @@ -24,20 +27,28 @@ newtype Actions = Actions [Action]
-- | The data specified for a Action
--
-- @since 0.1.0
data Action = Action { name :: String -- ^ The identifier of the Action
, assigned :: Maybe [Id] -- ^ To whom belongs the Action
data Action = Action { name :: String -- ^ The identifier of the Action
, assigned :: Maybe Resources -- ^ To whom belongs the Action
} deriving (Eq, Generic, Show)

-- | Parses the 'Action' from YAML/JSON
--
-- @since 0.1.0
instance FromJSON Action

-- | Parses the 'Actions' from YAML/JSON
--
-- @since 0.1.0
instance FromJSON Actions

-- | Generates the YAML/JSON from an 'Action'
--
-- @since 0.1.0
instance ToJSON Action

-- | Generates the YAML/JSON from 'Actions'
--
-- @since 0.1.0
instance ToJSON Actions

-- | The empty 'Actions' representation
Expand Down
31 changes: 31 additions & 0 deletions src/Seer/Entity.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- | This module includes everything about general entity handling
--
-- @since 0.1.0

{-# LANGUAGE MultiParamTypeClasses #-}

module Seer.Entity (
EntityRelation(..)
) where

-- | A relation between a single type `s` and its plural `p`
--
-- @since 0.1.0
class EntityRelation s p where
-- | Adds a single `s` to plural `p`
--
-- @since 0.1.0
infixr 5 |+
(|+)
:: p -- ^ The plural where the single entity should be added
-> s -- ^ The single entity to be added
-> p -- ^ The resulting plural

-- | Removes a single `s` from plural `p`
--
-- @since 0.1.0
infixr 5 |-
(|-)
:: p -- ^ The plural where the single entity should be removed
-> s -- ^ The single entity to be removed
-> p -- ^ The resulting plural
2 changes: 2 additions & 0 deletions src/Seer/Git.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- | This module includes everything related to git.
--
-- @since 0.1.0

{-# LANGUAGE OverloadedStrings #-}

Expand Down
104 changes: 104 additions & 0 deletions src/Seer/Resource.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
-- | This module includes everything about a 'Resource'.
--
-- @since 0.1.0

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module Seer.Resource (
Resource,
Resources,
empty,
name,
newResource,
toResources,
) where

import Data.Yaml (FromJSON, ToJSON)
import GHC.Generics (Generic)
import Seer (Id)
import Seer.Entity (EntityRelation(..))
import qualified Data.Set as S (Set, delete, empty, insert, singleton)

-- | The data representing multiple Resources
--
-- @since 0.1.0
newtype Resources = Resources (S.Set Resource)
deriving (Eq, Generic, Ord, Show)

-- | The data representing a single Resource
--
-- @since 0.1.0
newtype Resource = Resource { name :: Id -- ^ The name of the resource
} deriving (Eq, Generic, Ord, Show)

-- | Parses the 'Resource' from YAML/JSON
--
-- @since 0.1.0
instance FromJSON Resource

-- | Parses the 'Resources' from YAML/JSON
--
-- @since 0.1.0
instance FromJSON Resources

-- | Generates the YAML/JSON from an 'Resource'
--
-- @since 0.1.0
instance ToJSON Resource

-- | Generates the YAML/JSON from 'Resources'
--
-- @since 0.1.0
instance ToJSON Resources

-- | Entity relations between 'Resource' and 'Resources'
--
-- @since 0.1.0
instance EntityRelation Resource Resources where
-- | Removes a 'Resource' from 'Resources'
--
-- @since 0.1.0
Resources xs |- x = Resources $ S.delete x xs

-- | Adds a 'Resource' to 'Resources'
--
-- @since 0.1.0
Resources xs |+ x = Resources $ S.insert x xs

-- | The empty 'Resources' representation
--
-- Examples:
--
-- >>> empty
-- Resources (fromList [])
--
-- @since 0.1.0
empty :: Resources
empty = Resources S.empty

-- | Creates a new 'Resource' from a given name
--
-- Examples:
--
-- >>> newResource "Resourcename"
-- Resource {name = "Resourcename"}
--
-- @since 0.1.0
newResource
:: Id -- ^ The resources name
-> Resource -- ^ The resulting 'Resource'
newResource a = Resource {name = a}

-- | Converts a 'Resource' to 'Resources'
--
-- Examples:
--
-- >>> toResources $ newResource "Resource"
-- Resources (fromList [Resource {name = "Resource"}])
--
-- @since 0.1.0
toResources
:: Resource -- ^ The Resource to be added
-> Resources -- ^ The Resources where the resource should be added
toResources x = Resources $ S.singleton x
27 changes: 14 additions & 13 deletions src/Seer/Storage.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- | This module includes everything related to Storage handling.
--
-- @since 0.1.0

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
Expand All @@ -9,16 +11,14 @@ module Seer.Storage (
actions,
empty,
load,
resources,
save,
teams,
users,
) where

import Data.Bifunctor (first)
import Data.Yaml
import Seer.Action (Actions)
import Seer.Team (Teams)
import Seer.User (Users)
import Seer.Resource (Resources)

-- | A abstraction Monad to isolate real IO Actions
--
Expand All @@ -37,38 +37,39 @@ instance MonadStorage IO where
decodeFileEither' = decodeFileEither
encodeFile' = encodeFile

-- | The storage for representing 'Users', 'Teams' and 'Actions'.
-- | The storage for representing 'Resources' and 'Actions'.
--
-- @since 0.1.0
data Storage = Storage { users :: Maybe Users -- ^ The users to be stored
, teams :: Maybe Teams -- ^ The teams to be stored
data Storage = Storage { resources :: Maybe Resources -- ^ The resources to be stored
, actions :: Maybe Actions -- ^ The actions to be stored
} deriving (Eq, Show)

-- | Parses the 'Storage' from YAML/JSON
--
-- @since 0.1.0
instance FromJSON Storage where
parseJSON (Object m) = Storage <$>
m .: "users" <*>
m .: "teams" <*>
m .: "resources" <*>
m .: "actions"
parseJSON x = fail $ "not an object: " ++ show x

-- | Generates the YAML/JSON from a 'Storage'
--
-- @since 0.1.0
instance ToJSON Storage where
toJSON Storage{..} = object [ "users" .= users
, "teams" .= teams
toJSON Storage{..} = object [ "resources" .= resources
, "actions" .= actions ]

-- | The empty 'Storage' representation
--
-- Examples:
--
-- >>> empty
-- Storage {users = Nothing, teams = Nothing, actions = Nothing}
-- Storage {resources = Nothing, actions = Nothing}
--
-- @since 0.1.0
empty :: Storage
empty = Storage {users = Nothing, teams = Nothing, actions = Nothing}
empty = Storage {resources = Nothing, actions = Nothing}

-- | Load from the given 'FilePath' and return either a error 'String' or a
-- valid 'Storage' instance
Expand Down
66 changes: 0 additions & 66 deletions src/Seer/Team.hs

This file was deleted.

0 comments on commit 00885f2

Please sign in to comment.