New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(v3): add role slice (DEV-1010) #2099
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8e423b2
add sbt projects and dependencies
mpro7 3bc38be
add role domain
mpro7 fdf553e
Merge branch 'main' into DEV-1010-dsp-api-add-role-slice
mpro7 bdb71bf
add Role value objects + fix build
mpro7 3b259b6
add LangString value object
mpro7 7019fa6
add RoleIri value object + tests
mpro7 871b54c
update RoleId + LangString
mpro7 7616e84
add role test data + domain tests
mpro7 540f897
Merge branch 'main' into DEV-1010-dsp-api-add-role-slice
mpro7 a94da9d
add role repo implementation
mpro7 9103d38
add permission value object + update LangString
mpro7 835744f
Merge branch 'main' into DEV-1010-dsp-api-add-role-slice
mpro7 bd1b154
naming improvements
mpro7 adfaefe
add interface placeholders
mpro7 4fc0db2
add RoleRepoMock
mpro7 8043329
fix RoleRepoSpec name
mpro7 740c345
add RoleHandler + tests
mpro7 3f8cb1d
add RoleRepoLive + tests
mpro7 5a29941
update docs + cleanup
mpro7 b1b8cc1
forgotten docs
mpro7 ab4c9ee
Merge branch 'main' into DEV-1010-dsp-api-add-role-slice
mpro7 7a6bcc5
review changes
mpro7 5d9794a
Merge branch 'main' into DEV-1010-dsp-api-add-role-slice
mpro7 052f6c5
fix merge issues
mpro7 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright © 2021 - 2022 Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dsp.role.api | ||
|
||
import dsp.role.domain.Role | ||
import dsp.valueobjects.Id.RoleId | ||
import zio._ | ||
import zio.macros.accessible | ||
|
||
/** | ||
* The trait (interface) for the role repository. | ||
* The role repository is responsible for storing and retrieving roles. | ||
* Needs to be used by the role repository implementations. | ||
*/ | ||
@accessible | ||
trait RoleRepo { | ||
|
||
/** | ||
* Writes a role into the repository, while both creating or updating a role. | ||
* | ||
* @param r the [[Role]] to write | ||
* @return the [[RoleId]] | ||
*/ | ||
def storeRole(role: Role): UIO[RoleId] | ||
|
||
/** | ||
* Gets all roles from the repository. | ||
* | ||
* @return a list of [[Role]] | ||
*/ | ||
def getRoles(): UIO[List[Role]] | ||
|
||
/** | ||
* Retrieves a role from the repository. | ||
* | ||
* @param id the role's ID | ||
* @return the [[Role]] if found | ||
*/ | ||
def getRoleById(id: RoleId): IO[Option[Nothing], Role] | ||
|
||
// should the role name be unique like username??? | ||
|
||
/** | ||
* Deletes the [[Role]] from the repository by its [[RoleId]] | ||
* | ||
* @param id the role ID | ||
* @return the [[RoleId]] of the deleted role, if found | ||
*/ | ||
def deleteRole(id: RoleId): IO[Option[Nothing], RoleId] | ||
} |
122 changes: 122 additions & 0 deletions
122
dsp-role/core/src/main/scala/dsp/role/domain/RoleDomain.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright © 2021 - 2022 Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dsp.role.domain | ||
|
||
import dsp.errors.BadRequestException | ||
import dsp.valueobjects.Id.RoleId | ||
import dsp.valueobjects.Id.UserId | ||
import dsp.valueobjects.Permission | ||
import dsp.valueobjects.Role._ | ||
import zio.prelude.Validation | ||
|
||
case class RoleUser( | ||
id: UserId | ||
) | ||
|
||
/** | ||
* Role's domain entity. | ||
* | ||
* @param id the role's ID | ||
* @param name the role's name | ||
* @param description the role's description | ||
* @param users the role's users | ||
* @param permission the role's permission | ||
*/ | ||
sealed abstract case class Role private ( | ||
id: RoleId, | ||
name: LangString, | ||
description: LangString, | ||
users: List[RoleUser], // how to reperesnt the user here? | ||
permission: Permission | ||
) extends Ordered[Role] { self => | ||
|
||
/** | ||
* Allows to compare the [[Role]] instances. | ||
* | ||
* @param that [[Role]] to compare | ||
* @return [[Boolean]] value | ||
*/ | ||
def compare(that: Role): Int = self.id.iri.toString().compareTo(that.id.iri.toString()) | ||
|
||
/** | ||
* Updates the role's name with new value. | ||
* | ||
* @param newValue new role's name to update | ||
* @return updated [[Role]] | ||
*/ | ||
def updateName(newValue: LangString): Validation[BadRequestException, Role] = | ||
Role.make( | ||
self.id, | ||
newValue, | ||
self.description, | ||
self.users, | ||
self.permission | ||
) | ||
|
||
/** | ||
* Updates the role's description with new value. | ||
* | ||
* @param newValue new role's description to update | ||
* @return updated [[Role]] | ||
*/ | ||
def updateDescription(newValue: LangString): Validation[BadRequestException, Role] = | ||
mpro7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Role.make( | ||
self.id, | ||
self.name, | ||
newValue, | ||
self.users, | ||
self.permission | ||
) | ||
|
||
/** | ||
* Updates the role's users with new value. | ||
* | ||
* @param newValue new role's users to update | ||
* @return updated [[Role]] | ||
*/ | ||
def updateUsers(newValue: List[RoleUser]): Validation[BadRequestException, Role] = | ||
mpro7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Role.make( | ||
self.id, | ||
self.name, | ||
self.description, | ||
newValue, | ||
self.permission | ||
) | ||
|
||
/** | ||
* Updates the role's permission with new value. | ||
* | ||
* @param newValue new role's permission to update | ||
* @return updated [[Role]] | ||
*/ | ||
def updatePermission(newValue: Permission): Validation[BadRequestException, Role] = | ||
mpro7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Role.make( | ||
self.id, | ||
self.name, | ||
self.description, | ||
self.users, | ||
newValue | ||
) | ||
} | ||
|
||
object Role { | ||
def make( | ||
id: RoleId, | ||
name: LangString, | ||
description: LangString, | ||
users: List[RoleUser], | ||
permission: Permission | ||
): Validation[BadRequestException, Role] = | ||
Validation.succeed( | ||
new Role( | ||
id, | ||
name, | ||
description, | ||
users, | ||
permission | ||
) {} | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
dsp-role/core/src/test/scala/dsp/role/api/RoleApiSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright © 2021 - 2022 Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dsp.role.api | ||
|
||
/** | ||
* To be implemented... | ||
*/ | ||
object placeholder {} |
111 changes: 111 additions & 0 deletions
111
dsp-role/core/src/test/scala/dsp/role/domain/RoleDomainSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright © 2021 - 2022 Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dsp.role.domain | ||
|
||
import dsp.role.sharedtestdata.RoleTestData | ||
import dsp.valueobjects.Id | ||
import dsp.valueobjects.Permission | ||
import dsp.valueobjects.Role._ | ||
import zio.test._ | ||
|
||
/** | ||
* This spec is used to test [[RoleDomain]]. | ||
*/ | ||
object RoleDomainSpec extends ZIOSpecDefault { | ||
def spec = (compareRolesTest + createRoleTest + updateRoleTest) | ||
|
||
private val compareRolesTest = suite("compareRoles")( | ||
test("compare two roles") { | ||
val role = RoleTestData.role1 | ||
val equalRole = RoleTestData.role1 | ||
val nonEqualRole = RoleTestData.role2 | ||
|
||
assertTrue(role == equalRole) && | ||
assertTrue(role != nonEqualRole) | ||
} | ||
) | ||
|
||
private val createRoleTest = suite("createRole")( | ||
test("create a role") { | ||
( | ||
for { | ||
id <- RoleTestData.id1 | ||
name <- RoleTestData.name1 | ||
description <- RoleTestData.description1 | ||
users = RoleTestData.users1 | ||
permission <- RoleTestData.permission1 | ||
mpro7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
role <- Role.make( | ||
id, | ||
name, | ||
description, | ||
users = users, | ||
permission | ||
) | ||
} yield assertTrue(role.id == id) && | ||
assertTrue(role.name == name) && | ||
assertTrue(role.description == description) && | ||
assertTrue(role.users == users) && | ||
assertTrue(role.permission == permission) | ||
).toZIO | ||
} | ||
) | ||
|
||
private val updateRoleTest = suite("updateRole")( | ||
test("update the name") { | ||
( | ||
for { | ||
role <- RoleTestData.role1 | ||
newValue <- LangString.make("newRoleName", "en") | ||
updatedRole <- role.updateName(newValue) | ||
} yield assertTrue(updatedRole.name == newValue) && | ||
assertTrue(updatedRole.name != role.name) && | ||
assertTrue(updatedRole.description == role.description) && | ||
assertTrue(updatedRole.users == role.users) && | ||
assertTrue(updatedRole.permission == role.permission) | ||
).toZIO | ||
}, | ||
test("update the description") { | ||
( | ||
for { | ||
role <- RoleTestData.role1 | ||
newValue <- LangString.make("New Role Description", "en") | ||
updatedRole <- role.updateDescription(newValue) | ||
} yield assertTrue(updatedRole.name == role.name) && | ||
assertTrue(updatedRole.description == newValue) && | ||
assertTrue(updatedRole.description != role.description) && | ||
assertTrue(updatedRole.users == role.users) && | ||
assertTrue(updatedRole.permission == role.permission) | ||
).toZIO | ||
}, | ||
test("update the users") { | ||
( | ||
for { | ||
role <- RoleTestData.role1 | ||
newValue = List(RoleUser(Id.UserId.make().fold(e => throw e.head, v => v))) | ||
updatedRole <- role.updateUsers(newValue) | ||
} yield assertTrue(updatedRole.name == role.name) && | ||
assertTrue(updatedRole.description == role.description) && | ||
assertTrue(updatedRole.users == newValue) && | ||
assertTrue(updatedRole.users != role.users) && | ||
assertTrue(updatedRole.permission == role.permission) | ||
).toZIO | ||
}, | ||
test("update the permission") { | ||
( | ||
for { | ||
role <- RoleTestData.role1 | ||
newValue <- Permission.make(Permission.Create) | ||
updatedRole <- role.updatePermission(newValue) | ||
} yield assertTrue(updatedRole.name == role.name) && | ||
assertTrue(updatedRole.description == role.description) && | ||
assertTrue(updatedRole.users == role.users) && | ||
assertTrue(updatedRole.permission == newValue) && | ||
assertTrue(updatedRole.permission != role.permission) | ||
).toZIO | ||
} | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be more expressive, maybe even
newName
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In opposite to that
r: Role
here maybe the param name could be name/newName, because type doesn't say what it is, but:def updateName(newValue: LangString)
is very clear the method will update the Name and requires its new value inLangString
type to be passed