mirror of
https://github.com/PacktPublishing/Web-Development-with-Blazor-Second-Edition.git
synced 2026-04-08 07:43:53 +00:00
Initial commit
This commit is contained in:
parent
2190113c56
commit
3088165398
1765 changed files with 192085 additions and 0 deletions
|
|
@ -0,0 +1,43 @@
|
|||
using Data.Models;
|
||||
using Data.Models.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BlazorWebAssembly.Server.Endpoints;
|
||||
public static class BlogPostEndpoints
|
||||
{
|
||||
public static void MapBlogPostApi(this WebApplication app)
|
||||
{
|
||||
app.MapGet("/api/BlogPosts",
|
||||
async (IBlogApi api, [FromQuery] int numberofposts, [FromQuery] int startindex) =>
|
||||
{
|
||||
return Results.Ok(await api.GetBlogPostsAsync(numberofposts, startindex));
|
||||
});
|
||||
|
||||
app.MapGet("/api/BlogPostCount",
|
||||
async (IBlogApi api) =>
|
||||
{
|
||||
return Results.Ok(await api.GetBlogPostCountAsync());
|
||||
});
|
||||
|
||||
app.MapGet("/api/BlogPosts/{*id}",
|
||||
async (IBlogApi api, string id) =>
|
||||
{
|
||||
return Results.Ok(await api.GetBlogPostAsync(id));
|
||||
});
|
||||
|
||||
app.MapPut("/api/BlogPosts",
|
||||
async (IBlogApi api, [FromBody] BlogPost item) =>
|
||||
{
|
||||
return Results.Ok(await api.SaveBlogPostAsync(item));
|
||||
}).RequireAuthorization();
|
||||
|
||||
app.MapDelete("/api/BlogPosts/{*id}",
|
||||
async (IBlogApi api, string id) =>
|
||||
{
|
||||
await api.DeleteBlogPostAsync(id);
|
||||
return Results.Ok();
|
||||
}).RequireAuthorization();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue