-
Notifications
You must be signed in to change notification settings - Fork 36
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
Post article #184
Post article #184
Conversation
|
||
fun Application.articleRoutes(articleService: ArticleService, jwtService: JwtService) = routing { | ||
route("/articles") { | ||
post { |
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 have some questions:
1 - Since there's no articleId
on the specification, how should we proceed with it here?
2 - how should we implement validations?
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 we need to add an
ArticleResponse
that matches the specification. So we have 3 models, the one matching the OpenAPI, the one used in our business logic domain, and the one used in our database. The database model is generated by SqlDelight, and is typically ignored by usingexecuteOne { /** transform properties to business logic domain */ }
. -
You can check
validations.kt
for validation, I think it already includes all validation checks.body
,description
,title
andtags
. So something like:
fun NewArticle.validate(): Either<IncorrectInput, NewArticle> =
zipOrAccumulate(
title.validTitle(),
description.validDescription(),
body.validBody(),
validTags(tags)
:: NewArticle
)
.mapLeft(::IncorrectInput)
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.
Looks really good to me @arioston! I answered your questions, hope that clarifies things.
I'm very sorry for the delay in code review 🙏
Thank you for taking interest in the project 🙌
|
||
fun Application.articleRoutes(articleService: ArticleService, jwtService: JwtService) = routing { | ||
route("/articles") { | ||
post { |
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 we need to add an
ArticleResponse
that matches the specification. So we have 3 models, the one matching the OpenAPI, the one used in our business logic domain, and the one used in our database. The database model is generated by SqlDelight, and is typically ignored by usingexecuteOne { /** transform properties to business logic domain */ }
. -
You can check
validations.kt
for validation, I think it already includes all validation checks.body
,description
,title
andtags
. So something like:
fun NewArticle.validate(): Either<IncorrectInput, NewArticle> =
zipOrAccumulate(
title.validTitle(),
description.validDescription(),
body.validBody(),
validTags(tags)
:: NewArticle
)
.mapLeft(::IncorrectInput)
This change was made due to the modification of the extension function.
@nomisRev Thank you for all the assistance with those PRs; I have learned a lot. |
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.
Hey @arioston,
It's my pleasure! I am happy to hear you've learned a lot
The PR looks perfect, but due to your question of the nullability I think we can optimise some stuff away.
By using a default argument of = emptyList()
the parameter remains optional, and we rely on emptyList as a default value. We could've used null
, but that is IMHO only valuable if the logic is different depending on the value being present or not. Which is not the case here.
Co-authored-by: Simon Vergauwen <[email protected]>
Co-authored-by: Simon Vergauwen <[email protected]>
Co-authored-by: Simon Vergauwen <[email protected]>
…into post-article � Conflicts: � src/main/kotlin/io/github/nomisrev/routes/articles.kt � src/main/kotlin/io/github/nomisrev/routes/root.kt � src/main/kotlin/io/github/nomisrev/validation.kt � src/test/kotlin/io/github/nomisrev/routes/ArticleRouteSpec.kt
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.
Perfect @arioston! Thank you 👏 👏 👏
This PR resolves issue #160