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(projects): cleaner value objects usage in addProject route (DEV-119) #1920
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
af4afa1
refactor(projects): cleaner value objects usage in addProject route
subotic cccf143
refactor(projects): cleaner value objects usage in addProject route
subotic a43ce8e
refactor(projects): use zio.prelude.Validation instead of Either
subotic 65bfb4e
refactor(projects): use zio.prelude.Validation instead of Either
subotic 1ae3337
refactor(projects): use zio.prelude.Validation instead of Either
subotic 51e7a44
Merge branch 'main' into wip/DEV-119-cleaner-value-objects-usage
subotic 6098139
Merge branch 'main' into wip/DEV-119-cleaner-value-objects-usage
subotic 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
28 changes: 28 additions & 0 deletions
28
.../org/knora/webapi/messages/admin/responder/projectsmessages/ProjectCreatePayloadADM.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,28 @@ | ||
package org.knora.webapi.messages.admin.responder.projectsmessages | ||
|
||
import org.knora.webapi.IRI | ||
import org.knora.webapi.messages.admin.responder.valueObjects.{ | ||
Shortname, | ||
Longname, | ||
Shortcode, | ||
Description, | ||
Keywords, | ||
Logo, | ||
Status, | ||
Selfjoin | ||
} | ||
|
||
/** | ||
* Project payload | ||
*/ | ||
final case class ProjectCreatePayloadADM( | ||
id: Option[IRI] = None, | ||
shortname: Shortname, | ||
shortcode: Shortcode, | ||
longname: Option[Longname], | ||
description: Description, | ||
keywords: Keywords, | ||
logo: Option[Logo], | ||
status: Status, | ||
selfjoin: Selfjoin | ||
) |
57 changes: 0 additions & 57 deletions
57
...scala/org/knora/webapi/messages/admin/responder/projectsmessages/ProjectPayloadsADM.scala
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ import org.knora.webapi.messages.admin.responder.projectsmessages.{ | |
} | ||
import org.knora.webapi.messages.admin.responder.usersmessages.UserADM | ||
import org.knora.webapi.settings.{KnoraDispatchers, KnoraSettings, KnoraSettingsImpl} | ||
import zio.prelude.Validation | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
|
@@ -159,4 +160,16 @@ abstract class KnoraRoute(routeData: KnoraRouteData) extends KnoraRouteFactory(r | |
)).mapTo[ProjectGetResponseADM] | ||
} yield projectInfoResponse.project | ||
} | ||
|
||
/** | ||
* Helper method converting an [[Either]] to a [[Future]]. | ||
*/ | ||
def toFuture[A](either: Either[Throwable, A]): Future[A] = either.fold(Future.failed, Future.successful) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this (i.e. do we still want to use Either in the future and not Validation everywhere)? |
||
|
||
/** | ||
* Helper method converting an [[zio.prelude.Validation]] to a [[Future]]. | ||
* FIXME: only the first error is returned, which defeats the purpose, but don't know better at the moment. | ||
*/ | ||
def toFuture[A](validation: Validation[Throwable, A]): Future[A] = | ||
validation.fold(errors => Future.failed(errors.head), Future.successful) | ||
} |
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
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.
You have moved updated class to the new file specific to the create method. Does it mean we should keep things separated like that - one class per file, or actually having all payloads in
ROUTEPayloadsXXX
would be better idea (if there would be more)?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.
I think that one RoutePayloadsADM file would be enough. There are not that many per route. There could also be a RouteValueObjects file, where the route specific value objects are defined.
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.
RoutePayloadsADM => ProjectPayloadsADM.scala, GroupPayloadsADM.scala, etc.
RouteValueObjects => ProjectValueObjectsADM.scala, GroupValueObjectsADM.scala, etc.
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.
also, anything that is shared, should be inside a SharedValueObjectsADM.scala to make it obvious.
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.
That was exactly my plan, but after our latest conversation about the modularisation I'm not sure if we should have shared value objects anymore.