Edit Records
This commit is contained in:
@@ -18,9 +18,9 @@ public class AuthService
|
||||
private bool? _isAuthenticated;
|
||||
private UserInfo? _userInfo = null;
|
||||
private string? _apiToken;
|
||||
|
||||
|
||||
public event Action<bool>? AuthenticationStateChanged;
|
||||
|
||||
|
||||
public AuthService(HttpClient httpClient, IJSRuntime jsRuntime)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
@@ -51,17 +51,17 @@ public class AuthService
|
||||
Email = email,
|
||||
AvatarUrl = avatarUrl
|
||||
};
|
||||
|
||||
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "api_token", _apiToken);
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "user_info", JsonSerializer.Serialize(_userInfo));
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Authorization =
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Authorization =
|
||||
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiToken);
|
||||
|
||||
|
||||
_isAuthenticated = true;
|
||||
Console.WriteLine($"✅ Backend validation successful. UserId={result.Id}");
|
||||
AuthenticationStateChanged?.Invoke(true);
|
||||
|
||||
|
||||
return (true, null);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class AuthService
|
||||
// Restore header
|
||||
_httpClient.DefaultRequestHeaders.Authorization =
|
||||
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiToken);
|
||||
|
||||
|
||||
Console.WriteLine($"✅ Session restored: {_userInfo?.Email}");
|
||||
}
|
||||
else
|
||||
@@ -137,11 +137,11 @@ public class AuthService
|
||||
Console.WriteLine("=== AuthService.ClearAuthenticationAsync ===");
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", "api_token");
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", "user_info");
|
||||
|
||||
|
||||
_apiToken = null;
|
||||
_isAuthenticated = false;
|
||||
_userInfo = null;
|
||||
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
|
||||
Console.WriteLine("✅ Authentication cleared");
|
||||
|
||||
@@ -56,4 +56,38 @@ public class LayerService
|
||||
// For now we don't need it for read-only view
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
|
||||
public async Task<RecordDto?> CreateRecordAsync(Guid layerId, RecordDto record)
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync($"Layers/{layerId}/records", record);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = await response.Content.ReadAsStringAsync();
|
||||
Console.Error.WriteLine($"CreateRecordAsync failed: {response.StatusCode} - {error}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<RecordDto>();
|
||||
}
|
||||
|
||||
public async Task<RecordDto?> UpdateRecordAsync(Guid layerId, Guid recordId, RecordDto record)
|
||||
{
|
||||
var response = await _httpClient.PutAsJsonAsync($"Layers/{layerId}/records/{recordId}", record);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = await response.Content.ReadAsStringAsync();
|
||||
Console.Error.WriteLine($"UpdateRecordAsync failed: {response.StatusCode} - {error}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<RecordDto>();
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteRecordAsync(Guid layerId, Guid recordId)
|
||||
{
|
||||
var response = await _httpClient.DeleteAsync($"Layers/{layerId}/records/{recordId}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
6
DiunaBI.UI.Shared/Services/TokenProvider.cs
Normal file
6
DiunaBI.UI.Shared/Services/TokenProvider.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace DiunaBI.UI.Shared.Services;
|
||||
|
||||
public class TokenProvider
|
||||
{
|
||||
public string? Token { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user