| | | 1 | | using Chronicis.Api.Infrastructure; |
| | | 2 | | using Chronicis.Api.Services; |
| | | 3 | | using Chronicis.Shared.DTOs; |
| | | 4 | | using Microsoft.AspNetCore.Authorization; |
| | | 5 | | using Microsoft.AspNetCore.Mvc; |
| | | 6 | | |
| | | 7 | | namespace Chronicis.Api.Controllers; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// API endpoints for User profile management. |
| | | 11 | | /// </summary> |
| | | 12 | | [ApiController] |
| | | 13 | | [Route("users")] |
| | | 14 | | [Authorize] |
| | | 15 | | public class UsersController : ControllerBase |
| | | 16 | | { |
| | | 17 | | private readonly IUserService _userService; |
| | | 18 | | private readonly ICurrentUserService _currentUserService; |
| | | 19 | | private readonly ILogger<UsersController> _logger; |
| | | 20 | | |
| | 0 | 21 | | public UsersController( |
| | 0 | 22 | | IUserService userService, |
| | 0 | 23 | | ICurrentUserService currentUserService, |
| | 0 | 24 | | ILogger<UsersController> logger) |
| | | 25 | | { |
| | 0 | 26 | | _userService = userService; |
| | 0 | 27 | | _currentUserService = currentUserService; |
| | 0 | 28 | | _logger = logger; |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// GET /api/users/me - Get the current user's profile. |
| | | 33 | | /// </summary> |
| | | 34 | | [HttpGet("me")] |
| | | 35 | | public async Task<ActionResult<UserProfileDto>> GetCurrentUserProfile() |
| | | 36 | | { |
| | 0 | 37 | | var user = await _currentUserService.GetRequiredUserAsync(); |
| | 0 | 38 | | _logger.LogDebug("Getting profile for user {UserId}", user.Id); |
| | | 39 | | |
| | 0 | 40 | | var profile = await _userService.GetUserProfileAsync(user.Id); |
| | | 41 | | |
| | 0 | 42 | | if (profile == null) |
| | | 43 | | { |
| | 0 | 44 | | return NotFound(new { error = "User profile not found" }); |
| | | 45 | | } |
| | | 46 | | |
| | 0 | 47 | | return Ok(profile); |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// POST /api/users/me/complete-onboarding - Mark onboarding as complete. |
| | | 52 | | /// </summary> |
| | | 53 | | [HttpPost("me/complete-onboarding")] |
| | | 54 | | public async Task<IActionResult> CompleteOnboarding() |
| | | 55 | | { |
| | 0 | 56 | | var user = await _currentUserService.GetRequiredUserAsync(); |
| | 0 | 57 | | _logger.LogDebug("Completing onboarding for user {UserId}", user.Id); |
| | | 58 | | |
| | 0 | 59 | | var success = await _userService.CompleteOnboardingAsync(user.Id); |
| | | 60 | | |
| | 0 | 61 | | if (!success) |
| | | 62 | | { |
| | 0 | 63 | | return BadRequest(new { error = "Failed to complete onboarding" }); |
| | | 64 | | } |
| | | 65 | | |
| | 0 | 66 | | return NoContent(); |
| | 0 | 67 | | } |
| | | 68 | | } |