Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/Api/Controllers/V1/SampleController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace Api.Controllers.V1
{
using Asp.Versioning;
using Domain.Entities;
using Domain.Interfaces;
using Microsoft.AspNetCore.Mvc;

/// <summary>
/// Represents the sample controller.
/// </summary>
[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<SampleEntity> repository;

/// <summary>
/// Initializes a new instance of the <see cref="SampleController"/> class.
/// </summary>
/// <param name="repository">The repository.</param>
public SampleController(IRepository<SampleEntity> repository)
{
this.repository = repository;
}

/// <summary>
/// Gets the weather forecast.
/// </summary>
/// <returns>The weather forecast.</returns>
[HttpGet]
public async Task<IEnumerable<WeatherForecast>> 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;
}
}
}
9 changes: 9 additions & 0 deletions src/Infra/Data/DataContext.cs
Original file line number Diff line number Diff line change
@@ -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<DataContext> opts) : base(opts) { }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.LogTo(message => Log.Information(message));
base.OnConfiguring(optionsBuilder);
}

public virtual DbSet<SampleEntity> Products => Set<SampleEntity>();
}
9 changes: 9 additions & 0 deletions src/Infra/Infra.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Domain/Domain.csproj" />

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />

<PackageReference Include="Serilog" Version="4.2.0" />

<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />

<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.4" />
</ItemGroup>
</Project>