Skip to content
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

Merged
merged 13 commits into from
Nov 2, 2023
Merged

Post article #184

merged 13 commits into from
Nov 2, 2023

Conversation

arioston
Copy link
Contributor

@arioston arioston commented Oct 8, 2023

This PR resolves issue #160


fun Application.articleRoutes(articleService: ArticleService, jwtService: JwtService) = routing {
route("/articles") {
post {
Copy link
Contributor Author

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?

Copy link
Owner

Choose a reason for hiding this comment

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

  1. 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 using executeOne { /** transform properties to business logic domain */ }.

  2. You can check validations.kt for validation, I think it already includes all validation checks. body, description, title and tags. So something like:

fun NewArticle.validate(): Either<IncorrectInput, NewArticle> =
  zipOrAccumulate(
      title.validTitle(),
      description.validDescription(),
      body.validBody(),
      validTags(tags)
      :: NewArticle
    )
    .mapLeft(::IncorrectInput)

Copy link
Owner

@nomisRev nomisRev left a 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 {
Copy link
Owner

Choose a reason for hiding this comment

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

  1. 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 using executeOne { /** transform properties to business logic domain */ }.

  2. You can check validations.kt for validation, I think it already includes all validation checks. body, description, title and tags. 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.
@arioston
Copy link
Contributor Author

@nomisRev Thank you for all the assistance with those PRs; I have learned a lot.

Copy link
Owner

@nomisRev nomisRev left a 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 ☺️ Sorry for the slow review, I was sick all week 🤒

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.

arioston and others added 6 commits October 29, 2023 18:14
…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
Copy link
Owner

@nomisRev nomisRev left a 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 👏 👏 👏

@nomisRev nomisRev merged commit 3bcb3db into nomisRev:main Nov 2, 2023
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