Refactored response and request models to dto naming. Adjusted mapper naming
This commit is contained in:
@@ -17,13 +17,13 @@ public class DiagnoseController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<DiagnoseResultResponse[]>> GetAsync()
|
public async Task<ActionResult<DiagnoseResultDto[]>> GetAsync()
|
||||||
{
|
{
|
||||||
var results = await DiagnoseService.DiagnoseAsync();
|
var results = await DiagnoseService.DiagnoseAsync();
|
||||||
|
|
||||||
return results
|
return results
|
||||||
.OrderBy(x => x.Level)
|
.OrderBy(x => x.Level)
|
||||||
.MapToResult()
|
.ToDto()
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ public class RolesController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<PagedData<RoleResponse>>> GetAsync(
|
public async Task<ActionResult<PagedData<RoleDto>>> GetAsync(
|
||||||
[FromQuery] int startIndex,
|
[FromQuery] int startIndex,
|
||||||
[FromQuery] int length,
|
[FromQuery] int length,
|
||||||
[FromQuery] FilterOptions? filterOptions
|
[FromQuery] FilterOptions? filterOptions
|
||||||
@@ -57,18 +57,18 @@ public class RolesController : Controller
|
|||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
var data = await query
|
var data = await query
|
||||||
.ProjectToResponse()
|
.ProjectToDto()
|
||||||
.Skip(startIndex)
|
.Skip(startIndex)
|
||||||
.Take(length)
|
.Take(length)
|
||||||
.ToArrayAsync();
|
.ToArrayAsync();
|
||||||
|
|
||||||
var total = await query.CountAsync();
|
var total = await query.CountAsync();
|
||||||
|
|
||||||
return new PagedData<RoleResponse>(data, total);
|
return new PagedData<RoleDto>(data, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id:int}")]
|
[HttpGet("{id:int}")]
|
||||||
public async Task<ActionResult<RoleResponse>> GetAsync([FromRoute] int id)
|
public async Task<ActionResult<RoleDto>> GetAsync([FromRoute] int id)
|
||||||
{
|
{
|
||||||
var role = await RoleRepository
|
var role = await RoleRepository
|
||||||
.Query()
|
.Query()
|
||||||
@@ -77,21 +77,21 @@ public class RolesController : Controller
|
|||||||
if (role == null)
|
if (role == null)
|
||||||
return Problem("No role with this id found", statusCode: 404);
|
return Problem("No role with this id found", statusCode: 404);
|
||||||
|
|
||||||
return RoleMapper.MapToResponse(role);
|
return RoleMapper.ToDto(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult<RoleResponse>> CreateAsync([FromBody] CreateRoleRequest request)
|
public async Task<ActionResult<RoleDto>> CreateAsync([FromBody] CreateRoleDto request)
|
||||||
{
|
{
|
||||||
var role = RoleMapper.MapToRole(request);
|
var role = RoleMapper.ToEntity(request);
|
||||||
|
|
||||||
var finalRole = await RoleRepository.AddAsync(role);
|
var finalRole = await RoleRepository.AddAsync(role);
|
||||||
|
|
||||||
return RoleMapper.MapToResponse(finalRole);
|
return RoleMapper.ToDto(finalRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("{id:int}")]
|
[HttpPatch("{id:int}")]
|
||||||
public async Task<ActionResult<RoleResponse>> UpdateAsync([FromRoute] int id, [FromBody] UpdateRoleRequest request)
|
public async Task<ActionResult<RoleDto>> UpdateAsync([FromRoute] int id, [FromBody] UpdateRoleDto request)
|
||||||
{
|
{
|
||||||
var role = await RoleRepository
|
var role = await RoleRepository
|
||||||
.Query()
|
.Query()
|
||||||
@@ -104,7 +104,7 @@ public class RolesController : Controller
|
|||||||
|
|
||||||
await RoleRepository.UpdateAsync(role);
|
await RoleRepository.UpdateAsync(role);
|
||||||
|
|
||||||
return RoleMapper.MapToResponse(role);
|
return RoleMapper.ToDto(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("{id:int}")]
|
[HttpDelete("{id:int}")]
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ public class SystemController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("info")]
|
[HttpGet("info")]
|
||||||
public async Task<ActionResult<SystemInfoResponse>> GetInfoAsync()
|
public async Task<ActionResult<SystemInfoDto>> GetInfoAsync()
|
||||||
{
|
{
|
||||||
var cpuUsage = await ApplicationService.GetCpuUsageAsync();
|
var cpuUsage = await ApplicationService.GetCpuUsageAsync();
|
||||||
var memoryUsage = await ApplicationService.GetMemoryUsageAsync();
|
var memoryUsage = await ApplicationService.GetMemoryUsageAsync();
|
||||||
|
|
||||||
return new SystemInfoResponse(
|
return new SystemInfoDto(
|
||||||
cpuUsage,
|
cpuUsage,
|
||||||
memoryUsage,
|
memoryUsage,
|
||||||
ApplicationService.OperatingSystem,
|
ApplicationService.OperatingSystem,
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ public class AuthController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<SchemeResponse[]>> GetSchemesAsync()
|
public async Task<ActionResult<SchemeDto[]>> GetSchemesAsync()
|
||||||
{
|
{
|
||||||
var schemes = await SchemeProvider.GetAllSchemesAsync();
|
var schemes = await SchemeProvider.GetAllSchemesAsync();
|
||||||
|
|
||||||
return schemes
|
return schemes
|
||||||
.Where(scheme => !string.IsNullOrWhiteSpace(scheme.DisplayName))
|
.Where(scheme => !string.IsNullOrWhiteSpace(scheme.DisplayName))
|
||||||
.Select(scheme => new SchemeResponse(scheme.Name, scheme.DisplayName!))
|
.Select(scheme => new SchemeDto(scheme.Name, scheme.DisplayName!))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,13 +43,13 @@ public class AuthController : Controller
|
|||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpGet("claims")]
|
[HttpGet("claims")]
|
||||||
public Task<ActionResult<ClaimResponse[]>> GetClaimsAsync()
|
public Task<ActionResult<ClaimDto[]>> GetClaimsAsync()
|
||||||
{
|
{
|
||||||
var result = User.Claims
|
var result = User.Claims
|
||||||
.Select(claim => new ClaimResponse(claim.Type, claim.Value))
|
.Select(claim => new ClaimDto(claim.Type, claim.Value))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
return Task.FromResult<ActionResult<ClaimResponse[]>>(result);
|
return Task.FromResult<ActionResult<ClaimDto[]>>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("logout")]
|
[HttpGet("logout")]
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class UsersController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<PagedData<UserResponse>>> GetAsync(
|
public async Task<ActionResult<PagedData<UserDto>>> GetAsync(
|
||||||
[FromQuery] int startIndex,
|
[FromQuery] int startIndex,
|
||||||
[FromQuery] int length,
|
[FromQuery] int length,
|
||||||
[FromQuery] FilterOptions? filterOptions
|
[FromQuery] FilterOptions? filterOptions
|
||||||
@@ -62,18 +62,18 @@ public class UsersController : Controller
|
|||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
var data = await query
|
var data = await query
|
||||||
.ProjectToResponse()
|
.ProjectToDto()
|
||||||
.Skip(startIndex)
|
.Skip(startIndex)
|
||||||
.Take(length)
|
.Take(length)
|
||||||
.ToArrayAsync();
|
.ToArrayAsync();
|
||||||
|
|
||||||
var total = await query.CountAsync();
|
var total = await query.CountAsync();
|
||||||
|
|
||||||
return new PagedData<UserResponse>(data, total);
|
return new PagedData<UserDto>(data, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id:int}")]
|
[HttpGet("{id:int}")]
|
||||||
public async Task<ActionResult<UserResponse>> GetAsync([FromRoute] int id)
|
public async Task<ActionResult<UserDto>> GetAsync([FromRoute] int id)
|
||||||
{
|
{
|
||||||
var user = await UserRepository
|
var user = await UserRepository
|
||||||
.Query()
|
.Query()
|
||||||
@@ -82,22 +82,22 @@ public class UsersController : Controller
|
|||||||
if (user == null)
|
if (user == null)
|
||||||
return Problem("No user with this id found", statusCode: 404);
|
return Problem("No user with this id found", statusCode: 404);
|
||||||
|
|
||||||
return UserMapper.MapToResponse(user);
|
return UserMapper.ToDto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult<UserResponse>> CreateAsync([FromBody] CreateUserRequest request)
|
public async Task<ActionResult<UserDto>> CreateAsync([FromBody] CreateUserDto request)
|
||||||
{
|
{
|
||||||
var user = UserMapper.MapToUser(request);
|
var user = UserMapper.ToEntity(request);
|
||||||
user.InvalidateTimestamp = DateTimeOffset.UtcNow.AddMinutes(-1);
|
user.InvalidateTimestamp = DateTimeOffset.UtcNow.AddMinutes(-1);
|
||||||
|
|
||||||
var finalUser = await UserRepository.AddAsync(user);
|
var finalUser = await UserRepository.AddAsync(user);
|
||||||
|
|
||||||
return UserMapper.MapToResponse(finalUser);
|
return UserMapper.ToDto(finalUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("{id:int}")]
|
[HttpPatch("{id:int}")]
|
||||||
public async Task<ActionResult<UserResponse>> UpdateAsync([FromRoute] int id, [FromBody] UpdateUserRequest request)
|
public async Task<ActionResult<UserDto>> UpdateAsync([FromRoute] int id, [FromBody] UpdateUserDto request)
|
||||||
{
|
{
|
||||||
var user = await UserRepository
|
var user = await UserRepository
|
||||||
.Query()
|
.Query()
|
||||||
@@ -109,7 +109,7 @@ public class UsersController : Controller
|
|||||||
UserMapper.Merge(user, request);
|
UserMapper.Merge(user, request);
|
||||||
await UserRepository.UpdateAsync(user);
|
await UserRepository.UpdateAsync(user);
|
||||||
|
|
||||||
return UserMapper.MapToResponse(user);
|
return UserMapper.ToDto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("{id:int}")]
|
[HttpDelete("{id:int}")]
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ namespace Moonlight.Api.Mappers;
|
|||||||
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
public static partial class DiagnoseResultMapper
|
public static partial class DiagnoseResultMapper
|
||||||
{
|
{
|
||||||
public static partial IEnumerable<DiagnoseResultResponse> MapToResult(this IEnumerable<DiagnoseResult> results);
|
public static partial IEnumerable<DiagnoseResultDto> ToDto(this IEnumerable<DiagnoseResult> results);
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,10 @@ namespace Moonlight.Api.Mappers;
|
|||||||
[SuppressMessage("Mapper", "RMG012:Source member was not found for target member")]
|
[SuppressMessage("Mapper", "RMG012:Source member was not found for target member")]
|
||||||
public static partial class RoleMapper
|
public static partial class RoleMapper
|
||||||
{
|
{
|
||||||
[MapProperty([nameof(Role.Members), nameof(Role.Members.Count)], nameof(RoleResponse.MemberCount))]
|
[MapProperty([nameof(Role.Members), nameof(Role.Members.Count)], nameof(RoleDto.MemberCount))]
|
||||||
public static partial RoleResponse MapToResponse(Role role);
|
public static partial RoleDto ToDto(Role role);
|
||||||
public static partial Role MapToRole(CreateRoleRequest request);
|
public static partial Role ToEntity(CreateRoleDto request);
|
||||||
public static partial void Merge([MappingTarget] Role role, UpdateRoleRequest request);
|
public static partial void Merge([MappingTarget] Role role, UpdateRoleDto request);
|
||||||
|
|
||||||
public static partial IQueryable<RoleResponse> ProjectToResponse(this IQueryable<Role> roles);
|
public static partial IQueryable<RoleDto> ProjectToDto(this IQueryable<Role> roles);
|
||||||
}
|
}
|
||||||
@@ -11,11 +11,11 @@ namespace Moonlight.Api.Mappers;
|
|||||||
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
public static partial class UserMapper
|
public static partial class UserMapper
|
||||||
{
|
{
|
||||||
public static partial IQueryable<UserResponse> ProjectToResponse(this IQueryable<User> users);
|
public static partial IQueryable<UserDto> ProjectToDto(this IQueryable<User> users);
|
||||||
|
|
||||||
public static partial UserResponse MapToResponse(User user);
|
public static partial UserDto ToDto(User user);
|
||||||
|
|
||||||
public static partial void Merge([MappingTarget] User user, UpdateUserRequest request);
|
public static partial void Merge([MappingTarget] User user, UpdateUserDto request);
|
||||||
|
|
||||||
public static partial User MapToUser(CreateUserRequest request);
|
public static partial User ToEntity(CreateUserDto request);
|
||||||
}
|
}
|
||||||
@@ -10,5 +10,5 @@ namespace Moonlight.Frontend.Mappers;
|
|||||||
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
public static partial class RoleMapper
|
public static partial class RoleMapper
|
||||||
{
|
{
|
||||||
public static partial UpdateRoleRequest MapToUpdate(RoleResponse role);
|
public static partial UpdateRoleDto ToUpdate(RoleDto role);
|
||||||
}
|
}
|
||||||
@@ -10,5 +10,5 @@ namespace Moonlight.Frontend.Mappers;
|
|||||||
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
public static partial class UserMapper
|
public static partial class UserMapper
|
||||||
{
|
{
|
||||||
public static partial UpdateUserRequest MapToUpdate(UserResponse response);
|
public static partial UpdateUserDto ToUpdate(UserDto dto);
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ public class RemoteAuthProvider : AuthenticationStateProvider
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var claimResponses = await HttpClient.GetFromJsonAsync<ClaimResponse[]>(
|
var claimResponses = await HttpClient.GetFromJsonAsync<ClaimDto[]>(
|
||||||
"api/auth/claims", Constants.SerializerOptions
|
"api/auth/claims", Constants.SerializerOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,9 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
[Parameter] public Func<CreateRoleRequest, Task> OnSubmit { get; set; }
|
[Parameter] public Func<CreateRoleDto, Task> OnSubmit { get; set; }
|
||||||
|
|
||||||
private CreateRoleRequest Request;
|
private CreateRoleDto Request;
|
||||||
private List<string> Permissions;
|
private List<string> Permissions;
|
||||||
private FormHandler FormHandler;
|
private FormHandler FormHandler;
|
||||||
|
|
||||||
|
|||||||
@@ -58,16 +58,16 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
[Parameter] public Func<UpdateRoleRequest, Task> OnSubmit { get; set; }
|
[Parameter] public Func<UpdateRoleDto, Task> OnSubmit { get; set; }
|
||||||
[Parameter] public RoleResponse Role { get; set; }
|
[Parameter] public RoleDto Role { get; set; }
|
||||||
|
|
||||||
private UpdateRoleRequest Request;
|
private UpdateRoleDto Request;
|
||||||
private List<string> Permissions;
|
private List<string> Permissions;
|
||||||
private FormHandler FormHandler;
|
private FormHandler FormHandler;
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
Request = RoleMapper.MapToUpdate(Role);
|
Request = RoleMapper.ToUpdate(Role);
|
||||||
Permissions = Role.Permissions.ToList();
|
Permissions = Role.Permissions.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,14 +144,14 @@
|
|||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private bool IsInfoLoading = true;
|
private bool IsInfoLoading = true;
|
||||||
private SystemInfoResponse? InfoResponse;
|
private SystemInfoDto? InfoResponse;
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if(!firstRender)
|
if(!firstRender)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
InfoResponse = await HttpClient.GetFromJsonAsync<SystemInfoResponse>("api/admin/system/info", Constants.SerializerOptions);
|
InfoResponse = await HttpClient.GetFromJsonAsync<SystemInfoDto>("api/admin/system/info", Constants.SerializerOptions);
|
||||||
IsInfoLoading = false;
|
IsInfoLoading = false;
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|||||||
@@ -218,7 +218,7 @@
|
|||||||
{
|
{
|
||||||
private bool IsLoading = false;
|
private bool IsLoading = false;
|
||||||
private bool HasDiagnosed = false;
|
private bool HasDiagnosed = false;
|
||||||
private DiagnoseResultResponse[] Entries;
|
private DiagnoseResultDto[] Entries;
|
||||||
|
|
||||||
private async Task DiagnoseAsync()
|
private async Task DiagnoseAsync()
|
||||||
{
|
{
|
||||||
@@ -226,7 +226,7 @@
|
|||||||
HasDiagnosed = false;
|
HasDiagnosed = false;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
var results = await HttpClient.GetFromJsonAsync<DiagnoseResultResponse[]>("api/admin/system/diagnose");
|
var results = await HttpClient.GetFromJsonAsync<DiagnoseResultDto[]>("api/admin/system/diagnose");
|
||||||
Entries = results ?? [];
|
Entries = results ?? [];
|
||||||
|
|
||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
|
|||||||
@@ -27,9 +27,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<DataGrid @ref="Grid" TGridItem="RoleResponse" Loader="LoadAsync" PageSize="10" ClassName="bg-card">
|
<DataGrid @ref="Grid" TGridItem="RoleDto" Loader="LoadAsync" PageSize="10" ClassName="bg-card">
|
||||||
<PropertyColumn Field="u => u.Id"/>
|
<PropertyColumn Field="u => u.Id"/>
|
||||||
<PropertyColumn IsFilterable="true" Identifier="@nameof(RoleResponse.Name)" Field="r => r.Name"/>
|
<PropertyColumn IsFilterable="true" Identifier="@nameof(RoleDto.Name)" Field="r => r.Name"/>
|
||||||
<PropertyColumn Title="Description" Field="r => r.Description"/>
|
<PropertyColumn Title="Description" Field="r => r.Description"/>
|
||||||
<PropertyColumn Title="Members" Field="r => r.MemberCount"/>
|
<PropertyColumn Title="Members" Field="r => r.MemberCount"/>
|
||||||
<TemplateColumn>
|
<TemplateColumn>
|
||||||
@@ -68,26 +68,26 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private DataGrid<RoleResponse> Grid;
|
private DataGrid<RoleDto> Grid;
|
||||||
|
|
||||||
private async Task<DataGridResponse<RoleResponse>> LoadAsync(DataGridRequest<RoleResponse> request)
|
private async Task<DataGridResponse<RoleDto>> LoadAsync(DataGridRequest<RoleDto> request)
|
||||||
{
|
{
|
||||||
var query = $"?startIndex={request.StartIndex}&length={request.Length}";
|
var query = $"?startIndex={request.StartIndex}&length={request.Length}";
|
||||||
var filterOptions = request.Filters.Count > 0 ? new FilterOptions(request.Filters) : null;
|
var filterOptions = request.Filters.Count > 0 ? new FilterOptions(request.Filters) : null;
|
||||||
|
|
||||||
var response = await HttpClient.GetFromJsonAsync<PagedData<RoleResponse>>(
|
var response = await HttpClient.GetFromJsonAsync<PagedData<RoleDto>>(
|
||||||
$"api/admin/roles{query}&filterOptions={filterOptions}",
|
$"api/admin/roles{query}&filterOptions={filterOptions}",
|
||||||
Constants.SerializerOptions
|
Constants.SerializerOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
return new DataGridResponse<RoleResponse>(response!.Data, response.TotalLength);
|
return new DataGridResponse<RoleDto>(response!.Data, response.TotalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreateAsync()
|
private async Task CreateAsync()
|
||||||
{
|
{
|
||||||
await DialogService.LaunchAsync<CreateRoleDialog>(parameters =>
|
await DialogService.LaunchAsync<CreateRoleDialog>(parameters =>
|
||||||
{
|
{
|
||||||
parameters[nameof(CreateRoleDialog.OnSubmit)] = async Task (CreateRoleRequest request) =>
|
parameters[nameof(CreateRoleDialog.OnSubmit)] = async Task (CreateRoleDto request) =>
|
||||||
{
|
{
|
||||||
await HttpClient.PostAsJsonAsync(
|
await HttpClient.PostAsJsonAsync(
|
||||||
"api/admin/roles",
|
"api/admin/roles",
|
||||||
@@ -101,12 +101,12 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task EditAsync(RoleResponse role)
|
private async Task EditAsync(RoleDto role)
|
||||||
{
|
{
|
||||||
await DialogService.LaunchAsync<UpdateRoleDialog>(parameters =>
|
await DialogService.LaunchAsync<UpdateRoleDialog>(parameters =>
|
||||||
{
|
{
|
||||||
parameters[nameof(UpdateRoleDialog.Role)] = role;
|
parameters[nameof(UpdateRoleDialog.Role)] = role;
|
||||||
parameters[nameof(UpdateRoleDialog.OnSubmit)] = async Task (UpdateRoleRequest request) =>
|
parameters[nameof(UpdateRoleDialog.OnSubmit)] = async Task (UpdateRoleDto request) =>
|
||||||
{
|
{
|
||||||
await HttpClient.PatchAsJsonAsync(
|
await HttpClient.PatchAsJsonAsync(
|
||||||
$"api/admin/roles/{role.Id}",
|
$"api/admin/roles/{role.Id}",
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DeleteAsync(RoleResponse role)
|
private async Task DeleteAsync(RoleDto role)
|
||||||
{
|
{
|
||||||
await AlertDialogService.ConfirmDangerAsync(
|
await AlertDialogService.ConfirmDangerAsync(
|
||||||
$"Deletion of role {role.Name}",
|
$"Deletion of role {role.Name}",
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private CreateUserRequest Request = new();
|
private CreateUserDto Request = new();
|
||||||
|
|
||||||
private FormHandler Form;
|
private FormHandler Form;
|
||||||
|
|
||||||
|
|||||||
@@ -77,15 +77,15 @@
|
|||||||
[Parameter] public int Id { get; set; }
|
[Parameter] public int Id { get; set; }
|
||||||
|
|
||||||
private FormHandler Form;
|
private FormHandler Form;
|
||||||
private UpdateUserRequest Request;
|
private UpdateUserDto Request;
|
||||||
private UserResponse User;
|
private UserDto User;
|
||||||
|
|
||||||
private async Task LoadAsync(LazyLoader _)
|
private async Task LoadAsync(LazyLoader _)
|
||||||
{
|
{
|
||||||
var user = await HttpClient.GetFromJsonAsync<UserResponse>($"api/users/{Id}", Constants.SerializerOptions);
|
var user = await HttpClient.GetFromJsonAsync<UserDto>($"api/users/{Id}", Constants.SerializerOptions);
|
||||||
User = user!;
|
User = user!;
|
||||||
|
|
||||||
Request = UserMapper.MapToUpdate(User);
|
Request = UserMapper.ToUpdate(User);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnSubmitAsync()
|
private async Task OnSubmitAsync()
|
||||||
|
|||||||
@@ -36,12 +36,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-8">
|
<div class="mt-8">
|
||||||
<DataGrid @ref="Grid" TGridItem="UserResponse" Loader="LoadAsync" PageSize="10" ClassName="bg-card">
|
<DataGrid @ref="Grid" TGridItem="UserDto" Loader="LoadAsync" PageSize="10" ClassName="bg-card">
|
||||||
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" Field="u => u.Id"/>
|
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" Field="u => u.Id"/>
|
||||||
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" IsFilterable="true"
|
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" IsFilterable="true"
|
||||||
Identifier="@nameof(UserResponse.Username)" Field="u => u.Username"/>
|
Identifier="@nameof(UserDto.Username)" Field="u => u.Username"/>
|
||||||
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" IsFilterable="true"
|
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" IsFilterable="true"
|
||||||
Identifier="@nameof(UserResponse.Email)" Field="u => u.Email"/>
|
Identifier="@nameof(UserDto.Email)" Field="u => u.Email"/>
|
||||||
<TemplateColumn>
|
<TemplateColumn>
|
||||||
<CellTemplate>
|
<CellTemplate>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
@@ -78,24 +78,24 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private DataGrid<UserResponse> Grid;
|
private DataGrid<UserDto> Grid;
|
||||||
|
|
||||||
private async Task<DataGridResponse<UserResponse>> LoadAsync(DataGridRequest<UserResponse> request)
|
private async Task<DataGridResponse<UserDto>> LoadAsync(DataGridRequest<UserDto> request)
|
||||||
{
|
{
|
||||||
var query = $"?startIndex={request.StartIndex}&length={request.Length}";
|
var query = $"?startIndex={request.StartIndex}&length={request.Length}";
|
||||||
var filterOptions = request.Filters.Count > 0 ? new FilterOptions(request.Filters) : null;
|
var filterOptions = request.Filters.Count > 0 ? new FilterOptions(request.Filters) : null;
|
||||||
|
|
||||||
var response = await HttpClient.GetFromJsonAsync<PagedData<UserResponse>>(
|
var response = await HttpClient.GetFromJsonAsync<PagedData<UserDto>>(
|
||||||
$"api/users{query}&filterOptions={filterOptions}",
|
$"api/users{query}&filterOptions={filterOptions}",
|
||||||
Constants.SerializerOptions
|
Constants.SerializerOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
return new DataGridResponse<UserResponse>(response!.Data, response.TotalLength);
|
return new DataGridResponse<UserDto>(response!.Data, response.TotalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Edit(UserResponse response) => Navigation.NavigateTo($"/users/{response.Id}");
|
private void Edit(UserDto dto) => Navigation.NavigateTo($"/users/{dto.Id}");
|
||||||
|
|
||||||
private async Task DeleteAsync(UserResponse user)
|
private async Task DeleteAsync(UserDto user)
|
||||||
{
|
{
|
||||||
await AlertDialogService.ConfirmDangerAsync(
|
await AlertDialogService.ConfirmDangerAsync(
|
||||||
$"Deletion of user {user.Username}",
|
$"Deletion of user {user.Username}",
|
||||||
|
|||||||
@@ -40,14 +40,14 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private SchemeResponse[]? Schemes;
|
private SchemeDto[]? Schemes;
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (!firstRender)
|
if (!firstRender)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var schemes = await HttpClient.GetFromJsonAsync<SchemeResponse[]>(
|
var schemes = await HttpClient.GetFromJsonAsync<SchemeDto[]>(
|
||||||
"api/auth", Constants.SerializerOptions
|
"api/auth", Constants.SerializerOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace Moonlight.Shared.Http.Requests.Roles;
|
namespace Moonlight.Shared.Http.Requests.Roles;
|
||||||
|
|
||||||
public class CreateRoleRequest
|
public class CreateRoleDto
|
||||||
{
|
{
|
||||||
[Required] [MaxLength(15)] public string Name { get; set; }
|
[Required] [MaxLength(15)] public string Name { get; set; }
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace Moonlight.Shared.Http.Requests.Roles;
|
namespace Moonlight.Shared.Http.Requests.Roles;
|
||||||
|
|
||||||
public class UpdateRoleRequest
|
public class UpdateRoleDto
|
||||||
{
|
{
|
||||||
[Required] [MaxLength(15)] public string Name { get; set; }
|
[Required] [MaxLength(15)] public string Name { get; set; }
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Moonlight.Shared.Http.Requests.Users;
|
namespace Moonlight.Shared.Http.Requests.Users;
|
||||||
|
|
||||||
public class CreateUserRequest
|
public class CreateUserDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[MinLength(3)]
|
[MinLength(3)]
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Moonlight.Shared.Http.Requests.Users;
|
namespace Moonlight.Shared.Http.Requests.Users;
|
||||||
|
|
||||||
public class UpdateUserRequest
|
public class UpdateUserDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[MinLength(3)]
|
[MinLength(3)]
|
||||||
10
Moonlight.Shared/Http/Responses/Admin/DiagnoseResultDto.cs
Normal file
10
Moonlight.Shared/Http/Responses/Admin/DiagnoseResultDto.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Admin;
|
||||||
|
|
||||||
|
public record DiagnoseResultDto(DiagnoseLevel Level, string Title, string[] Tags, string? Message, string? StackStrace, string? SolutionUrl, string? ReportUrl);
|
||||||
|
|
||||||
|
public enum DiagnoseLevel
|
||||||
|
{
|
||||||
|
Error = 0,
|
||||||
|
Warning = 1,
|
||||||
|
Healthy = 2
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace Moonlight.Shared.Http.Responses.Admin;
|
|
||||||
|
|
||||||
public record DiagnoseResultResponse(DiagnoseLevel Level, string Title, string[] Tags, string? Message, string? StackStrace, string? SolutionUrl, string? ReportUrl);
|
|
||||||
|
|
||||||
public enum DiagnoseLevel
|
|
||||||
{
|
|
||||||
Error = 0,
|
|
||||||
Warning = 1,
|
|
||||||
Healthy = 2
|
|
||||||
}
|
|
||||||
3
Moonlight.Shared/Http/Responses/Admin/RoleDto.cs
Normal file
3
Moonlight.Shared/Http/Responses/Admin/RoleDto.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Admin;
|
||||||
|
|
||||||
|
public record RoleDto(int Id, string Name, string Description, string[] Permissions, int MemberCount, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt);
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Moonlight.Shared.Http.Responses.Admin;
|
|
||||||
|
|
||||||
public record RoleResponse(int Id, string Name, string Description, string[] Permissions, int MemberCount, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt);
|
|
||||||
3
Moonlight.Shared/Http/Responses/Admin/SystemInfoDto.cs
Normal file
3
Moonlight.Shared/Http/Responses/Admin/SystemInfoDto.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Admin;
|
||||||
|
|
||||||
|
public record SystemInfoDto(double CpuUsage, long MemoryUsage, string OperatingSystem, TimeSpan Uptime, string VersionName, bool IsUpToDate);
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Moonlight.Shared.Http.Responses.Admin;
|
|
||||||
|
|
||||||
public record SystemInfoResponse(double CpuUsage, long MemoryUsage, string OperatingSystem, TimeSpan Uptime, string VersionName, bool IsUpToDate);
|
|
||||||
3
Moonlight.Shared/Http/Responses/Auth/ClaimDto.cs
Normal file
3
Moonlight.Shared/Http/Responses/Auth/ClaimDto.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Auth;
|
||||||
|
|
||||||
|
public record ClaimDto(string Type, string Value);
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Moonlight.Shared.Http.Responses.Auth;
|
|
||||||
|
|
||||||
public record ClaimResponse(string Type, string Value);
|
|
||||||
3
Moonlight.Shared/Http/Responses/Auth/SchemeDto.cs
Normal file
3
Moonlight.Shared/Http/Responses/Auth/SchemeDto.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Auth;
|
||||||
|
|
||||||
|
public record SchemeDto(string Name, string DisplayName);
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Moonlight.Shared.Http.Responses.Auth;
|
|
||||||
|
|
||||||
public record SchemeResponse(string Name, string DisplayName);
|
|
||||||
3
Moonlight.Shared/Http/Responses/Users/UserDto.cs
Normal file
3
Moonlight.Shared/Http/Responses/Users/UserDto.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Users;
|
||||||
|
|
||||||
|
public record UserDto(int Id, string Username, string Email, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt);
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Moonlight.Shared.Http.Responses.Users;
|
|
||||||
|
|
||||||
public record UserResponse(int Id, string Username, string Email, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt);
|
|
||||||
@@ -8,18 +8,18 @@ using Moonlight.Shared.Http.Responses.Users;
|
|||||||
|
|
||||||
namespace Moonlight.Shared.Http;
|
namespace Moonlight.Shared.Http;
|
||||||
|
|
||||||
[JsonSerializable(typeof(CreateUserRequest))]
|
[JsonSerializable(typeof(CreateUserDto))]
|
||||||
[JsonSerializable(typeof(UpdateUserRequest))]
|
[JsonSerializable(typeof(UpdateUserDto))]
|
||||||
[JsonSerializable(typeof(ClaimResponse[]))]
|
[JsonSerializable(typeof(ClaimDto[]))]
|
||||||
[JsonSerializable(typeof(SchemeResponse[]))]
|
[JsonSerializable(typeof(SchemeDto[]))]
|
||||||
[JsonSerializable(typeof(DiagnoseResultResponse[]))]
|
[JsonSerializable(typeof(DiagnoseResultDto[]))]
|
||||||
[JsonSerializable(typeof(UserResponse))]
|
[JsonSerializable(typeof(UserDto))]
|
||||||
[JsonSerializable(typeof(SystemInfoResponse))]
|
[JsonSerializable(typeof(SystemInfoDto))]
|
||||||
[JsonSerializable(typeof(PagedData<UserResponse>))]
|
[JsonSerializable(typeof(PagedData<UserDto>))]
|
||||||
[JsonSerializable(typeof(PagedData<RoleResponse>))]
|
[JsonSerializable(typeof(PagedData<RoleDto>))]
|
||||||
[JsonSerializable(typeof(RoleResponse))]
|
[JsonSerializable(typeof(RoleDto))]
|
||||||
[JsonSerializable(typeof(CreateRoleRequest))]
|
[JsonSerializable(typeof(CreateRoleDto))]
|
||||||
[JsonSerializable(typeof(UpdateRoleRequest))]
|
[JsonSerializable(typeof(UpdateRoleDto))]
|
||||||
public partial class SerializationContext : JsonSerializerContext
|
public partial class SerializationContext : JsonSerializerContext
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user