mirror of
https://github.com/XFox111/PhonebookService.git
synced 2026-04-22 06:29:55 +03:00
Implemented API layer
This commit is contained in:
@@ -1,11 +1,32 @@
|
||||
using FluentValidation;
|
||||
using PhonebookService.Domain.Models;
|
||||
using PhonebookService.Domain.Validators;
|
||||
using PhonebookService.Infrastructure;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddLogging(options =>
|
||||
{
|
||||
options.AddConfiguration(builder.Configuration.GetSection("Logging"));
|
||||
options.AddConsole();
|
||||
options.AddDebug();
|
||||
options.AddEventSourceLogger();
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// Settings up infrastructure layer
|
||||
builder.Services.ConfigureInfrastructure(builder.Configuration, enableSensitiveDataLogging: builder.Environment.IsDevelopment());
|
||||
|
||||
// Adding validators
|
||||
builder.Services.AddScoped<IValidator<PhonebookRecord>, PhonebookRecordValidator>();
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
options.SwaggerDoc("v1", new() { Title = "PhonebookService API", Version = "v1" }));
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
@@ -13,7 +34,7 @@ WebApplication app = builder.Build();
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "PhonebookService API v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
@@ -22,4 +43,6 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.MapGet("/", () => Results.Redirect("/api/v1/Phonebook"));
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user