Skip to content

Commit

Permalink
minor: better filter support
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasteles committed Dec 26, 2023
1 parent 901bc8d commit 27bf4d2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion BasicApi/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let routes =
| None -> return !! NotFound()
})

routeGroup "profile" {
withGroup "profile" {
allowAnonymous

post
Expand Down
2 changes: 1 addition & 1 deletion FSharp.MinimalApi/Builder/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ let inline private implicit (x: ^a) : ^b =
let inline (!!) v = implicit v

let endpoints = EndpointsBuilder()
let routeGroup groupName = EndpointsBuilder groupName
let withGroup groupName = EndpointsBuilder groupName
9 changes: 7 additions & 2 deletions FSharp.MinimalApi/Builder/EndpointsBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ type EndpointsBuilder(?groupName: string) =
{ state with
MapFn = state.MapFn >> (fun e -> e.RequireAuthorization(policy)) }

[<CustomOperation("addFilter")>]
member _.AddFilter<'f when 'f :> IEndpointFilter>(state) =
[<CustomOperation("filter")>]
member _.Filter<'args, 'f when 'f :> IEndpointFilter>(state, ctor: 'args -> 'f) =
{ state with
MapFn = state.MapFn >> (fun e -> e.AddEndpointFilter<'f>()) }

[<CustomOperation("filter")>]
member _.Filter<'f when 'f :> IEndpointFilter>(state, filter: 'f) =
{ state with
MapFn = state.MapFn >> (fun e -> e.AddEndpointFilter(filter)) }

[<CustomOperation("filter")>]
member _.Filter
(
Expand Down
1 change: 0 additions & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ no-bump-message: "^(none|skip):"

branches:
master:
tag: beta
is-mainline: true
source-branches: []
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let routes =
})
// group mappping
routeGroup "profile" {
withGroup "profile" {
allowAnonymous
post
Expand Down

0 comments on commit 27bf4d2

Please sign in to comment.