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 flash scope #2451

Merged
merged 1 commit into from
Sep 24, 2023
Merged

add flash scope #2451

merged 1 commit into from
Sep 24, 2023

Conversation

TomTriple
Copy link
Contributor

@TomTriple TomTriple commented Sep 19, 2023

This adds functionality for adding a message to the (cookie-based) flash scope and also a middleware for managing that scope automatically.

The message in the flash scope is kept for a single request only and is cleared afterwards by the provided middleware. At the moment one can only add a single string message to the flash scope. A more featureful implementation should provide support for a serialized key-value structure.

The implementation is still a bit rough (duplicate code ...), but it technically works as one would expect.

I could provide docs and support for key-value structure in a follow-up commit.

Adding middleware:

  override val run =
    Server.serve(appRoutes.toHttpApp @@ Middleware.flashScopeHandling).provide(Server.default)

Flash scope usage:

Response.seeOther("some url").addFlashMessage("overview not available at the moment")

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.05% ⚠️

Comparison is base (8780eb9) 64.21% compared to head (54ed9e9) 64.17%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2451      +/-   ##
==========================================
- Coverage   64.21%   64.17%   -0.05%     
==========================================
  Files         136      136              
  Lines        7118     7123       +5     
  Branches     1302     1245      -57     
==========================================
  Hits         4571     4571              
- Misses       2547     2552       +5     
Files Changed Coverage Δ
zio-http/src/main/scala/zio/http/Middleware.scala 73.13% <0.00%> (-2.26%) ⬇️
zio-http/src/main/scala/zio/http/Request.scala 43.90% <0.00%> (-2.26%) ⬇️
zio-http/src/main/scala/zio/http/Response.scala 40.47% <0.00%> (-0.49%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jdegoes jdegoes merged commit 037bc99 into zio:main Sep 24, 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