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

Add QueryParamEncoder[Instant] and QueryParamDecoder[Instant] #2724

Merged
merged 18 commits into from Aug 11, 2019

Conversation

@kevinmeredith
Copy link
Contributor

commented Jul 16, 2019

Addresses part of #2670.

Please take a look, @rossabaker and @LukaJCB.

@kevinmeredith

This comment has been minimized.

Copy link
Contributor Author

commented Jul 16, 2019

It seems slightly better to me if a single function produces both a QueryParamEncoder and QueryParamDecoder. Otherwise, a QueryParamEncoder[Instant] could be created with DateTimeFormatter.A, and then QueryParamDecoder[Instant] could be constructed with DateTimeFormatter.B.

@rossabaker
Copy link
Member

left a comment

Would a function that returns both return a tuple? There's no QueryParamCodec, or is that what you're proposing?

def instantQueryParamDecoder(formatter: DateTimeFormatter): QueryParamDecoder[Instant] =
new QueryParamDecoder[Instant] {
override def decode(value: QueryParameterValue): ValidatedNel[ParseFailure, Instant] =
Either

This comment has been minimized.

Copy link
@rossabaker

rossabaker Jul 17, 2019

Member

Validated has catchOnly and is a Bifunctor. I don't think you need the Either.

This comment has been minimized.

Copy link
@kevinmeredith

kevinmeredith Aug 6, 2019

Author Contributor

Done - 924c996

@kevinmeredith

This comment has been minimized.

Copy link
Contributor Author

commented Jul 17, 2019

Would a function that returns both return a tuple?

That seems reasonable to me, @rossabaker.

There's no QueryParamCodec, or is that what you're proposing?

Good question. I wasn't proposing that route. Looking at https://github.com/circe/circe/blob/v0.12.0-M4/modules/core/shared/src/main/scala/io/circe/Codec.scala#L7-L8, it shows that Codec is for convenience purposes only. What are your thoughts, @rossabaker?

@rossabaker

This comment has been minimized.

Copy link
Member

commented Jul 17, 2019

There is a good discussion of codec at circe/circe#133. I tend to agree with the desiderata and conclusion there.

Replace Either w/ Validated.
Ross suggested the change in #2724 (comment). I believe 'principle of least powerful abstraction' applies in this case.
Add QueryParamCodec.
I borrowed from circe/circe@56a88d0.

Ross pointed me to how circe handled Codec: #2724 (comment).
Add fromCodec methods to QueryParamEn(D)ecoder.
Rob Norris's third bullet point, circe/circe#133 (comment), motivated this change.
@kevinmeredith

This comment has been minimized.

Copy link
Contributor Author

commented Aug 6, 2019

There is a good discussion of codec at circe/circe#133. I tend to agree with the desiderata and conclusion there.

Thanks for pointing me to that link, @rossabaker. Could you please review the recent changes that I've made?

Add type annotation.
Use types to improve documentation.
@kevinmeredith

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2019

I closed, and then opened because a flaky test appears to have been the problem: https://travis-ci.org/http4s/http4s/jobs/568317642.

@kevinmeredith

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2019

Hey @ChristopherDavenport @LukaJCB, please take a look cc @rossabaker. Thanks!

decodeA.decode(value)
}

private def instantQueryParamDecoder(formatter: DateTimeFormatter): QueryParamDecoder[Instant] =

This comment has been minimized.

Copy link
@rossabaker

rossabaker Aug 9, 2019

Member

Why would this and instanctQueryParamDecoder not go on the companions of their respective typeclasses? The instantQueryParamCodec to join them makes sense, as does being explicit (because there's no default format).

This comment has been minimized.

Copy link
@kevinmeredith

kevinmeredith Aug 9, 2019

Author Contributor

Good point, Ross. I'll address that.

This comment has been minimized.

Copy link
@kevinmeredith

kevinmeredith Aug 9, 2019

Author Contributor

I initially thought you suggested moving instantQueryParamDecoder and instantQueryParamEncoder to QueryParamDecoder and QueryParamEncoder respectively. However, I already took that approach.

In short, I don't entirely follow your requested changes. Could you please say more, @rossabaker?

This comment has been minimized.

Copy link
@rossabaker

rossabaker Aug 9, 2019

Member

Aren't they in QueryParamCodec still? Maybe I need to check this out and not squint at a GitHub diff.

This comment has been minimized.

Copy link
@kevinmeredith

kevinmeredith Aug 10, 2019

Author Contributor

My mistake, Ross. You're right, instantQueryParamDecoder and instantQueryParamEncoder are defined in object QueryParamCodec. I'll move them to their respective companions. Sorry about that.

This comment has been minimized.

Copy link
@kevinmeredith

kevinmeredith Aug 10, 2019

Author Contributor

Done in the commits added at #2724 (commits).

@kevinmeredith

This comment has been minimized.

Copy link
Contributor Author

commented Aug 10, 2019

I'm figuring the build failed due to a flaky spec, @rossabaker?

[error] Failed: Total 65, Failed 1, Errors 0, Passed 61, Skipped 3, Pending 1
[error] Failed tests:
[error] org.http4s.client.blaze.Http1ClientStageSpec

@kevinmeredith

This comment has been minimized.

Copy link
Contributor Author

commented Aug 10, 2019

Maybe 212e350 will fix the, I'm guessing, flaky test.

@rossabaker
Copy link
Member

left a comment

No, unfortunately those blaze-client tests have been flaky on CI and only CI for a long time. I'll restart it, but this is not related to this PR.

@aeons aeons merged commit 1f823bc into http4s:series/0.20 Aug 11, 2019

2 checks passed

Summary no rules match, no planned actions
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kevinmeredith kevinmeredith deleted the kevinmeredith:query-support-instant branch Aug 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.