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

Feature/get profile by username #186

Merged
merged 20 commits into from
Nov 2, 2023

Conversation

MarinJuricev
Copy link
Contributor

This PR attempts to solve the following issue 154

Missing piece:

  • A test that covers this scenario Get profile with following ( at the time of this PR the FollowPersistence isn't implemented ) and that's preventing us from setting that flow in ProfileRouteSpec

Any feedback is welcome as BE/Ktor is not my strong suite.

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.

Nice work @MarinJuricev! Even with tests 🙌
1 remark, and two nits ☺️ Let me know if anything is unclear.

Thanks for contributing, and happy hacktoberfest 👻

src/main/kotlin/io/github/nomisrev/routes/profile.kt Outdated Show resolved Hide resolved
src/main/kotlin/io/github/nomisrev/routes/profile.kt Outdated Show resolved Hide resolved
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType

class ProfileRouteSpec :
Copy link
Owner

Choose a reason for hiding this comment

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

We're missing a test case for when the path parameter is missing, I think that would've resulted MissingRequestParameterException case.

Copy link
Contributor Author

@MarinJuricev MarinJuricev Oct 21, 2023

Choose a reason for hiding this comment

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

I assume that the endpoint that we'd want to hit/test is api/profiles/ and assert that our new validation is triggered

However, I'm having difficulties actually hitting the above endpoint with the current Resource setup, I get 404 not found.

I've read through the docs, and tried with the ? approach, but with no luck.

@Resource("/{$USERNAME?}")
data class Username(val parent: ProfileResource = ProfileResource(), val username: String)

Do you have any suggestions?

Copy link
Owner

Choose a reason for hiding this comment

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

Strange, I made a small change and it's working fine for me.

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'm probably missing something obvious, I've tried various things to trigger the api/profiles logic.

The username implementation is marked as optional and a placeholder test that fails on my side is added here

I've tried also to write it without the @Resource implementation so that I just hit /api/profiles, but with no luck 🤷

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.

For me it's working with the small change I suggested. Could you check if this works for you, if not can you add the failing test case so I can try and reproduce it locally?

Sorry for the delay in reviewing, I was sick this week 🤒

Thanks again for your interest, and contribution!

import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType

class ProfileRouteSpec :
Copy link
Owner

Choose a reason for hiding this comment

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

Strange, I made a small change and it's working fine for me.

@@ -0,0 +1,42 @@
package io.github.nomisrev.routes
Copy link
Owner

Choose a reason for hiding this comment

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

I had to add this for detekt, I'd prefer not to change the filename. Perhaps we should disable this rule in some other issue.

Suggested change
package io.github.nomisrev.routes
@file:Suppress("MatchingDeclarationName")
package io.github.nomisrev.routes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, having to force every routes implementation to add the @file:Suppress for detekt isn't deal, something for a future PR 😄

Addressed in 76bea8b

Comment on lines 27 to 44
get<ProfileResource.Username> {
either {
val username = parameter(USERNAME) { it }.bind()
repo.selectProfile(username).bind()
}
.respond(HttpStatusCode.OK)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Type safe routing from Ktor gives us acces to an ProfileResource.Username instance, and thus safe acces to username.

Spotless also required a small formatting.

Suggested change
get<ProfileResource.Username> {
either {
val username = parameter(USERNAME) { it }.bind()
repo.selectProfile(username).bind()
}
.respond(HttpStatusCode.OK)
}
get<ProfileResource.Username> { route ->
either { repo.selectProfile(route.username).bind() }.respond(HttpStatusCode.OK)
}

Copy link
Contributor Author

@MarinJuricev MarinJuricev Oct 31, 2023

Choose a reason for hiding this comment

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

Wasn't aware of that TIL, addressed in: 8c1113f

@MarinJuricev MarinJuricev force-pushed the feature/GET-profile-by-username branch from 8b1f498 to 64dbe4d Compare October 31, 2023 19:46
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 @MarinJuricev! Thank you so much for the contribution 👏 👏 👏

@nomisRev nomisRev merged commit 4c27ef8 into nomisRev:main Nov 2, 2023
@MarinJuricev
Copy link
Contributor Author

Awesome, thanks for your time @nomisRev had a blast doing this mini contribution.

I'll try to snag another issue in the near future 😄

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.

2 participants