Repository navigation
refactor(projects): cleaner value objects usage in addProject route (DEV-119) - #1920
Conversation
irinaschubert
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
Is fold still needed? Can't it be done with Validation.validateWith as in the ProjectsRouteADM.scala?
There was a problem hiding this comment.
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.") |
| /* 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) | ||
|
|
| 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), |
| 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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
See above, can't fold be omitted?
mpro7
left a comment
There was a problem hiding this comment.
LGTM, but please answer my comment.
| /** | ||
| * Project payload | ||
| */ | ||
| final case class ProjectCreatePayloadADM( |
There was a problem hiding this comment.
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.
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.
RoutePayloadsADM => ProjectPayloadsADM.scala, GroupPayloadsADM.scala, etc.
RouteValueObjects => ProjectValueObjectsADM.scala, GroupValueObjectsADM.scala, etc.
There was a problem hiding this comment.
also, anything that is shared, should be inside a SharedValueObjectsADM.scala to make it obvious.
There was a problem hiding this comment.
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.
resolves DEV-119