Skip to content

Commit

Permalink
fix: pr feedback and small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mau5mat committed Nov 21, 2024
1 parent 5d3ca82 commit 97d19ef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
14 changes: 1 addition & 13 deletions changelog.d/63
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,5 @@ prs: #785
issues: #556

description: {

- Migration for `create_package_groups` & `create_package_group_packages`
- Updates to various files as a result of the work done
- Created:
- `Flora/Model/PackageGroup/Query.hs`
- `Flora/Model/PackageGroup/Types.hs`
- `Flora/Model/PackageGroup/Update.hs`
- Created:
- `Flora/Model/PackageGroupPackage/Query.hs`
- `Flora/Model/PackageGroupPackage/Types.hs`
- `Flora/Model/PackageGroupPackage/Update.hs`
- Created:
- test/Flora/PackageGroupSpec.hs`
Migration for `create_package_groups` & `create_package_group_packages`
}
28 changes: 11 additions & 17 deletions src/core/Flora/Model/PackageGroup/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,24 @@ module Flora.Model.PackageGroup.Query

import Data.Text (Text)
import Data.Vector (Vector)
import Database.PostgreSQL.Entity (selectOneByField)
import Database.PostgreSQL.Entity.DBT
( QueryNature (Select)
, query
)
import Database.PostgreSQL.Entity (joinSelectOneByField, selectOneByField)
import Database.PostgreSQL.Entity.Types (field)
import Database.PostgreSQL.Simple (Only (..))
import Database.PostgreSQL.Simple.SqlQQ (sql)
import Effectful (Eff, type (:>))
import Effectful.PostgreSQL.Transact.Effect (DB, dbtToEff)
import Flora.Model.Package.Types (Package)
import Flora.Model.PackageGroup.Types (PackageGroup, PackageGroupId)
import Flora.Model.PackageGroup.Types (PackageGroup (..), PackageGroupId (..))
import Flora.Model.PackageGroupPackage.Types (PackageGroupPackage (..))

getPackagesByPackageGroupId :: DB :> es => PackageGroupId -> Eff es (Vector Package)
getPackagesByPackageGroupId packageGroupId = dbtToEff $ query Select q (Only packageGroupId)
where
q =
[sql|
SELECT p.*
FROM packages AS p
JOIN package_group_packages AS pgp
ON p.package_id = pgp.package_id
WHERE pgp.package_group_id = ?
|]
getPackagesByPackageGroupId packageGroupId =
dbtToEff $
joinSelectOneByField
@Package
@PackageGroupPackage
[field| package_id |]
[field| package_group_id |]
packageGroupId

getPackageGroupByPackageGroupName :: DB :> es => Text -> Eff es (Maybe PackageGroup)
getPackageGroupByPackageGroupName groupName = dbtToEff $ selectOneByField [field| group_name |] (Only groupName)
1 change: 0 additions & 1 deletion src/core/Flora/Model/PackageGroup/Types.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Flora.Model.PackageGroup.Types where

import GHC.Generics

import Control.DeepSeq (NFData)
import Data.Aeson
import Data.Text (Text)
Expand Down
6 changes: 3 additions & 3 deletions test/Flora/PackageGroupSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ testAddPackageToPackageGroup = do
.~ pure user.userId
packageGroup <-
instantiatePackageGroup randomPackageGroupTemplate
packageGroupPackage <-
void $
instantiatePackageGroupPackage $
randomPackageGroupPackageTemplate
& #packageGroupId
Expand All @@ -75,7 +75,7 @@ testRemovePackageFromPackageGroup = do
.~ pure user.userId
packageGroup <-
instantiatePackageGroup randomPackageGroupTemplate
packageGroupPackage <-
void $
instantiatePackageGroupPackage $
randomPackageGroupPackageTemplate
& #packageGroupId
Expand All @@ -99,7 +99,7 @@ testGetPackagesByPackageGroupId = do
.~ pure user.userId
packageGroup <-
instantiatePackageGroup randomPackageGroupTemplate
packageGroupPackage <-
void $
instantiatePackageGroupPackage $
randomPackageGroupPackageTemplate
& #packageGroupId
Expand Down

0 comments on commit 97d19ef

Please sign in to comment.