| | | 1 | | using System.Net.Http.Json; |
| | | 2 | | using Chronicis.Shared.DTOs; |
| | | 3 | | |
| | | 4 | | namespace Chronicis.Client.Services; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Implementation of user profile API service. |
| | | 8 | | /// </summary> |
| | | 9 | | public class UserApiService : IUserApiService |
| | | 10 | | { |
| | | 11 | | private readonly HttpClient _http; |
| | | 12 | | private readonly ILogger<UserApiService> _logger; |
| | | 13 | | |
| | 0 | 14 | | public UserApiService(HttpClient http, ILogger<UserApiService> logger) |
| | | 15 | | { |
| | 0 | 16 | | _http = http; |
| | 0 | 17 | | _logger = logger; |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public async Task<UserProfileDto?> GetUserProfileAsync() |
| | | 21 | | { |
| | | 22 | | try |
| | | 23 | | { |
| | 0 | 24 | | return await _http.GetFromJsonAsync<UserProfileDto>("users/me"); |
| | | 25 | | } |
| | 0 | 26 | | catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound) |
| | | 27 | | { |
| | 0 | 28 | | _logger.LogWarning("User profile not found"); |
| | 0 | 29 | | return null; |
| | | 30 | | } |
| | 0 | 31 | | catch (Exception ex) |
| | | 32 | | { |
| | 0 | 33 | | _logger.LogError(ex, "Error fetching user profile"); |
| | 0 | 34 | | return null; |
| | | 35 | | } |
| | 0 | 36 | | } |
| | | 37 | | |
| | | 38 | | public async Task<bool> CompleteOnboardingAsync() |
| | | 39 | | { |
| | | 40 | | try |
| | | 41 | | { |
| | 0 | 42 | | var response = await _http.PostAsync("users/me/complete-onboarding", null); |
| | 0 | 43 | | return response.IsSuccessStatusCode; |
| | | 44 | | } |
| | 0 | 45 | | catch (Exception ex) |
| | | 46 | | { |
| | 0 | 47 | | _logger.LogError(ex, "Error completing onboarding"); |
| | 0 | 48 | | return false; |
| | | 49 | | } |
| | 0 | 50 | | } |
| | | 51 | | } |