-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApi.cs
More file actions
29 lines (23 loc) · 1.04 KB
/
Api.cs
File metadata and controls
29 lines (23 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using static FreeAwait.HttpSteps;
namespace MinimalWebApi;
public static class Api
{
public static async IStep<IAsyncEnumerable<Todo>> Get() =>
await (await new ReadAll())
.Select(item => new Locate(item))
.Sequence();
public static async IStep<Todo> Post(Create create) => await new Locate(await create);
public static async IStep<IResult> Get(int id) =>
await new Read(id) is { } item
? await new Ok(await new Locate(item))
: await new NotFound();
public static async IStep<IResult> Delete(int id) =>
await new Delete(id) is { } item
? await new Ok(await new Locate(item))
: await new NotFound();
public static IStep<IResult> Delete() => new DeleteAll().PassTo(_ => new NoContent());
public static async IStep<IResult> Patch(int id, Patch patch) =>
await new Update(id, patch) is { } item
? await new Ok(await new Locate(item))
: await new NotFound();
}