Skip to content

Commit

Permalink
Rename UserViewDto into UserPreviewDto
Browse files Browse the repository at this point in the history
  • Loading branch information
romandykyi committed Dec 23, 2023
1 parent 63db8ad commit 2b3c93d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Core/Dtos/Users/UserPreviewDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace EUniversity.Core.Dtos.Users;

public record UserPreviewDto(string Id, string Email, string UserName, string FirstName, string LastName, string? MiddleName);
3 changes: 0 additions & 3 deletions Core/Dtos/Users/UserViewDto.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Core/Services/Users/IUsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface IUsersService
/// <returns>
/// Page with all users with the role.
/// </returns>
Task<Page<UserViewDto>> GetUsersInRoleAsync(string role, PaginationProperties? properties = null,
Task<Page<UserPreviewDto>> GetUsersInRoleAsync(string role, PaginationProperties? properties = null,
IFilter<ApplicationUser>? filter = null);

/// <summary>
Expand All @@ -32,7 +32,7 @@ Task<Page<UserViewDto>> GetUsersInRoleAsync(string role, PaginationProperties? p
/// <returns>
/// Page with all users.
/// </returns>
Task<Page<UserViewDto>> GetAllUsersAsync(PaginationProperties? properties = null, IFilter<ApplicationUser>? filter = null);
Task<Page<UserPreviewDto>> GetAllUsersAsync(PaginationProperties? properties = null, IFilter<ApplicationUser>? filter = null);

/// <summary>
/// Gets a page with groups of the student.
Expand Down
6 changes: 3 additions & 3 deletions EUniversity/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public UsersController(IAuthService authService, IUsersService usersService)
/// <response code="401">Unauthorized user call</response>
/// <response code="403">User lacks 'Administrator' role</response>
[HttpGet]
[ProducesResponseType(typeof(Page<UserViewDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Page<UserPreviewDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[Authorize(Policies.HasAdministratorPermission)]
Expand Down Expand Up @@ -80,7 +80,7 @@ public async Task<IActionResult> GetAllUsersAsync(
/// <response code="403">User lacks 'Administrator' or 'Teacher' role</response>
[HttpGet]
[Route("students")]
[ProducesResponseType(typeof(Page<UserViewDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Page<UserPreviewDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[Authorize(Policies.IsTeacherOrAdministrator)]
Expand Down Expand Up @@ -111,7 +111,7 @@ public async Task<IActionResult> GetAllStudentsAsync(
/// <response code="401">Unauthorized user call</response>
[HttpGet]
[Route("teachers")]
[ProducesResponseType(typeof(Page<UserViewDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Page<UserPreviewDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetAllTeachersAsync(
Expand Down
8 changes: 4 additions & 4 deletions Infrastructure/Services/Users/UsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ public UsersService(ApplicationDbContext dbContext)
_dbContext = dbContext;
}

private static async Task<Page<UserViewDto>> SelectUsersAsync(
private static async Task<Page<UserPreviewDto>> SelectUsersAsync(
IQueryable<ApplicationUser> query,
PaginationProperties? properties,
IFilter<ApplicationUser>? filter)
{
query = filter?.Apply(query) ?? query;
return await query
.AsNoTracking()
.ToPageAsync<ApplicationUser, UserViewDto>(properties);
.ToPageAsync<ApplicationUser, UserPreviewDto>(properties);
}

/// <inheritdoc />
public async Task<Page<UserViewDto>> GetAllUsersAsync(PaginationProperties? properties,
public async Task<Page<UserPreviewDto>> GetAllUsersAsync(PaginationProperties? properties,
IFilter<ApplicationUser>? filter = null)
{
return await SelectUsersAsync(_dbContext.Users, properties, filter);
}

/// <inheritdoc />
public async Task<Page<UserViewDto>> GetUsersInRoleAsync(string role, PaginationProperties? properties,
public async Task<Page<UserPreviewDto>> GetUsersInRoleAsync(string role, PaginationProperties? properties,
IFilter<ApplicationUser>? filter = null)
{
string? roleId = await _dbContext.Roles
Expand Down
12 changes: 6 additions & 6 deletions IntegrationTests/Controllers/UsersControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class UsersControllerTests : ControllersTest
RegisterUser2
});

public UserViewDto[] TestUsers =
public UserPreviewDto[] TestUsers =
{
new("1", "mail1@example.com", "user1", "First1", "Last1", null),
new("2", "mail2@example.com", "user2", "First2", "Last2", "Middle2")
Expand Down Expand Up @@ -58,7 +58,7 @@ public static readonly (string, string)[] RegisterMethodsWithRoles =
(RolesGetMethods[1], Roles.Teacher)
};

private Page<UserViewDto> GetTestPage(PaginationProperties paginationProperties)
private Page<UserPreviewDto> GetTestPage(PaginationProperties paginationProperties)
{
return new(TestUsers, paginationProperties, TestUsers.Length);
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task GetMethods_AdministratorRole_SucceedAndReturnValidType(string

// Assert
result.EnsureSuccessStatusCode();
var users = await result.Content.ReadFromJsonAsync<Page<UserViewDto>>();
var users = await result.Content.ReadFromJsonAsync<Page<UserPreviewDto>>();
Assert.That(users, Is.Not.Null);
}

Expand All @@ -103,7 +103,7 @@ public async Task GetMethods_PaginationQueryParams_SucceedAndApplyPagination(str

// Assert
result.EnsureSuccessStatusCode();
var usersPage = await result.Content.ReadFromJsonAsync<Page<UserViewDto>>();
var usersPage = await result.Content.ReadFromJsonAsync<Page<UserPreviewDto>>();
Assert.That(usersPage, Is.Not.Null);
Assert.Multiple(() =>
{
Expand All @@ -124,7 +124,7 @@ public async Task GetAllUsers_FilterQueryParams_SucceedsAndAppliesFilter()

// Assert
result.EnsureSuccessStatusCode();
var usersPage = await result.Content.ReadFromJsonAsync<Page<UserViewDto>>();
var usersPage = await result.Content.ReadFromJsonAsync<Page<UserPreviewDto>>();
Assert.That(usersPage, Is.Not.Null);
await WebApplicationFactory.UsersServiceMock
.Received()
Expand All @@ -144,7 +144,7 @@ public async Task GetUsersInRoleMethods_FilterQueryParams_SucceedAndApplyFilter(

// Assert
result.EnsureSuccessStatusCode();
var usersPage = await result.Content.ReadFromJsonAsync<Page<UserViewDto>>();
var usersPage = await result.Content.ReadFromJsonAsync<Page<UserPreviewDto>>();
Assert.That(usersPage, Is.Not.Null);
await WebApplicationFactory.UsersServiceMock
.Received()
Expand Down

0 comments on commit 2b3c93d

Please sign in to comment.