71 lines
1.6 KiB
C#
71 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var app = builder.Build();
|
|
|
|
app.MapGet("/", () =>
|
|
{
|
|
string[] saudacoes = ["Olá!", "こんにちは", "Привет", "Ողջույն"];
|
|
|
|
return saudacoes[Random.Shared.Next(saudacoes.Length)];
|
|
});
|
|
|
|
// Obtém uma lista com os livros registrados.
|
|
app.MapGet("/livros", () =>
|
|
{
|
|
return new Livro[]
|
|
{
|
|
new()
|
|
{
|
|
Isbn = "9780262510875",
|
|
Titulo = "Structure and Interpretation of Computer Programs",
|
|
Autor = "Gerald Jay Sussman"
|
|
},
|
|
new()
|
|
{
|
|
Isbn = "9780131103627",
|
|
Titulo = "C Programming Language: ANSI C Version",
|
|
Autor = "Dennis Ritchie, Brian Kerningham"
|
|
},
|
|
new()
|
|
{
|
|
Isbn = "9780134190440",
|
|
Titulo = "The Go Programming Language",
|
|
Autor = "Brian Kerningham"
|
|
}
|
|
};
|
|
});
|
|
|
|
// Cria um novo livro.
|
|
app.MapPost("/livros", (Livro livro) =>
|
|
{
|
|
return livro;
|
|
});
|
|
|
|
// Edita um livro.
|
|
app.MapPut("/livros/{isbn}", (string isbn, Livro livro) =>
|
|
{
|
|
return new { editando = isbn, dados = livro };
|
|
});
|
|
|
|
// Obtém os dados de um livro individual.
|
|
app.MapGet("/livros/{isbn}", (string isbn) =>
|
|
{
|
|
return new Livro() { Isbn = isbn };
|
|
});
|
|
|
|
// Remove um livro.
|
|
app.MapDelete("/livros/{isbn}", (string isbn) =>
|
|
{
|
|
return Results.NoContent();
|
|
});
|
|
|
|
app.Run();
|
|
|
|
public class Livro
|
|
{
|
|
public string? Isbn { get; set; }
|
|
public string? Titulo { get; set; }
|
|
public string? Autor { get; set; }
|
|
}; |