Skip to content

refactor(projects): cleaner value objects usage in addProject route (DEV-119) - #1920

Merged
subotic merged 7 commits into
mainfrom
wip/DEV-119-cleaner-value-objects-usage
Oct 13, 2021
Merged

subotic merged 7 commits into
mainfrom
wip/DEV-119-cleaner-value-objects-usage

Conversation

@subotic

@subotic subotic commented Oct 8, 2021

Copy link
Copy Markdown
Collaborator

resolves DEV-119

@subotic subotic self-assigned this Oct 8, 2021
Comment thread webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteADM.scala Outdated
Comment thread webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteADM.scala Outdated

@irinaschubert irinaschubert left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically just one comment (just added it on several locations). Apart from that I think it looks good.

/**
* Helper method converting an [[Either]] to a [[Future]].
*/
def toFuture[A](either: Either[Throwable, A]): Future[A] = either.fold(Future.failed, Future.successful)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)?

password = Password.create(apiRequest.password).fold(error => throw error, value => value),
status = Status.create(apiRequest.status).fold(error => throw error, value => value),
status = Status.make(apiRequest.status).fold(error => throw error.head, value => value),
lang = LanguageCode.create(apiRequest.lang).fold(error => throw error, value => value),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is fold still needed? Can't it be done with Validation.validateWith as in the ProjectsRouteADM.scala?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation.validateWith needs all inputs to be of Validation type. The change can be done in another PR.

val newStatus = apiRequest.status match {
case Some(status) => Status.create(status).fold(error => throw error, value => value)
case Some(status) => Status.make(status).fold(error => throw error.head, value => value)
case None => throw BadRequestException("The status is missing.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, is fold needed?

/* update existing user's status to false */
val status = Status.create(false).fold(error => throw error, value => value)
val status = Status.make(false).fold(error => throw error.head, value => value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, is fold needed?

password = Password.create(createUserApiRequestADM.password).fold(error => throw error, value => value),
status = Status.create(createUserApiRequestADM.status).fold(error => throw error, value => value),
status = Status.make(createUserApiRequestADM.status).fold(error => throw error.head, value => value),
lang = LanguageCode.create(createUserApiRequestADM.lang).fold(error => throw error, value => value),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, is fold needed?

userIri = SharedTestDataADM.normalUser.id,
status = Status.create(false).fold(error => throw error, value => value),
status = Status.make(false).fold(error => throw error.head, value => value),
featureFactoryConfig = defaultFeatureFactoryConfig,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, can't fold be omitted?

userIri = SharedTestDataADM.normalUser.id,
status = Status.create(true).fold(error => throw error, value => value),
status = Status.make(true).fold(error => throw error.head, value => value),
featureFactoryConfig = defaultFeatureFactoryConfig,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, can't fold be omitted?

userIri = SharedTestDataADM.superUser.id,
status = Status.create(false).fold(error => throw error, value => value),
status = Status.make(false).fold(error => throw error.head, value => value),
featureFactoryConfig = defaultFeatureFactoryConfig,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, can't fold be omitted?

userIri = KnoraSystemInstances.Users.SystemUser.id,
status = Status.create(false).fold(error => throw error, value => value),
status = Status.make(false).fold(error => throw error.head, value => value),
featureFactoryConfig = defaultFeatureFactoryConfig,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, can't fold be omitted?

userIri = KnoraSystemInstances.Users.AnonymousUser.id,
status = Status.create(false).fold(error => throw error, value => value),
status = Status.make(false).fold(error => throw error.head, value => value),
featureFactoryConfig = defaultFeatureFactoryConfig,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, can't fold be omitted?

@subotic
subotic requested a review from mpro7 October 13, 2021 07:02

@mpro7 mpro7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please answer my comment.

/**
* Project payload
*/
final case class ProjectCreatePayloadADM(

Copy link
Copy Markdown
Contributor

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)?

Copy link
Copy Markdown
Collaborator Author

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.

@subotic subotic Oct 13, 2021 •

Copy link
Copy Markdown
Collaborator Author

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.

Copy link
Copy Markdown
Collaborator Author

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.

Copy link
Copy Markdown
Contributor

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.

@subotic
subotic merged commit 32b9e49 into main Oct 13, 2021
@subotic
subotic deleted the wip/DEV-119-cleaner-value-objects-usage branch October 13, 2021 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants