[ASP.NET] 엔드 포인트 CRUD

VS 에서 엔드포인트 CRUD 로 API 컨트롤러를 생성하면 모델에 생성됨

using Microsoft.AspNetCore.OpenApi;
using Microsoft.AspNetCore.Http.HttpResults;
namespace CoreMVCProject.Models
{
    public class BookCate
    {
        public int idx { get; set; }
        public string? book_cate_name { get; set; }
        public string? del_yn { get; set; }
        public string? book_set_name { get; set; }
        
    }


public static class BookCateEndpoints
{
    public static void MapBookCateEndpoints (this IEndpointRouteBuilder routes)
    {
        var group = routes.MapGroup("/api/BookCate").WithTags(nameof(BookCate));

        group.MapGet("/", () =>
        {
            return new [] { new BookCate() };
        })
        .WithName("GetAllBookCates")
        .WithOpenApi();

        group.MapGet("/{id}", (int id) =>
        {
            //return new BookCate { ID = id };
        })
        .WithName("GetBookCateById")
        .WithOpenApi();

        group.MapPut("/{id}", (int id, BookCate input) =>
        {
            return TypedResults.NoContent();
        })
        .WithName("UpdateBookCate")
        .WithOpenApi();

        group.MapPost("/", (BookCate model) =>
        {
            //return TypedResults.Created($"/api/BookCates/{model.ID}", model);
        })
        .WithName("CreateBookCate")
        .WithOpenApi();

        group.MapDelete("/{id}", (int id) =>
        {
            //return TypedResults.Ok(new BookCate { ID = id });
        })
        .WithName("DeleteBookCate")
        .WithOpenApi();
    }
}}
guest
0 Comments
Inline Feedbacks
View all comments