53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using API.Contracts.Profiles.Responses;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using RecNet.Application.Profiles;
|
|
using LoginRequest = API.Contracts.Profiles.Requests.LoginRequest;
|
|
|
|
namespace API.Controllers.Profiles.V1;
|
|
|
|
[Route("api/[controller]/v1")]
|
|
[ApiController]
|
|
public class ProfilesController(IProfileService profileService) : ControllerBase
|
|
{
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<ActionResult<ProfileDTO>> GetProfile(
|
|
Guid id,
|
|
CancellationToken ct)
|
|
{
|
|
var profile = await profileService.GetProfileAsync(id, ct);
|
|
if (profile == null)
|
|
return NotFound();
|
|
|
|
return profile;
|
|
}
|
|
|
|
[HttpGet("bulk")]
|
|
public async Task<IReadOnlyList<ProfileDTO>> GetBulkProfiles(
|
|
[FromQuery(Name = "id")] List<Guid> ids,
|
|
CancellationToken ct)
|
|
=> await profileService.GetProfilesAsync(ids, ct);
|
|
|
|
[HttpPost("login")]
|
|
public async Task<ActionResult<LoginResponse>> Login(
|
|
[FromBody] LoginRequest request,
|
|
CancellationToken ct)
|
|
{
|
|
var result = await profileService.LoginAsync(
|
|
new LoginProfileCommand(
|
|
request.DeviceId,
|
|
request.PlatformType,
|
|
request.PlatformId,
|
|
request.PlatformAuthentication),
|
|
ct);
|
|
|
|
if (!result.Succeeded)
|
|
return BadRequest(result.Message);
|
|
|
|
return new LoginResponse
|
|
{
|
|
Profile = result.Profile!,
|
|
AccessToken = result.AccessToken!,
|
|
ExpiresIn = result.ExpiresIn
|
|
};
|
|
}
|
|
} |