diff --git a/fundamentals/minimal-apis/samples/MultipleResultTypes/MultipleResultTypes.csproj b/fundamentals/minimal-apis/samples/MultipleResultTypes/MultipleResultTypes.csproj new file mode 100644 index 0000000..45a6b21 --- /dev/null +++ b/fundamentals/minimal-apis/samples/MultipleResultTypes/MultipleResultTypes.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + + diff --git a/fundamentals/minimal-apis/samples/MultipleResultTypes/Program.cs b/fundamentals/minimal-apis/samples/MultipleResultTypes/Program.cs new file mode 100644 index 0000000..54a5156 --- /dev/null +++ b/fundamentals/minimal-apis/samples/MultipleResultTypes/Program.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Http.HttpResults; +using Microsoft.AspNetCore.OpenApi; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddSingleton>((sp) => +{ + return new(){ + new Book(1, "Testing Dot", "John Doe"), + new Book(2, "Learn Linq", "Rick Perry"), + new Book(3, "Generics", "Dalis Chevy"), + new Book(4, "Testing the Mic", "Bob Tik"), + new Book(5, "Drop the Dot", "Farmy Lix"), +}; +}); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.MapGet("/book{id}", Results, NotFound> (int id, List bookList) => +{ + return bookList.FirstOrDefault((i) => i.Id == id) is Book book + ? TypedResults.Ok(book) + : TypedResults.NotFound(); +}); + +app.Run(); +record Book(int Id, string Title, string Author); diff --git a/fundamentals/minimal-apis/samples/MultipleResultTypes/appsettings.Development.json b/fundamentals/minimal-apis/samples/MultipleResultTypes/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/fundamentals/minimal-apis/samples/MultipleResultTypes/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/fundamentals/minimal-apis/samples/MultipleResultTypes/appsettings.json b/fundamentals/minimal-apis/samples/MultipleResultTypes/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/fundamentals/minimal-apis/samples/MultipleResultTypes/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}