diff --git a/src/Api/Controllers/V1/SampleController.cs b/src/Api/Controllers/V1/SampleController.cs new file mode 100644 index 0000000..99ec6bc --- /dev/null +++ b/src/Api/Controllers/V1/SampleController.cs @@ -0,0 +1,51 @@ +namespace Api.Controllers.V1 +{ + using Asp.Versioning; + using Domain.Entities; + using Domain.Interfaces; + using Microsoft.AspNetCore.Mvc; + + /// + /// Represents the sample controller. + /// + [ApiController] + [Route("sample")] + [Tags("sample")] + [ApiVersion("1.0")] + public class SampleController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching", + }; + + private readonly IRepository repository; + + /// + /// Initializes a new instance of the class. + /// + /// The repository. + public SampleController(IRepository repository) + { + this.repository = repository; + } + + /// + /// Gets the weather forecast. + /// + /// The weather forecast. + [HttpGet] + public async Task> Get() + { + this.repository.Add(new SampleEntity { Name = "Sample-1" }); + var result = await this.repository.ListAsync(); + var forecast = Enumerable.Range(1, 5).Select(index => + new WeatherForecast( + DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + Random.Shared.Next(-20, 55), + Summaries[Random.Shared.Next(Summaries.Length)])) + .ToArray(); + return forecast; + } + } +} diff --git a/src/Infra/Data/DataContext.cs b/src/Infra/Data/DataContext.cs index eced47b..53e89cd 100644 --- a/src/Infra/Data/DataContext.cs +++ b/src/Infra/Data/DataContext.cs @@ -1,10 +1,19 @@ using Domain.Entities; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Serilog; + namespace Infra.Data; public class DataContext : DbContext { public DataContext(DbContextOptions opts) : base(opts) { } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.LogTo(message => Log.Information(message)); + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Products => Set(); } \ No newline at end of file diff --git a/src/Infra/Infra.csproj b/src/Infra/Infra.csproj index 9806bce..8a6bc7c 100644 --- a/src/Infra/Infra.csproj +++ b/src/Infra/Infra.csproj @@ -7,11 +7,20 @@ + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all + \ No newline at end of file