Repository navigation
refactor(projects): refactor projects route with value objects (DEV-64) - #1909
Conversation
|
|
||
| import org.knora.webapi.IRI | ||
|
|
||
| trait ProjectCreatePayloadTraitADM { |
There was a problem hiding this comment.
Trait is superfluous here.
There was a problem hiding this comment.
in this case you don't even need it, just delete it
|
|
||
| import org.knora.webapi.IRI | ||
|
|
||
| trait ProjectCreatePayloadTraitADM { |
|
|
||
| import org.knora.webapi.IRI | ||
|
|
||
| trait ProjectCreatePayloadTraitADM { |
There was a problem hiding this comment.
in this case you don't even need it, just delete it
| /** | ||
| * Project payload | ||
| */ | ||
| sealed abstract case class ProjectCreatePayloadADM( |
There was a problem hiding this comment.
@irinaschubert I found the example for smart constructors. There is a private keyword missing:
sealed abstract case class ProjectCreatePayloadADM private (
| case object InvalidPassword extends ValidationError | ||
| case object InvalidLanguageCode extends ValidationError | ||
|
|
||
| trait UserCreatePayloadTraitADM { |
There was a problem hiding this comment.
same here, trait is not needed.
There was a problem hiding this comment.
a trait can be seen as a kind of an interface. you don't need an interface here, at is only used here and nowhere else.
| /** | ||
| * Project shortcode value object. | ||
| */ | ||
| sealed abstract case class Shortcode(value: String) |
|
|
||
| import scala.util.matching.Regex | ||
|
|
||
| trait ValueObject[T, K] { |
There was a problem hiding this comment.
I don't like the ValueObject trait. It brings hardly any benefits, but makes the implementations look more complicated than necessary. Don't over engineer things. Please keep them simple.
There was a problem hiding this comment.
Do you mean by this, no trait at all here?
| case None => None | ||
| } | ||
|
|
||
| val project: ProjectCreatePayloadADM = |
There was a problem hiding this comment.
it is a projectCreatePayload and not a project.
| ) | ||
| } yield ProjectCreateRequestADM( | ||
| createRequest = apiRequest.validateAndEscape, | ||
| createRequest = project, |
There was a problem hiding this comment.
having project here is confusing, i.e., unexpected. code should never surprise.
There was a problem hiding this comment.
In typed languages it isn't that bad, because you always see what is under the variable due the type, so this can be even just p ;)
There was a problem hiding this comment.
impairs readability. I'm doing review exclusively in the browser, so no types.
There was a problem hiding this comment.
of course it works and can be anything. the compiler doesn't care. but code is read by humans.
|
looks good. |
| /** | ||
| * Project payload | ||
| */ | ||
| sealed abstract case class ProjectCreatePayloadADM private ( |
There was a problem hiding this comment.
strictly speaking this does not need a smart constructor, since it doesn't do any "smart" checks on it and could be written as a final case class ProjectCreatePayloadADM(...). We can leave it like it is and if no smart checks get added over time, then we can refactor it.
In addition to DEV-64 implementing escaping characters, which has been already done, we have added the value objects handling for projects route.