Add profiles domain, infra, API endpoints
This commit is contained in:
@@ -10,4 +10,9 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.8"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RecNet.Infrastructure\RecNet.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\RecNet.ServiceDefaults\RecNet.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
@API_HostAddress = http://localhost:5155
|
||||
|
||||
GET {{API_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
6
API/Configurations/RecNetConfiguration.cs
Normal file
6
API/Configurations/RecNetConfiguration.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace API.Configurations;
|
||||
|
||||
public class RecNetConfiguration
|
||||
{
|
||||
public bool UseForwardedHeaders { get; set; } = true;
|
||||
}
|
||||
13
API/Contracts/Profiles/Requests/LoginRequest.cs
Normal file
13
API/Contracts/Profiles/Requests/LoginRequest.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using RecNet.Domain.Common;
|
||||
|
||||
namespace API.Contracts.Profiles.Requests;
|
||||
|
||||
public class LoginRequest
|
||||
{
|
||||
public required string AppVersion { get; set; }
|
||||
public required string DeviceId { get; set; }
|
||||
public required string PlatformAuthentication { get; set; }
|
||||
public required string PlatformId { get; set; }
|
||||
public PlatformType PlatformType { get; set; }
|
||||
public required string Username { get; set; }
|
||||
}
|
||||
8
API/Contracts/Profiles/Responses/LoginResponse.cs
Normal file
8
API/Contracts/Profiles/Responses/LoginResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using RecNet.Application.Profiles;
|
||||
|
||||
namespace API.Contracts.Profiles.Responses;
|
||||
|
||||
public class LoginResponse
|
||||
{
|
||||
public required ProfileDTO Profile { get; set; }
|
||||
}
|
||||
13
API/Controllers/Config/V1/ConfigController.cs
Normal file
13
API/Controllers/Config/V1/ConfigController.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace API.Controllers.Config.V1;
|
||||
|
||||
[Route("api/[controller]/v1")]
|
||||
[ApiController]
|
||||
public class ConfigController : ControllerBase
|
||||
{
|
||||
// TODO: Resolve from Database
|
||||
[HttpGet("motd")]
|
||||
public ActionResult<string> GetMotd()
|
||||
=> Ok("Hello World!");
|
||||
}
|
||||
64
API/Controllers/Profiles/V1/ProfilesController.cs
Normal file
64
API/Controllers/Profiles/V1/ProfilesController.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using API.Contracts.Profiles.Responses;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RecNet.Application.Profiles;
|
||||
using RecNet.Domain.Repositories;
|
||||
using LoginRequest = API.Contracts.Profiles.Requests.LoginRequest;
|
||||
using Profile = RecNet.Domain.Entities.Profiles.Profile;
|
||||
|
||||
namespace API.Controllers.Profiles.V1;
|
||||
|
||||
[Route("api/[controller]/v1")]
|
||||
[ApiController]
|
||||
public class ProfilesController(
|
||||
IProfileRepository profileRepository,
|
||||
IMapper mapper) : ControllerBase
|
||||
{
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<ActionResult<ProfileDTO>> GetProfile(
|
||||
Guid id,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var profile = await profileRepository.GetByIdAsync(id, ct);
|
||||
if (profile == null)
|
||||
return NotFound();
|
||||
|
||||
return mapper.Map<ProfileDTO>(profile);
|
||||
}
|
||||
|
||||
[HttpGet("bulk")]
|
||||
public async Task<IReadOnlyList<ProfileDTO>> GetBulkProfiles(
|
||||
[FromQuery(Name = "id")] List<Guid> ids,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var profiles = await profileRepository.GetByIdsAsync(ids, ct);
|
||||
|
||||
return mapper.Map<List<ProfileDTO>>(profiles);
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
[HttpPost("login")]
|
||||
public async Task<ActionResult<LoginResponse>> Login(
|
||||
[FromBody] LoginRequest request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var profile = await profileRepository.GetByPlatform(request.PlatformType, request.PlatformId, ct);
|
||||
if (profile is null)
|
||||
{
|
||||
profile = Profile.Create(request.Username, request.PlatformType, request.PlatformId);
|
||||
await profileRepository.AddAsync(profile, ct);
|
||||
}
|
||||
|
||||
profile.AddDeviceId(request.DeviceId);
|
||||
|
||||
if (request.Username != profile.Name)
|
||||
profile.SetName(request.Username);
|
||||
|
||||
await profileRepository.SaveChangesAsync(ct);
|
||||
|
||||
return new LoginResponse
|
||||
{
|
||||
Profile = mapper.Map<ProfileDTO>(profile)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
using API.Configurations;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using RecNet.Application;
|
||||
using RecNet.Infrastructure;
|
||||
using RecNet.ServiceDefaults;
|
||||
|
||||
namespace API;
|
||||
|
||||
public class Program
|
||||
@@ -5,28 +11,38 @@ public class Program
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var recNetOptions = builder.Configuration.GetSection("RecNet").Get<RecNetConfiguration>()
|
||||
?? new RecNetConfiguration();
|
||||
|
||||
// Add services to the container.
|
||||
builder.AddServiceDefaults();
|
||||
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders =
|
||||
ForwardedHeaders.XForwardedFor |
|
||||
ForwardedHeaders.XForwardedHost |
|
||||
ForwardedHeaders.XForwardedProto;
|
||||
options.KnownIPNetworks.Clear();
|
||||
options.KnownProxies.Clear();
|
||||
});
|
||||
|
||||
builder.Services.AddApplication();
|
||||
builder.AddInfrastructure();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (recNetOptions.UseForwardedHeaders)
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
// app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
app.MapDefaultEndpoints();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace API;
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user