From f274a6195be6299dc06f9f63f2be9b9bed1f2455 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 13:52:44 +0700 Subject: [PATCH 01/26] add: GetDepartmentById, UpdateDepartment, DeleteDepartment, EnableRoom endpoints --- src/Api/Controllers/DepartmentsController.cs | 63 ++++++++++++++++++- .../Requests/UpdateDepartmentRequest.cs | 6 ++ src/Api/Controllers/RoomsController.cs | 19 ++++++ .../UpdateDepartmentCommand.cs | 10 +++ .../GetDepartmentByIdQuery.cs | 9 +++ .../Commands/EnableRoom/EnableRoomCommand.cs | 9 +++ 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/Api/Controllers/Payload/Requests/UpdateDepartmentRequest.cs create mode 100644 src/Application/Departments/Commands/UpdateDepartment/UpdateDepartmentCommand.cs create mode 100644 src/Application/Departments/Queries/GetDepartmentById/GetDepartmentByIdQuery.cs create mode 100644 src/Application/Rooms/Commands/EnableRoom/EnableRoomCommand.cs diff --git a/src/Api/Controllers/DepartmentsController.cs b/src/Api/Controllers/DepartmentsController.cs index 6a010c00..717d3f0f 100644 --- a/src/Api/Controllers/DepartmentsController.cs +++ b/src/Api/Controllers/DepartmentsController.cs @@ -1,6 +1,10 @@ -using Application.Common.Models; +using Api.Controllers.Payload.Requests; +using Application.Common.Models; using Application.Departments.Commands.CreateDepartment; +using Application.Departments.Commands.DeleteDepartment; +using Application.Departments.Commands.UpdateDepartment; using Application.Departments.Queries.GetAllDepartments; +using Application.Departments.Queries.GetDepartmentById; using Application.Identity; using Application.Users.Queries; using Infrastructure.Identity.Authorization; @@ -38,4 +42,61 @@ public async Task>>> GetAllDepart var result = await Mediator.Send(new GetAllDepartmentsQuery()); return Ok(Result>.Succeed(result)); } + + /// + /// Get back a department based on its id + /// + /// id of the department to be found + /// A DepartmentDto representing the found department + [HttpGet("{departmentId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + public async Task>> GetDepartmentById([FromQuery] Guid departmentId) + { + var query = new GetDepartmentByIdQuery() + { + DepartmentId = departmentId + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } + + /// + /// Update a department + /// + /// id of the department to be updated + /// A DepartmentDto representing the updated department + [HttpPut("{departmentId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> UpdateDepartment([FromQuery] Guid departmentId, [FromBody] UpdateDepartmentRequest request) + { + var command = new UpdateDepartmentCommand() + { + DepartmentId = departmentId, + Name = request.Name + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } + + /// + /// Delete a department + /// + /// id of the department to be deleted + /// A DepartmentDto representing the deleted department + [HttpPut("{departmentId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> DeleteDepartment([FromQuery] Guid departmentId) + { + var command = new DeleteDepartmentCommand() + { + DepartmentId = departmentId, + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/UpdateDepartmentRequest.cs b/src/Api/Controllers/Payload/Requests/UpdateDepartmentRequest.cs new file mode 100644 index 00000000..467ceeb5 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/UpdateDepartmentRequest.cs @@ -0,0 +1,6 @@ +namespace Api.Controllers.Payload.Requests; + +public class UpdateDepartmentRequest +{ + public string Name { get; set; } = null!; +} \ No newline at end of file diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index 8d8916d6..315ba590 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -3,6 +3,7 @@ using Application.Identity; using Application.Rooms.Commands.CreateRoom; using Application.Rooms.Commands.DisableRoom; +using Application.Rooms.Commands.EnableRoom; using Application.Rooms.Commands.RemoveRoom; using Application.Rooms.Queries.GetEmptyContainersPaginated; using Infrastructure.Identity.Authorization; @@ -53,4 +54,22 @@ public async Task>> RemoveRoom(RemoveRoomCommand co var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } + + /// + /// Enable a room + /// + /// Command include the id of the room to be enabled + /// + [HttpPut("enable")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> EnableRoom([FromBody] EnableRoomCommand command) + { + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } + + } \ No newline at end of file diff --git a/src/Application/Departments/Commands/UpdateDepartment/UpdateDepartmentCommand.cs b/src/Application/Departments/Commands/UpdateDepartment/UpdateDepartmentCommand.cs new file mode 100644 index 00000000..941879af --- /dev/null +++ b/src/Application/Departments/Commands/UpdateDepartment/UpdateDepartmentCommand.cs @@ -0,0 +1,10 @@ +using Application.Users.Queries; +using MediatR; + +namespace Application.Departments.Commands.UpdateDepartment; + +public record UpdateDepartmentCommand : IRequest +{ + public Guid DepartmentId { get; set; } + public string Name { get; init; } = null!; +} \ No newline at end of file diff --git a/src/Application/Departments/Queries/GetDepartmentById/GetDepartmentByIdQuery.cs b/src/Application/Departments/Queries/GetDepartmentById/GetDepartmentByIdQuery.cs new file mode 100644 index 00000000..fe0ec11a --- /dev/null +++ b/src/Application/Departments/Queries/GetDepartmentById/GetDepartmentByIdQuery.cs @@ -0,0 +1,9 @@ +using Application.Users.Queries; +using MediatR; + +namespace Application.Departments.Queries.GetDepartmentById; + +public record GetDepartmentByIdQuery : IRequest +{ + public Guid DepartmentId { get; init; } +} \ No newline at end of file diff --git a/src/Application/Rooms/Commands/EnableRoom/EnableRoomCommand.cs b/src/Application/Rooms/Commands/EnableRoom/EnableRoomCommand.cs new file mode 100644 index 00000000..d89c52a5 --- /dev/null +++ b/src/Application/Rooms/Commands/EnableRoom/EnableRoomCommand.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Rooms.Commands.EnableRoom; + +public record EnableRoomCommand : IRequest +{ + public Guid RoomId { get; init; } +} \ No newline at end of file From b141a49566be6fd21837e44f56fe0576311c26cd Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 15:00:37 +0700 Subject: [PATCH 02/26] add: update room command and endpoint --- src/Api/Controllers/AuthController.cs | 1 + .../Payload/Requests/UpdateRoomRequest.cs | 8 ++++++++ src/Api/Controllers/RoomsController.cs | 20 ++++++++++++++++++- .../Commands/UpdateRoom/UpdateRoomCommand.cs | 12 +++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs create mode 100644 src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs diff --git a/src/Api/Controllers/AuthController.cs b/src/Api/Controllers/AuthController.cs index b0941458..afdf1099 100644 --- a/src/Api/Controllers/AuthController.cs +++ b/src/Api/Controllers/AuthController.cs @@ -102,6 +102,7 @@ private void SetJweToken(SecurityToken jweToken) var cookieOptions = new CookieOptions { HttpOnly = true, + }; var handler = new JwtSecurityTokenHandler(); Response.Cookies.Append("JweToken", handler.WriteToken(jweToken), cookieOptions); diff --git a/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs b/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs new file mode 100644 index 00000000..ce81c5fe --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs @@ -0,0 +1,8 @@ +namespace Api.Controllers.Payload.Requests; + +public class UpdateRoomRequest +{ + public string Description { get; set; } + public Guid StaffId { get; set; } + public int Capacity { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index 315ba590..62d33ddf 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -1,3 +1,4 @@ +using Api.Controllers.Payload.Requests; using Application.Common.Models; using Application.Common.Models.Dtos.Physical; using Application.Identity; @@ -5,6 +6,7 @@ using Application.Rooms.Commands.DisableRoom; using Application.Rooms.Commands.EnableRoom; using Application.Rooms.Commands.RemoveRoom; +using Application.Rooms.Commands.UpdateRoom; using Application.Rooms.Queries.GetEmptyContainersPaginated; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -71,5 +73,21 @@ public async Task>> EnableRoom([FromBody] EnableRoo return Ok(Result.Succeed(result)); } - + [HttpPut("{roomId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> Update([FromQuery] Guid roomId, [FromBody] UpdateRoomRequest request) + { + var command = new UpdateRoomCommand() + { + RoomId = roomId, + Description = request.Description, + Capacity = request.Capacity, + StaffId = request.StaffId + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs b/src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs new file mode 100644 index 00000000..d566adbb --- /dev/null +++ b/src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs @@ -0,0 +1,12 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Rooms.Commands.UpdateRoom; + +public record UpdateRoomCommand : IRequest +{ + public Guid RoomId { get; init; } + public string? Description { get; init; } + public Guid? StaffId { get; init; } + public int? Capacity { get; init; } +} \ No newline at end of file From 944947d6de0e32c1988aa101d7d301d240863e7f Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 15:05:40 +0700 Subject: [PATCH 03/26] add: get by id command and endpoint --- src/Api/Controllers/RoomsController.cs | 15 +++++++++++++++ .../Rooms/Queries/GetRoomById/GetRoomByIdQuery.cs | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/Application/Rooms/Queries/GetRoomById/GetRoomByIdQuery.cs diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index 62d33ddf..8b5929d3 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -8,6 +8,7 @@ using Application.Rooms.Commands.RemoveRoom; using Application.Rooms.Commands.UpdateRoom; using Application.Rooms.Queries.GetEmptyContainersPaginated; +using Application.Rooms.Queries.GetRoomById; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -90,4 +91,18 @@ public async Task>> Update([FromQuery] Guid roomId, var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } + + [HttpGet("{roomId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> GetById([FromQuery] Guid roomId) + { + var query = new GetRoomByIdQuery() + { + RoomId = roomId, + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Application/Rooms/Queries/GetRoomById/GetRoomByIdQuery.cs b/src/Application/Rooms/Queries/GetRoomById/GetRoomByIdQuery.cs new file mode 100644 index 00000000..638e9b51 --- /dev/null +++ b/src/Application/Rooms/Queries/GetRoomById/GetRoomByIdQuery.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Rooms.Queries.GetRoomById; + +public record GetRoomByIdQuery : IRequest +{ + public Guid RoomId { get; init; } +} \ No newline at end of file From 47a8d9b79c77f23e409ca2cac5dbcbf936625208 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 15:10:42 +0700 Subject: [PATCH 04/26] add: documentation on endpoints I forgot to add --- src/Api/Controllers/RoomsController.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index 8b5929d3..ee6a2af6 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -62,7 +62,7 @@ public async Task>> RemoveRoom(RemoveRoomCommand co /// Enable a room /// /// Command include the id of the room to be enabled - /// + /// a RoomDto of the enabled room [HttpPut("enable")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -74,6 +74,12 @@ public async Task>> EnableRoom([FromBody] EnableRoo return Ok(Result.Succeed(result)); } + /// + /// Update a room + /// + /// id of the room to be updated + /// room update details + /// a RoomDto of the updated room [HttpPut("{roomId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -92,6 +98,11 @@ public async Task>> Update([FromQuery] Guid roomId, return Ok(Result.Succeed(result)); } + /// + /// Get a room based on id + /// + /// id of the room to be found + /// a RoomDto of the found room [HttpGet("{roomId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] From 880a6b2d8e0e472700bac8533e7332673a83dd9c Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 19:22:36 +0700 Subject: [PATCH 05/26] fix: change annotation with some documentation and get all room paginated endpoint --- src/Api/Controllers/DepartmentsController.cs | 8 +++---- src/Api/Controllers/RoomsController.cs | 21 +++++++++++++++++-- .../GetAllRoomPaginatedQuery.cs | 13 ++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomPaginatedQuery.cs diff --git a/src/Api/Controllers/DepartmentsController.cs b/src/Api/Controllers/DepartmentsController.cs index 717d3f0f..299e277e 100644 --- a/src/Api/Controllers/DepartmentsController.cs +++ b/src/Api/Controllers/DepartmentsController.cs @@ -51,7 +51,7 @@ public async Task>>> GetAllDepart [HttpGet("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] - public async Task>> GetDepartmentById([FromQuery] Guid departmentId) + public async Task>> GetDepartmentById([FromRoute] Guid departmentId) { var query = new GetDepartmentByIdQuery() { @@ -70,7 +70,7 @@ public async Task>> GetDepartmentById([FromQu [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task>> UpdateDepartment([FromQuery] Guid departmentId, [FromBody] UpdateDepartmentRequest request) + public async Task>> UpdateDepartment([FromRoute] Guid departmentId, [FromBody] UpdateDepartmentRequest request) { var command = new UpdateDepartmentCommand() { @@ -86,11 +86,11 @@ public async Task>> UpdateDepartment([FromQue /// /// id of the department to be deleted /// A DepartmentDto representing the deleted department - [HttpPut("{departmentId:guid}")] + [HttpDelete("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task>> DeleteDepartment([FromQuery] Guid departmentId) + public async Task>> DeleteDepartment([FromRoute] Guid departmentId) { var command = new DeleteDepartmentCommand() { diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index ee6a2af6..e6cb4d26 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -7,6 +7,7 @@ using Application.Rooms.Commands.EnableRoom; using Application.Rooms.Commands.RemoveRoom; using Application.Rooms.Commands.UpdateRoom; +using Application.Rooms.Queries.GetAllRoomPaginated; using Application.Rooms.Queries.GetEmptyContainersPaginated; using Application.Rooms.Queries.GetRoomById; using Infrastructure.Identity.Authorization; @@ -85,7 +86,7 @@ public async Task>> EnableRoom([FromBody] EnableRoo [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status409Conflict)] - public async Task>> Update([FromQuery] Guid roomId, [FromBody] UpdateRoomRequest request) + public async Task>> Update([FromRoute] Guid roomId, [FromBody] UpdateRoomRequest request) { var command = new UpdateRoomCommand() { @@ -107,7 +108,7 @@ public async Task>> Update([FromQuery] Guid roomId, [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task>> GetById([FromQuery] Guid roomId) + public async Task>> GetById([FromRoute] Guid roomId) { var query = new GetRoomByIdQuery() { @@ -116,4 +117,20 @@ public async Task>> GetById([FromQuery] Guid roomId var result = await Mediator.Send(query); return Ok(Result.Succeed(result)); } + + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + public async Task>>> GetAllPaginated(int? page, int? size, string? sortBy, string? sortOrder) + { + var query = new GetAllRoomPaginatedQuery() + { + Page = page, + Size = size, + SortBy = sortBy, + SortOrder = sortOrder + }; + var result = await Mediator.Send(query); + return Ok(Result>.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomPaginatedQuery.cs b/src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomPaginatedQuery.cs new file mode 100644 index 00000000..abaf62c3 --- /dev/null +++ b/src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomPaginatedQuery.cs @@ -0,0 +1,13 @@ +using Application.Common.Models; +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Rooms.Queries.GetAllRoomPaginated; + +public record GetAllRoomPaginatedQuery : IRequest> +{ + public int? Page { get; init; } + public int? Size { get; init; } + public string? SortBy { get; init; } + public string? SortOrder { get; init; } +} \ No newline at end of file From 59d5efd865ce952c99056dc56b3c1f6df09f654c Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 19:22:51 +0700 Subject: [PATCH 06/26] fix: change annotation with some documentation and get all room paginated endpoint pt2 --- src/Api/Controllers/DepartmentsController.cs | 11 +++++----- src/Api/Controllers/RoomsController.cs | 22 +++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Api/Controllers/DepartmentsController.cs b/src/Api/Controllers/DepartmentsController.cs index 299e277e..43cb9055 100644 --- a/src/Api/Controllers/DepartmentsController.cs +++ b/src/Api/Controllers/DepartmentsController.cs @@ -47,7 +47,7 @@ public async Task>>> GetAllDepart /// Get back a department based on its id /// /// id of the department to be found - /// A DepartmentDto representing the found department + /// A DepartmentDto of the found department [HttpGet("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -64,8 +64,9 @@ public async Task>> GetDepartmentById([FromRo /// /// Update a department /// - /// id of the department to be updated - /// A DepartmentDto representing the updated department + /// Id of the department to be updated + /// Update department details + /// A DepartmentDto of the updated department [HttpPut("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -84,8 +85,8 @@ public async Task>> UpdateDepartment([FromRou /// /// Delete a department /// - /// id of the department to be deleted - /// A DepartmentDto representing the deleted department + /// Id of the department to be deleted + /// A DepartmentDto of the deleted department [HttpDelete("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index e6cb4d26..d763a5b0 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -62,8 +62,8 @@ public async Task>> RemoveRoom(RemoveRoomCommand co /// /// Enable a room /// - /// Command include the id of the room to be enabled - /// a RoomDto of the enabled room + /// Enable room details + /// A RoomDto of the enabled room [HttpPut("enable")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -78,9 +78,9 @@ public async Task>> EnableRoom([FromBody] EnableRoo /// /// Update a room /// - /// id of the room to be updated - /// room update details - /// a RoomDto of the updated room + /// Id of the room to be updated + /// Update room details + /// A RoomDto of the updated room [HttpPut("{roomId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -102,8 +102,8 @@ public async Task>> Update([FromRoute] Guid roomId, /// /// Get a room based on id /// - /// id of the room to be found - /// a RoomDto of the found room + /// Id of the room to be found + /// A RoomDto of the found room [HttpGet("{roomId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -118,6 +118,14 @@ public async Task>> GetById([FromRoute] Guid roomId return Ok(Result.Succeed(result)); } + /// + /// Get all rooms paginated + /// + /// The page index + /// The size number + /// Criteria + /// The order in which the rooms are sorted + /// A paginated list of rooms [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] From 97215f2f7c41a2203b86ab7d9a32a192a98384ab Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 19:26:01 +0700 Subject: [PATCH 07/26] add: remove locker endpoint and command --- src/Api/Controllers/LockersController.cs | 16 ++++++++++++++++ .../Commands/RemoveLocker/RemoveLockerCommand.cs | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/Application/Lockers/Commands/RemoveLocker/RemoveLockerCommand.cs diff --git a/src/Api/Controllers/LockersController.cs b/src/Api/Controllers/LockersController.cs index 1dd1b3ce..a4a6dcd3 100644 --- a/src/Api/Controllers/LockersController.cs +++ b/src/Api/Controllers/LockersController.cs @@ -4,6 +4,7 @@ using Application.Lockers.Commands.AddLocker; using Application.Lockers.Commands.DisableLocker; using Application.Lockers.Commands.EnableLocker; +using Application.Lockers.Commands.RemoveLocker; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -36,4 +37,19 @@ public async Task>> EnableLocker([FromBody] Enabl var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } + + [HttpDelete("{lockerId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> Remove([FromRoute] Guid lockerId) + { + var command = new RemoveLockerCommand() + { + LockerId = lockerId + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } } diff --git a/src/Application/Lockers/Commands/RemoveLocker/RemoveLockerCommand.cs b/src/Application/Lockers/Commands/RemoveLocker/RemoveLockerCommand.cs new file mode 100644 index 00000000..412df4b7 --- /dev/null +++ b/src/Application/Lockers/Commands/RemoveLocker/RemoveLockerCommand.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Lockers.Commands.RemoveLocker; + +public record RemoveLockerCommand : IRequest +{ + public Guid LockerId { get; init; } +} \ No newline at end of file From 205acc653ffa2fe261fab164cfcab1e68d5619ea Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 22:02:31 +0700 Subject: [PATCH 08/26] add: update locker command and request --- src/Api/Controllers/LockersController.cs | 30 ++++++++++++++++++- .../Payload/Requests/UpdateLockerRequest.cs | 7 +++++ .../Payload/Requests/UpdateRoomRequest.cs | 6 ++-- src/Api/Controllers/RoomsController.cs | 3 +- .../UpdateLocker/UpdateLockerCommand.cs | 11 +++++++ .../Commands/UpdateRoom/UpdateRoomCommand.cs | 6 ++-- 6 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 src/Api/Controllers/Payload/Requests/UpdateLockerRequest.cs create mode 100644 src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs diff --git a/src/Api/Controllers/LockersController.cs b/src/Api/Controllers/LockersController.cs index a4a6dcd3..77cf3442 100644 --- a/src/Api/Controllers/LockersController.cs +++ b/src/Api/Controllers/LockersController.cs @@ -1,10 +1,12 @@ -using Application.Common.Models; +using Api.Controllers.Payload.Requests; +using Application.Common.Models; using Application.Common.Models.Dtos.Physical; using Application.Identity; using Application.Lockers.Commands.AddLocker; using Application.Lockers.Commands.DisableLocker; using Application.Lockers.Commands.EnableLocker; using Application.Lockers.Commands.RemoveLocker; +using Application.Lockers.Commands.UpdateLocker; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -38,6 +40,32 @@ public async Task>> EnableLocker([FromBody] Enabl return Ok(Result.Succeed(result)); } + /// + /// Update a locker + /// + /// Id of the locker to be updated + /// Update locker details + /// A LockerDto of the updated locker + [HttpPut("{lockerId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> Update([FromRoute] Guid lockerId, [FromBody] UpdateLockerRequest request) + { + var command = new UpdateLockerCommand() + { + LockerId = lockerId + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } + + /// + /// Remove a locker + /// + /// Id of the locker to be removed + /// A LockerDto of the removed locker [HttpDelete("{lockerId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/src/Api/Controllers/Payload/Requests/UpdateLockerRequest.cs b/src/Api/Controllers/Payload/Requests/UpdateLockerRequest.cs new file mode 100644 index 00000000..dc348d57 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/UpdateLockerRequest.cs @@ -0,0 +1,7 @@ +namespace Api.Controllers.Payload.Requests; + +public class UpdateLockerRequest +{ + public string Name { get; set; } + public string? Description { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs b/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs index ce81c5fe..72f7bd09 100644 --- a/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs +++ b/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs @@ -2,7 +2,7 @@ namespace Api.Controllers.Payload.Requests; public class UpdateRoomRequest { - public string Description { get; set; } - public Guid StaffId { get; set; } - public int Capacity { get; set; } + public string Name { get; init; } + public string Description { get; init; } + public int Capacity { get; init; } } \ No newline at end of file diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index d763a5b0..176ad0a0 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -88,12 +88,13 @@ public async Task>> EnableRoom([FromBody] EnableRoo [ProducesResponseType(StatusCodes.Status409Conflict)] public async Task>> Update([FromRoute] Guid roomId, [FromBody] UpdateRoomRequest request) { + Console.WriteLine(request.Description); var command = new UpdateRoomCommand() { RoomId = roomId, + Name = request.Name, Description = request.Description, Capacity = request.Capacity, - StaffId = request.StaffId }; var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); diff --git a/src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs b/src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs new file mode 100644 index 00000000..f35daa47 --- /dev/null +++ b/src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs @@ -0,0 +1,11 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Lockers.Commands.UpdateLocker; + +public record UpdateLockerCommand : IRequest +{ + public Guid LockerId { get; set; } + public string Name { get; set; } = null!; + public string Description { get; set; } = null!; +} \ No newline at end of file diff --git a/src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs b/src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs index d566adbb..9f0dfdce 100644 --- a/src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs +++ b/src/Application/Rooms/Commands/UpdateRoom/UpdateRoomCommand.cs @@ -6,7 +6,7 @@ namespace Application.Rooms.Commands.UpdateRoom; public record UpdateRoomCommand : IRequest { public Guid RoomId { get; init; } - public string? Description { get; init; } - public Guid? StaffId { get; init; } - public int? Capacity { get; init; } + public string Name { get; set; } = null!; + public string Description { get; init; } = null!; + public int Capacity { get; init; } } \ No newline at end of file From 10355c3772bc260483e2785760bd753df0d179c8 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Fri, 26 May 2023 22:09:03 +0700 Subject: [PATCH 09/26] add: get locker by id endpoint and command --- src/Api/Controllers/DepartmentsController.cs | 4 ++-- src/Api/Controllers/LockersController.cs | 21 +++++++++++++++++++ src/Api/Controllers/RoomsController.cs | 6 +++--- .../GetLockerById/GetLockerByIdQuery.cs | 9 ++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/Application/Lockers/Queries/GetLockerById/GetLockerByIdQuery.cs diff --git a/src/Api/Controllers/DepartmentsController.cs b/src/Api/Controllers/DepartmentsController.cs index 43cb9055..19a60c4f 100644 --- a/src/Api/Controllers/DepartmentsController.cs +++ b/src/Api/Controllers/DepartmentsController.cs @@ -46,8 +46,8 @@ public async Task>>> GetAllDepart /// /// Get back a department based on its id /// - /// id of the department to be found - /// A DepartmentDto of the found department + /// id of the department to be retrieved + /// A DepartmentDto of the retrieved department [HttpGet("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/src/Api/Controllers/LockersController.cs b/src/Api/Controllers/LockersController.cs index 77cf3442..598d6677 100644 --- a/src/Api/Controllers/LockersController.cs +++ b/src/Api/Controllers/LockersController.cs @@ -7,6 +7,7 @@ using Application.Lockers.Commands.EnableLocker; using Application.Lockers.Commands.RemoveLocker; using Application.Lockers.Commands.UpdateLocker; +using Application.Lockers.Queries.GetLockerById; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -14,6 +15,26 @@ namespace Api.Controllers; public class LockersController : ApiControllerBase { + /// + /// Get a locker by id + /// + /// Id of the locker to be retrieved + /// A LockerDto of the retrieved locker + [HttpGet("{lockerId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> GetById([FromRoute] Guid lockerId) + { + var query = new GetLockerByIdQuery() + { + LockerId = lockerId + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } + [RequiresRole(IdentityData.Roles.Staff)] [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index 176ad0a0..9ebbde9e 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -101,10 +101,10 @@ public async Task>> Update([FromRoute] Guid roomId, } /// - /// Get a room based on id + /// Get a room by id /// - /// Id of the room to be found - /// A RoomDto of the found room + /// Id of the room to be retrieved + /// A RoomDto of the retrieved room [HttpGet("{roomId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/src/Application/Lockers/Queries/GetLockerById/GetLockerByIdQuery.cs b/src/Application/Lockers/Queries/GetLockerById/GetLockerByIdQuery.cs new file mode 100644 index 00000000..1a592104 --- /dev/null +++ b/src/Application/Lockers/Queries/GetLockerById/GetLockerByIdQuery.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Lockers.Queries.GetLockerById; + +public record GetLockerByIdQuery : IRequest +{ + public Guid LockerId { get; init; } +} \ No newline at end of file From 210bddf68da505758c5f81c1505e1fe799a71746 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 18:36:50 +0700 Subject: [PATCH 10/26] add: get all lockers paginated query and endpoint --- src/Api/Controllers/LockersController.cs | 25 +++++++++++++++++++ .../GetAllLockersPaginatedQueryParameters.cs | 13 ++++++++++ .../{ => Lockers}/UpdateLockerRequest.cs | 2 +- src/Api/Controllers/RoomsController.cs | 2 +- .../GetAllLockersPaginatedQuery.cs | 14 +++++++++++ ...dQuery.cs => GetAllRoomsPaginatedQuery.cs} | 2 +- 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/Api/Controllers/Payload/Requests/Lockers/GetAllLockersPaginatedQueryParameters.cs rename src/Api/Controllers/Payload/Requests/{ => Lockers}/UpdateLockerRequest.cs (69%) create mode 100644 src/Application/Lockers/Queries/GetAllLockersPaginated/GetAllLockersPaginatedQuery.cs rename src/Application/Rooms/Queries/GetAllRoomPaginated/{GetAllRoomPaginatedQuery.cs => GetAllRoomsPaginatedQuery.cs} (80%) diff --git a/src/Api/Controllers/LockersController.cs b/src/Api/Controllers/LockersController.cs index 598d6677..8ba6c192 100644 --- a/src/Api/Controllers/LockersController.cs +++ b/src/Api/Controllers/LockersController.cs @@ -1,4 +1,5 @@ using Api.Controllers.Payload.Requests; +using Api.Controllers.Payload.Requests.Lockers; using Application.Common.Models; using Application.Common.Models.Dtos.Physical; using Application.Identity; @@ -7,6 +8,7 @@ using Application.Lockers.Commands.EnableLocker; using Application.Lockers.Commands.RemoveLocker; using Application.Lockers.Commands.UpdateLocker; +using Application.Lockers.Queries.GetAllLockersPaginated; using Application.Lockers.Queries.GetLockerById; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -34,6 +36,29 @@ public async Task>> GetById([FromRoute] Guid lock var result = await Mediator.Send(query); return Ok(Result.Succeed(result)); } + + /// + /// Get all lockers paginated + /// + /// Get all lockers query parameters + /// A paginated list of LockerDto + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + public async Task>>> GetAllPaginated( + [FromQuery] GetAllLockersPaginatedQueryParameters queryParameters) + { + var query = new GetAllLockersPaginatedQuery() + { + RoomId = queryParameters.RoomId, + Page = queryParameters.Page, + Size = queryParameters.Size, + SortBy = queryParameters.SortBy, + SortOrder = queryParameters.SortOrder, + }; + var result = await Mediator.Send(query); + return Ok(Result>.Succeed(result)); + } [RequiresRole(IdentityData.Roles.Staff)] [HttpPost] diff --git a/src/Api/Controllers/Payload/Requests/Lockers/GetAllLockersPaginatedQueryParameters.cs b/src/Api/Controllers/Payload/Requests/Lockers/GetAllLockersPaginatedQueryParameters.cs new file mode 100644 index 00000000..b4b7f837 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Lockers/GetAllLockersPaginatedQueryParameters.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Api.Controllers.Payload.Requests.Lockers; + + +public class GetAllLockersPaginatedQueryParameters +{ + public Guid? RoomId { get; set; } + public int? Page { get; set; } + public int? Size { get; set; } + public string? SortBy { get; set; } + public string? SortOrder { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/UpdateLockerRequest.cs b/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs similarity index 69% rename from src/Api/Controllers/Payload/Requests/UpdateLockerRequest.cs rename to src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs index dc348d57..46b26311 100644 --- a/src/Api/Controllers/Payload/Requests/UpdateLockerRequest.cs +++ b/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs @@ -1,4 +1,4 @@ -namespace Api.Controllers.Payload.Requests; +namespace Api.Controllers.Payload.Requests.Lockers; public class UpdateLockerRequest { diff --git a/src/Api/Controllers/RoomsController.cs b/src/Api/Controllers/RoomsController.cs index 9ebbde9e..23d33af9 100644 --- a/src/Api/Controllers/RoomsController.cs +++ b/src/Api/Controllers/RoomsController.cs @@ -132,7 +132,7 @@ public async Task>> GetById([FromRoute] Guid roomId [ProducesResponseType(StatusCodes.Status403Forbidden)] public async Task>>> GetAllPaginated(int? page, int? size, string? sortBy, string? sortOrder) { - var query = new GetAllRoomPaginatedQuery() + var query = new GetAllRoomsPaginatedQuery() { Page = page, Size = size, diff --git a/src/Application/Lockers/Queries/GetAllLockersPaginated/GetAllLockersPaginatedQuery.cs b/src/Application/Lockers/Queries/GetAllLockersPaginated/GetAllLockersPaginatedQuery.cs new file mode 100644 index 00000000..4e0e8eb7 --- /dev/null +++ b/src/Application/Lockers/Queries/GetAllLockersPaginated/GetAllLockersPaginatedQuery.cs @@ -0,0 +1,14 @@ +using Application.Common.Models; +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Lockers.Queries.GetAllLockersPaginated; + +public record GetAllLockersPaginatedQuery : IRequest> +{ + public Guid? RoomId { get; init; } + public int? Page { get; init; } + public int? Size { get; init; } + public string? SortBy { get; init; } + public string? SortOrder { get; init; } +} \ No newline at end of file diff --git a/src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomPaginatedQuery.cs b/src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomsPaginatedQuery.cs similarity index 80% rename from src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomPaginatedQuery.cs rename to src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomsPaginatedQuery.cs index abaf62c3..c691570f 100644 --- a/src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomPaginatedQuery.cs +++ b/src/Application/Rooms/Queries/GetAllRoomPaginated/GetAllRoomsPaginatedQuery.cs @@ -4,7 +4,7 @@ namespace Application.Rooms.Queries.GetAllRoomPaginated; -public record GetAllRoomPaginatedQuery : IRequest> +public record GetAllRoomsPaginatedQuery : IRequest> { public int? Page { get; init; } public int? Size { get; init; } From d440ef34aa292230df15f722ad576865cbffadc0 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 18:42:58 +0700 Subject: [PATCH 11/26] add: enable folder command and endpoint --- src/Api/Controllers/FoldersController.cs | 28 +++++++++++++++++++ .../EnableFolder/EnableFolderCommand.cs | 9 ++++++ 2 files changed, 37 insertions(+) create mode 100644 src/Application/Folders/Commands/EnableFolder/EnableFolderCommand.cs diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index 77664c44..f2e09bbe 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -2,6 +2,7 @@ using Application.Common.Models.Dtos.Physical; using Application.Folders.Commands.AddFolder; using Application.Folders.Commands.DisableFolder; +using Application.Folders.Commands.EnableFolder; using Application.Identity; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -22,8 +23,35 @@ public async Task>> AddFolder([FromBody] AddFolde var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } + + /// + /// Enable a folder + /// + /// Enable folder details + /// A FolderDto of the enabled folder + [HttpPut("enable")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> EnableFolder([FromBody] EnableFolderCommand command) + { + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } + /// + /// Disable a folder + /// + /// Disable folder details + /// A FolderDto of the disabled folder [HttpPut("disable")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] public async Task>> DisableFolder([FromBody] DisableFolderCommand command) { var result = await Mediator.Send(command); diff --git a/src/Application/Folders/Commands/EnableFolder/EnableFolderCommand.cs b/src/Application/Folders/Commands/EnableFolder/EnableFolderCommand.cs new file mode 100644 index 00000000..eb7f49f9 --- /dev/null +++ b/src/Application/Folders/Commands/EnableFolder/EnableFolderCommand.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Folders.Commands.EnableFolder; + +public record EnableFolderCommand : IRequest +{ + public Guid FolderId { get; init; } +} From 5e1d565ed118f40d62a9d8f1ff805f4f5b581004 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 18:45:19 +0700 Subject: [PATCH 12/26] add: remove folder command and endpoint --- src/Api/Controllers/FoldersController.cs | 23 +++++++++++++++++++ .../RemoveFolder/RemoveFolderCommand.cs | 9 ++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/Application/Folders/Commands/RemoveFolder/RemoveFolderCommand.cs diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index f2e09bbe..6f3e91ee 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -3,6 +3,7 @@ using Application.Folders.Commands.AddFolder; using Application.Folders.Commands.DisableFolder; using Application.Folders.Commands.EnableFolder; +using Application.Folders.Commands.RemoveFolder; using Application.Identity; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -11,6 +12,11 @@ namespace Api.Controllers; public class FoldersController : ApiControllerBase { + /// + /// Add a folder + /// + /// Add folder details + /// A FolderDto of the added folder [RequiresRole(IdentityData.Roles.Staff)] [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] @@ -24,6 +30,23 @@ public async Task>> AddFolder([FromBody] AddFolde return Ok(Result.Succeed(result)); } + /// + /// Remove a folder + /// + /// Remove folder details + /// A FolderDto of the removed folder + [HttpPut("disable")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> RemoveFolder([FromBody] RemoveFolderCommand command) + { + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } + /// /// Enable a folder /// diff --git a/src/Application/Folders/Commands/RemoveFolder/RemoveFolderCommand.cs b/src/Application/Folders/Commands/RemoveFolder/RemoveFolderCommand.cs new file mode 100644 index 00000000..91db8b5e --- /dev/null +++ b/src/Application/Folders/Commands/RemoveFolder/RemoveFolderCommand.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Folders.Commands.RemoveFolder; + +public record RemoveFolderCommand : IRequest +{ + public Guid FolderId { get; init; } +} \ No newline at end of file From 34797157be655c78f8b19899fa36a898b161f100 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 18:47:17 +0700 Subject: [PATCH 13/26] add: get folder by id query and endpoint --- src/Api/Controllers/FoldersController.cs | 21 +++++++++++++++++++ .../GetFolderById/GetFolderByIdQuery.cs | 9 ++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/Application/Folders/Queries/GetFolderById/GetFolderByIdQuery.cs diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index 6f3e91ee..f976bda5 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -4,6 +4,7 @@ using Application.Folders.Commands.DisableFolder; using Application.Folders.Commands.EnableFolder; using Application.Folders.Commands.RemoveFolder; +using Application.Folders.Queries.GetFolderById; using Application.Identity; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -12,6 +13,26 @@ namespace Api.Controllers; public class FoldersController : ApiControllerBase { + /// + /// Get a folder by id + /// + /// Id of the folder to be retrieved + /// A FolderDto of the retrieved folder + [HttpGet("{folderId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> GetById([FromRoute] Guid folderId) + { + var query = new GetFolderByIdQuery() + { + FolderId = folderId + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } + /// /// Add a folder /// diff --git a/src/Application/Folders/Queries/GetFolderById/GetFolderByIdQuery.cs b/src/Application/Folders/Queries/GetFolderById/GetFolderByIdQuery.cs new file mode 100644 index 00000000..bf422997 --- /dev/null +++ b/src/Application/Folders/Queries/GetFolderById/GetFolderByIdQuery.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Folders.Queries.GetFolderById; + +public record GetFolderByIdQuery : IRequest +{ + public Guid FolderId { get; init; } +} \ No newline at end of file From 76a6de1a54ec81834451efb180c86520f9353b48 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 18:49:45 +0700 Subject: [PATCH 14/26] add: get all folders paginated query and endpoint --- src/Api/Controllers/FoldersController.cs | 26 +++++++++++++++++++ .../GetAllFoldersPaginatedQueryParameters.cs | 11 ++++++++ .../GetAllFoldersPaginatedQuery.cs | 15 +++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/Api/Controllers/Payload/Requests/Folders/GetAllFoldersPaginatedQueryParameters.cs create mode 100644 src/Application/Folders/Queries/GetAllFoldersPaginated/GetAllFoldersPaginatedQuery.cs diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index f976bda5..5f3e30b3 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -1,9 +1,11 @@ +using Api.Controllers.Payload.Requests.Folders; using Application.Common.Models; using Application.Common.Models.Dtos.Physical; using Application.Folders.Commands.AddFolder; using Application.Folders.Commands.DisableFolder; using Application.Folders.Commands.EnableFolder; using Application.Folders.Commands.RemoveFolder; +using Application.Folders.Queries.GetAllFoldersPaginated; using Application.Folders.Queries.GetFolderById; using Application.Identity; using Infrastructure.Identity.Authorization; @@ -33,6 +35,30 @@ public async Task>> GetById([FromRoute] Guid fold return Ok(Result.Succeed(result)); } + /// + /// Get all folders paginated + /// + /// Get all folders query parameters + /// A paginated list of FolderDto + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + public async Task>>> GetAllPaginated( + [FromQuery] GetAllFoldersPaginatedQueryParameters queryParameters) + { + var query = new GetAllFoldersPaginatedQuery() + { + RoomId = queryParameters.RoomId, + LockerId = queryParameters.LockerId, + Page = queryParameters.Page, + Size = queryParameters.Size, + SortBy = queryParameters.SortBy, + SortOrder = queryParameters.SortOrder, + }; + var result = await Mediator.Send(query); + return Ok(Result>.Succeed(result)); + } + /// /// Add a folder /// diff --git a/src/Api/Controllers/Payload/Requests/Folders/GetAllFoldersPaginatedQueryParameters.cs b/src/Api/Controllers/Payload/Requests/Folders/GetAllFoldersPaginatedQueryParameters.cs new file mode 100644 index 00000000..db642122 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Folders/GetAllFoldersPaginatedQueryParameters.cs @@ -0,0 +1,11 @@ +namespace Api.Controllers.Payload.Requests.Folders; + +public class GetAllFoldersPaginatedQueryParameters +{ + public Guid? RoomId { get; set; } + public Guid? LockerId { get; set; } + public int? Page { get; set; } + public int? Size { get; set; } + public string? SortBy { get; set; } + public string? SortOrder { get; set; } +} \ No newline at end of file diff --git a/src/Application/Folders/Queries/GetAllFoldersPaginated/GetAllFoldersPaginatedQuery.cs b/src/Application/Folders/Queries/GetAllFoldersPaginated/GetAllFoldersPaginatedQuery.cs new file mode 100644 index 00000000..ecd9fbb2 --- /dev/null +++ b/src/Application/Folders/Queries/GetAllFoldersPaginated/GetAllFoldersPaginatedQuery.cs @@ -0,0 +1,15 @@ +using Application.Common.Models; +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Folders.Queries.GetAllFoldersPaginated; + +public record GetAllFoldersPaginatedQuery : IRequest> +{ + public Guid? RoomId { get; init; } + public Guid? LockerId { get; init; } + public int? Page { get; init; } + public int? Size { get; init; } + public string? SortBy { get; init; } + public string? SortOrder { get; init; } +} \ No newline at end of file From 6d989f7ae29b5dda9978ef3b12ec569282ed3734 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:01:16 +0700 Subject: [PATCH 15/26] add: update folder command and endpoint --- src/Api/Controllers/FoldersController.cs | 25 +++++++++++++++++++ src/Api/Controllers/LockersController.cs | 5 +++- .../Requests/Folders/UpdateFolderRequest.cs | 8 ++++++ .../Requests/Lockers/UpdateLockerRequest.cs | 5 ++-- .../UpdateFolder/UpdateFolderCommand.cs | 12 +++++++++ .../UpdateLocker/UpdateLockerCommand.cs | 1 + 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs create mode 100644 src/Application/Folders/Commands/UpdateFolder/UpdateFolderCommand.cs diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index 5f3e30b3..c597fcee 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -5,6 +5,7 @@ using Application.Folders.Commands.DisableFolder; using Application.Folders.Commands.EnableFolder; using Application.Folders.Commands.RemoveFolder; +using Application.Folders.Commands.UpdateFolder; using Application.Folders.Queries.GetAllFoldersPaginated; using Application.Folders.Queries.GetFolderById; using Application.Identity; @@ -127,4 +128,28 @@ public async Task>> DisableFolder([FromBody] Disa var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } + + /// + /// Update a folder + /// + /// Id of the folder to be updated + /// Update folder details + /// A FolderDto of the updated folder + [HttpPut("{folderId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> Update([FromRoute] Guid folderId, [FromBody] UpdateFolderRequest request) + { + var command = new UpdateFolderCommand() + { + FolderId = folderId, + Name = request.Name, + Description = request.Description, + Capacity = request.Capacity + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Api/Controllers/LockersController.cs b/src/Api/Controllers/LockersController.cs index 8ba6c192..80e37551 100644 --- a/src/Api/Controllers/LockersController.cs +++ b/src/Api/Controllers/LockersController.cs @@ -101,7 +101,10 @@ public async Task>> Update([FromRoute] Guid locke { var command = new UpdateLockerCommand() { - LockerId = lockerId + LockerId = lockerId, + Name = request.Name, + Description = request.Description, + Capacity = request.Capacity }; var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); diff --git a/src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs b/src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs new file mode 100644 index 00000000..bd21c3b2 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs @@ -0,0 +1,8 @@ +namespace Api.Controllers.Payload.Requests.Folders; + +public class UpdateFolderRequest +{ + public string Name { get; set; } = null!; + public string Description { get; set; } = null!; + public int Capacity { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs b/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs index 46b26311..46822e85 100644 --- a/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs +++ b/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs @@ -2,6 +2,7 @@ namespace Api.Controllers.Payload.Requests.Lockers; public class UpdateLockerRequest { - public string Name { get; set; } - public string? Description { get; set; } + public string Name { get; set; } = null!; + public string Description { get; set; } = null!; + public int Capacity { get; set; } } \ No newline at end of file diff --git a/src/Application/Folders/Commands/UpdateFolder/UpdateFolderCommand.cs b/src/Application/Folders/Commands/UpdateFolder/UpdateFolderCommand.cs new file mode 100644 index 00000000..8a46ce04 --- /dev/null +++ b/src/Application/Folders/Commands/UpdateFolder/UpdateFolderCommand.cs @@ -0,0 +1,12 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Folders.Commands.UpdateFolder; + +public record UpdateFolderCommand : IRequest +{ + public Guid FolderId { get; init; } + public string Name { get; init; } = null!; + public string Description { get; init; } = null!; + public int Capacity { get; init; } +} \ No newline at end of file diff --git a/src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs b/src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs index f35daa47..cf96ecd4 100644 --- a/src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs +++ b/src/Application/Lockers/Commands/UpdateLocker/UpdateLockerCommand.cs @@ -8,4 +8,5 @@ public record UpdateLockerCommand : IRequest public Guid LockerId { get; set; } public string Name { get; set; } = null!; public string Description { get; set; } = null!; + public int Capacity { get; init; } } \ No newline at end of file From 2f258f1d6ddf8d31fd5aa9f1c68d6eeae1f07024 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:05:49 +0700 Subject: [PATCH 16/26] add: update document command and endpoint --- src/Api/Controllers/DocumentsController.cs | 26 +++++++++++++++++++ .../Documents/UpdateDocumentRequest.cs | 8 ++++++ .../UpdateDocument/UpdateDocumentCommand.cs | 11 +++----- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs diff --git a/src/Api/Controllers/DocumentsController.cs b/src/Api/Controllers/DocumentsController.cs index 7d491b2b..d96ff79b 100644 --- a/src/Api/Controllers/DocumentsController.cs +++ b/src/Api/Controllers/DocumentsController.cs @@ -1,7 +1,9 @@ +using Api.Controllers.Payload.Requests.Documents; using Application.Common.Models; using Application.Common.Models.Dtos.Physical; using Application.Departments.Commands.CreateDepartment; using Application.Documents.Commands.ImportDocument; +using Application.Documents.Commands.UpdateDocument; using Application.Documents.Queries.GetAllDocumentsPaginated; using Application.Documents.Queries.GetDocumentById; using Application.Documents.Queries.GetDocumentTypes; @@ -70,4 +72,28 @@ public async Task>> GetDocumentById(Guid id) var result = await Mediator.Send(query); return Ok(Result.Succeed(result)); } + + /// + /// Update a document + /// + /// Id of the document to be updated + /// Update document details + /// A DocumentDto of the updated document + [HttpPut("{documentId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> UpdateDocument([FromRoute] Guid documentId, [FromBody] UpdateDocumentRequest request) + { + var query = new UpdateDocumentCommand() + { + DocumentId = documentId, + Title = request.Title, + Description = request.Description, + DocumentType = request.DocumentType + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs b/src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs new file mode 100644 index 00000000..4ff487f6 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs @@ -0,0 +1,8 @@ +namespace Api.Controllers.Payload.Requests.Documents; + +public class UpdateDocumentRequest +{ + public string Title { get; set; } = null!; + public string Description { get; set; } = null!; + public string DocumentType { get; set; } = null!; +} \ No newline at end of file diff --git a/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs b/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs index 96e9dc8d..eb315e59 100644 --- a/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs +++ b/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs @@ -5,11 +5,8 @@ namespace Application.Documents.Commands.UpdateDocument; public record UpdateDocumentCommand : IRequest { - public Guid Id { get; set; } - public string? Title { get; set; } - public string? Description { get; set; } - public string? DocumentType { get; set; } - public Guid? Department { get; set; } - public Guid? Importer { get; set; } - public Guid? Folder { get; set; } + public Guid DocumentId { get; init; } + public string Title { get; init; } = null!; + public string Description { get; init; } = null!; + public string DocumentType { get; init; } = null!; } \ No newline at end of file From 0278989ec228f62bec8842103ed644e0640b57d7 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:08:28 +0700 Subject: [PATCH 17/26] add: delete document command and endpoint --- src/Api/Controllers/DocumentsController.cs | 22 +++++++++++++++++-- .../DeleteDocument/DeleteDocumentCommand.cs | 9 ++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/Application/Documents/Commands/DeleteDocument/DeleteDocumentCommand.cs diff --git a/src/Api/Controllers/DocumentsController.cs b/src/Api/Controllers/DocumentsController.cs index d96ff79b..d0c4f073 100644 --- a/src/Api/Controllers/DocumentsController.cs +++ b/src/Api/Controllers/DocumentsController.cs @@ -1,14 +1,13 @@ using Api.Controllers.Payload.Requests.Documents; using Application.Common.Models; using Application.Common.Models.Dtos.Physical; -using Application.Departments.Commands.CreateDepartment; +using Application.Documents.Commands.DeleteDocument; using Application.Documents.Commands.ImportDocument; using Application.Documents.Commands.UpdateDocument; using Application.Documents.Queries.GetAllDocumentsPaginated; using Application.Documents.Queries.GetDocumentById; using Application.Documents.Queries.GetDocumentTypes; using Application.Identity; -using Application.Users.Queries; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -96,4 +95,23 @@ public async Task>> UpdateDocument([FromRoute] var result = await Mediator.Send(query); return Ok(Result.Succeed(result)); } + + /// + /// Delete a document + /// + /// Id of the document to be deleted + /// A DocumentDto of the deleted document + [HttpDelete("{documentId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> UpdateDocument([FromRoute] Guid documentId) + { + var query = new DeleteDocumentCommand() + { + DocumentId = documentId, + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Application/Documents/Commands/DeleteDocument/DeleteDocumentCommand.cs b/src/Application/Documents/Commands/DeleteDocument/DeleteDocumentCommand.cs new file mode 100644 index 00000000..eefecf87 --- /dev/null +++ b/src/Application/Documents/Commands/DeleteDocument/DeleteDocumentCommand.cs @@ -0,0 +1,9 @@ +using Application.Common.Models.Dtos.Physical; +using MediatR; + +namespace Application.Documents.Commands.DeleteDocument; + +public record DeleteDocumentCommand : IRequest +{ + public Guid DocumentId { get; init; } +} \ No newline at end of file From 2ec1ed85497bd24241c979cf738405ea6d23348a Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:16:31 +0700 Subject: [PATCH 18/26] add: update user command and endpoint --- .../Documents/UpdateDocumentRequest.cs | 2 +- .../Requests/Folders/UpdateFolderRequest.cs | 2 +- .../Requests/Lockers/UpdateLockerRequest.cs | 2 +- .../Payload/Requests/UpdateRoomRequest.cs | 6 ++-- .../Requests/Users/UpdateUserRequest.cs | 11 +++++++ src/Api/Controllers/UsersController.cs | 29 +++++++++++++++++++ .../Commands/UpdateUser/UpdateUserCommand.cs | 15 ++++++++++ 7 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/Api/Controllers/Payload/Requests/Users/UpdateUserRequest.cs create mode 100644 src/Application/Users/Commands/UpdateUser/UpdateUserCommand.cs diff --git a/src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs b/src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs index 4ff487f6..e6a0885b 100644 --- a/src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs +++ b/src/Api/Controllers/Payload/Requests/Documents/UpdateDocumentRequest.cs @@ -3,6 +3,6 @@ namespace Api.Controllers.Payload.Requests.Documents; public class UpdateDocumentRequest { public string Title { get; set; } = null!; - public string Description { get; set; } = null!; + public string? Description { get; set; } public string DocumentType { get; set; } = null!; } \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs b/src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs index bd21c3b2..97e9691f 100644 --- a/src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs +++ b/src/Api/Controllers/Payload/Requests/Folders/UpdateFolderRequest.cs @@ -3,6 +3,6 @@ namespace Api.Controllers.Payload.Requests.Folders; public class UpdateFolderRequest { public string Name { get; set; } = null!; - public string Description { get; set; } = null!; + public string? Description { get; set; } public int Capacity { get; set; } } \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs b/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs index 46822e85..a7f69036 100644 --- a/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs +++ b/src/Api/Controllers/Payload/Requests/Lockers/UpdateLockerRequest.cs @@ -3,6 +3,6 @@ namespace Api.Controllers.Payload.Requests.Lockers; public class UpdateLockerRequest { public string Name { get; set; } = null!; - public string Description { get; set; } = null!; + public string? Description { get; set; } public int Capacity { get; set; } } \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs b/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs index 72f7bd09..a579a447 100644 --- a/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs +++ b/src/Api/Controllers/Payload/Requests/UpdateRoomRequest.cs @@ -2,7 +2,7 @@ namespace Api.Controllers.Payload.Requests; public class UpdateRoomRequest { - public string Name { get; init; } - public string Description { get; init; } - public int Capacity { get; init; } + public string Name { get; set; } = null!; + public string? Description { get; set; } + public int Capacity { get; set; } } \ No newline at end of file diff --git a/src/Api/Controllers/Payload/Requests/Users/UpdateUserRequest.cs b/src/Api/Controllers/Payload/Requests/Users/UpdateUserRequest.cs new file mode 100644 index 00000000..77bcb0e4 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Users/UpdateUserRequest.cs @@ -0,0 +1,11 @@ +namespace Api.Controllers.Payload.Requests.Users; + +public class UpdateUserRequest +{ + public string Username { get; set; } = null!; + public string Email { get; set; } = null!; + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string Role { get; set; } = null!; + public string? Position { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/UsersController.cs b/src/Api/Controllers/UsersController.cs index 33aa1714..a82c5475 100644 --- a/src/Api/Controllers/UsersController.cs +++ b/src/Api/Controllers/UsersController.cs @@ -1,7 +1,9 @@ +using Api.Controllers.Payload.Requests.Users; using Application.Common.Models; using Application.Identity; using Application.Users.Commands.CreateUser; using Application.Users.Commands.DisableUser; +using Application.Users.Commands.UpdateUser; using Application.Users.Queries; using Application.Users.Queries.GetUsersByName; using Infrastructure.Identity.Authorization; @@ -51,4 +53,31 @@ public async Task>> DisableUser([FromBody] DisableU var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } + + /// + /// Update a user + /// + /// Id of the user to be updated + /// Update user details + /// A UserDto of the updated user + [HttpPut("{userId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> Update([FromRoute] Guid userId, [FromBody] UpdateUserRequest request) + { + var command = new UpdateUserCommand() + { + UserId = userId, + Username = request.Username, + Email = request.Email, + FirstName = request.FirstName, + LastName = request.LastName, + Role = request.Role, + Position = request.Position, + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } } diff --git a/src/Application/Users/Commands/UpdateUser/UpdateUserCommand.cs b/src/Application/Users/Commands/UpdateUser/UpdateUserCommand.cs new file mode 100644 index 00000000..0f3736ea --- /dev/null +++ b/src/Application/Users/Commands/UpdateUser/UpdateUserCommand.cs @@ -0,0 +1,15 @@ +using Application.Users.Queries; +using MediatR; + +namespace Application.Users.Commands.UpdateUser; + +public record UpdateUserCommand : IRequest +{ + public Guid UserId { get; init; } + public string Username { get; init; } = null!; + public string Email { get; init; } = null!; + public string? FirstName { get; init; } + public string? LastName { get; init; } + public string Role { get; init; } = null!; + public string? Position { get; init; } +} \ No newline at end of file From aa5ff257105a4f7e174cd118a1d435a9dc3ce97a Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:20:44 +0700 Subject: [PATCH 19/26] add: get user by id query and endpoint --- src/Api/Controllers/UsersController.cs | 20 +++++++++++++++++++ .../Queries/GetUserById/GetUserByIdQuery.cs | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/Application/Users/Queries/GetUserById/GetUserByIdQuery.cs diff --git a/src/Api/Controllers/UsersController.cs b/src/Api/Controllers/UsersController.cs index a82c5475..6787ebee 100644 --- a/src/Api/Controllers/UsersController.cs +++ b/src/Api/Controllers/UsersController.cs @@ -5,6 +5,7 @@ using Application.Users.Commands.DisableUser; using Application.Users.Commands.UpdateUser; using Application.Users.Queries; +using Application.Users.Queries.GetUserById; using Application.Users.Queries.GetUsersByName; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Authorization; @@ -14,6 +15,25 @@ namespace Api.Controllers; public class UsersController : ApiControllerBase { + /// + /// Get a user by id + /// + /// Id of the user to be retrieved + /// A UserDto of the retrieved user + [HttpGet("{userId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> GetUserById([FromRoute] Guid userId) + { + var query = new GetUserByIdQuery + { + UserId = userId, + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } + [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] diff --git a/src/Application/Users/Queries/GetUserById/GetUserByIdQuery.cs b/src/Application/Users/Queries/GetUserById/GetUserByIdQuery.cs new file mode 100644 index 00000000..9f2e60d7 --- /dev/null +++ b/src/Application/Users/Queries/GetUserById/GetUserByIdQuery.cs @@ -0,0 +1,8 @@ +using MediatR; + +namespace Application.Users.Queries.GetUserById; + +public record GetUserByIdQuery : IRequest +{ + public Guid UserId { get; init; } +} \ No newline at end of file From 61a1c53589d790d91d6c8edd8227d1bd9621aa2f Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:25:17 +0700 Subject: [PATCH 20/26] add: get all users paginated query and endpoint --- .../GetAllUsersPaginatedQueryParameters.cs | 11 ++++++++ src/Api/Controllers/UsersController.cs | 26 +++++++++++++++++++ .../GetAllUsersPaginatedQuery.cs | 14 ++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/Api/Controllers/Payload/Requests/Users/GetAllUsersPaginatedQueryParameters.cs create mode 100644 src/Application/Users/Queries/GetAllUsersPaginated/GetAllUsersPaginatedQuery.cs diff --git a/src/Api/Controllers/Payload/Requests/Users/GetAllUsersPaginatedQueryParameters.cs b/src/Api/Controllers/Payload/Requests/Users/GetAllUsersPaginatedQueryParameters.cs new file mode 100644 index 00000000..d3484660 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Users/GetAllUsersPaginatedQueryParameters.cs @@ -0,0 +1,11 @@ +namespace Api.Controllers.Payload.Requests.Users; + +public class GetAllUsersPaginatedQueryParameters +{ + public Guid? DepartmentId { get; set; } + public string? SearchTerm { get; set; } + public int? Page { get; set; } + public int? Size { get; set; } + public string? SortBy { get; set; } + public string? SortOrder { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/UsersController.cs b/src/Api/Controllers/UsersController.cs index 6787ebee..99d66bb1 100644 --- a/src/Api/Controllers/UsersController.cs +++ b/src/Api/Controllers/UsersController.cs @@ -1,10 +1,12 @@ using Api.Controllers.Payload.Requests.Users; using Application.Common.Models; +using Application.Common.Models.Dtos.Physical; using Application.Identity; using Application.Users.Commands.CreateUser; using Application.Users.Commands.DisableUser; using Application.Users.Commands.UpdateUser; using Application.Users.Queries; +using Application.Users.Queries.GetAllUsersPaginated; using Application.Users.Queries.GetUserById; using Application.Users.Queries.GetUsersByName; using Infrastructure.Identity.Authorization; @@ -34,6 +36,30 @@ public async Task>> GetUserById([FromRoute] Guid us return Ok(Result.Succeed(result)); } + /// + /// Get all users paginated + /// + /// Get all users query parameters + /// A paginated list of UserDto + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + public async Task>>> GetAllPaginated( + [FromQuery] GetAllUsersPaginatedQueryParameters queryParameters) + { + var query = new GetAllUsersPaginatedQuery() + { + DepartmentId = queryParameters.DepartmentId, + SearchTerm = queryParameters.SearchTerm, + Page = queryParameters.Page, + Size = queryParameters.Size, + SortBy = queryParameters.SortBy, + SortOrder = queryParameters.SortOrder, + }; + var result = await Mediator.Send(query); + return Ok(Result>.Succeed(result)); + } + [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] diff --git a/src/Application/Users/Queries/GetAllUsersPaginated/GetAllUsersPaginatedQuery.cs b/src/Application/Users/Queries/GetAllUsersPaginated/GetAllUsersPaginatedQuery.cs new file mode 100644 index 00000000..0c3146c7 --- /dev/null +++ b/src/Application/Users/Queries/GetAllUsersPaginated/GetAllUsersPaginatedQuery.cs @@ -0,0 +1,14 @@ +using Application.Common.Models; +using MediatR; + +namespace Application.Users.Queries.GetAllUsersPaginated; + +public record GetAllUsersPaginatedQuery : IRequest> +{ + public Guid? DepartmentId { get; init; } + public string? SearchTerm { get; init; } + public int? Page { get; init; } + public int? Size { get; init; } + public string? SortBy { get; init; } + public string? SortOrder { get; init; } +} \ No newline at end of file From 92786ac18f4118c1181308d519d4501dcc184edb Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:29:58 +0700 Subject: [PATCH 21/26] add: remove staff from room command and endpoint --- .../Staffs/RemoveStaffFromRoomRequest.cs | 6 +++++ src/Api/Controllers/StaffsController.cs | 23 +++++++++++++++++++ .../RemoveStaffFromRoomCommand.cs | 10 ++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/Api/Controllers/Payload/Requests/Staffs/RemoveStaffFromRoomRequest.cs create mode 100644 src/Application/Staffs/Commands/RemoveStaffFromRoom/RemoveStaffFromRoomCommand.cs diff --git a/src/Api/Controllers/Payload/Requests/Staffs/RemoveStaffFromRoomRequest.cs b/src/Api/Controllers/Payload/Requests/Staffs/RemoveStaffFromRoomRequest.cs new file mode 100644 index 00000000..811608df --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Staffs/RemoveStaffFromRoomRequest.cs @@ -0,0 +1,6 @@ +namespace Api.Controllers.Payload.Requests.Staffs; + +public class RemoveStaffFromRoomRequest +{ + public Guid RoomId { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/StaffsController.cs b/src/Api/Controllers/StaffsController.cs index 255335ef..741601c7 100644 --- a/src/Api/Controllers/StaffsController.cs +++ b/src/Api/Controllers/StaffsController.cs @@ -1,6 +1,8 @@ +using Api.Controllers.Payload.Requests.Staffs; using Application.Common.Models; using Application.Identity; using Application.Staffs.Commands.CreateStaff; +using Application.Staffs.Commands.RemoveStaffFromRoom; using Application.Users.Queries.Physical; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -19,4 +21,25 @@ public async Task>> CreateStaff([FromBody] CreateS var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } + + /// + /// Remove a staff from room + /// + /// Id of the staff to be removed from room + /// Remove details + /// A StaffDto of the removed staff + [HttpPut("{staffId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> RemoveStaffFromRoom([FromRoute] Guid staffId, [FromBody] RemoveStaffFromRoomRequest request) + { + var command = new RemoveStaffFromRoomCommand() + { + StaffId = staffId, + RoomId = request.RoomId, + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } } \ No newline at end of file diff --git a/src/Application/Staffs/Commands/RemoveStaffFromRoom/RemoveStaffFromRoomCommand.cs b/src/Application/Staffs/Commands/RemoveStaffFromRoom/RemoveStaffFromRoomCommand.cs new file mode 100644 index 00000000..c25f18ca --- /dev/null +++ b/src/Application/Staffs/Commands/RemoveStaffFromRoom/RemoveStaffFromRoomCommand.cs @@ -0,0 +1,10 @@ +using Application.Users.Queries.Physical; +using MediatR; + +namespace Application.Staffs.Commands.RemoveStaffFromRoom; + +public record RemoveStaffFromRoomCommand : IRequest +{ + public Guid StaffId { get; init; } + public Guid RoomId { get; init; } +} \ No newline at end of file From 11e894ef2ae8c14894c80ea5d457cbf43c3385a5 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:31:59 +0700 Subject: [PATCH 22/26] add: get staff by id query and endpoint --- src/Api/Controllers/StaffsController.cs | 26 +++++++++++++++++-- .../Staffs/Queries/GetStaffByIdQuery.cs | 9 +++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Application/Staffs/Queries/GetStaffByIdQuery.cs diff --git a/src/Api/Controllers/StaffsController.cs b/src/Api/Controllers/StaffsController.cs index 741601c7..59a64916 100644 --- a/src/Api/Controllers/StaffsController.cs +++ b/src/Api/Controllers/StaffsController.cs @@ -3,6 +3,7 @@ using Application.Identity; using Application.Staffs.Commands.CreateStaff; using Application.Staffs.Commands.RemoveStaffFromRoom; +using Application.Staffs.Queries; using Application.Users.Queries.Physical; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -11,6 +12,26 @@ namespace Api.Controllers; public class StaffsController : ApiControllerBase { + /// + /// Get a staff by id + /// + /// Id of the staff to be retrieved + /// A StaffDto of the retrieved staff + [HttpGet("{staffId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + public async Task>> GetById([FromRoute] Guid staffId) + { + var query = new GetStaffByIdQuery() + { + StaffId = staffId + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } + [RequiresRole(IdentityData.Roles.Admin)] [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] @@ -21,7 +42,7 @@ public async Task>> CreateStaff([FromBody] CreateS var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } - + /// /// Remove a staff from room /// @@ -32,7 +53,8 @@ public async Task>> CreateStaff([FromBody] CreateS [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task>> RemoveStaffFromRoom([FromRoute] Guid staffId, [FromBody] RemoveStaffFromRoomRequest request) + public async Task>> RemoveStaffFromRoom([FromRoute] Guid staffId, + [FromBody] RemoveStaffFromRoomRequest request) { var command = new RemoveStaffFromRoomCommand() { diff --git a/src/Application/Staffs/Queries/GetStaffByIdQuery.cs b/src/Application/Staffs/Queries/GetStaffByIdQuery.cs new file mode 100644 index 00000000..23e51098 --- /dev/null +++ b/src/Application/Staffs/Queries/GetStaffByIdQuery.cs @@ -0,0 +1,9 @@ +using Application.Users.Queries.Physical; +using MediatR; + +namespace Application.Staffs.Queries; + +public record GetStaffByIdQuery : IRequest +{ + public Guid StaffId { get; init; } +} \ No newline at end of file From 746acb914e1f19533f559559b89a944d2555d2f5 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:34:52 +0700 Subject: [PATCH 23/26] add: get all staffs paginated query and endpoint --- .../GetAllStaffsPaginatedQueryParameters.cs | 10 ++++++++ src/Api/Controllers/StaffsController.cs | 24 +++++++++++++++++++ .../GetAllStaffsPaginatedQuery.cs | 14 +++++++++++ .../{ => GetStaffById}/GetStaffByIdQuery.cs | 2 +- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/Api/Controllers/Payload/Requests/Staffs/GetAllStaffsPaginatedQueryParameters.cs create mode 100644 src/Application/Staffs/Queries/GetAllStaffsPaginated/GetAllStaffsPaginatedQuery.cs rename src/Application/Staffs/Queries/{ => GetStaffById}/GetStaffByIdQuery.cs (75%) diff --git a/src/Api/Controllers/Payload/Requests/Staffs/GetAllStaffsPaginatedQueryParameters.cs b/src/Api/Controllers/Payload/Requests/Staffs/GetAllStaffsPaginatedQueryParameters.cs new file mode 100644 index 00000000..bcb47cb4 --- /dev/null +++ b/src/Api/Controllers/Payload/Requests/Staffs/GetAllStaffsPaginatedQueryParameters.cs @@ -0,0 +1,10 @@ +namespace Api.Controllers.Payload.Requests.Staffs; + +public class GetAllStaffsPaginatedQueryParameters +{ + public string? SearchTerm { get; set; } + public int? Page { get; set; } + public int? Size { get; set; } + public string? SortBy { get; set; } + public string? SortOrder { get; set; } +} \ No newline at end of file diff --git a/src/Api/Controllers/StaffsController.cs b/src/Api/Controllers/StaffsController.cs index 59a64916..b2ce8125 100644 --- a/src/Api/Controllers/StaffsController.cs +++ b/src/Api/Controllers/StaffsController.cs @@ -4,6 +4,8 @@ using Application.Staffs.Commands.CreateStaff; using Application.Staffs.Commands.RemoveStaffFromRoom; using Application.Staffs.Queries; +using Application.Staffs.Queries.GetAllStaffsPaginated; +using Application.Staffs.Queries.GetStaffById; using Application.Users.Queries.Physical; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -32,6 +34,28 @@ public async Task>> GetById([FromRoute] Guid staff return Ok(Result.Succeed(result)); } + /// + /// Get all staffs paginated + /// + /// Get all staffs query parameters + /// A paginated list of StaffDto + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + public async Task>>> GetAllPaginated( + [FromQuery] GetAllStaffsPaginatedQueryParameters queryParameters) + { + var query = new GetAllStaffsPaginatedQuery() + { + Page = queryParameters.Page, + Size = queryParameters.Size, + SortBy = queryParameters.SortBy, + SortOrder = queryParameters.SortOrder, + }; + var result = await Mediator.Send(query); + return Ok(Result>.Succeed(result)); + } + [RequiresRole(IdentityData.Roles.Admin)] [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] diff --git a/src/Application/Staffs/Queries/GetAllStaffsPaginated/GetAllStaffsPaginatedQuery.cs b/src/Application/Staffs/Queries/GetAllStaffsPaginated/GetAllStaffsPaginatedQuery.cs new file mode 100644 index 00000000..a640b907 --- /dev/null +++ b/src/Application/Staffs/Queries/GetAllStaffsPaginated/GetAllStaffsPaginatedQuery.cs @@ -0,0 +1,14 @@ +using Application.Common.Models; +using Application.Users.Queries.Physical; +using MediatR; + +namespace Application.Staffs.Queries.GetAllStaffsPaginated; + +public class GetAllStaffsPaginatedQuery : IRequest> +{ + public string? SearchTerm { get; set; } + public int? Page { get; set; } + public int? Size { get; set; } + public string? SortBy { get; set; } + public string? SortOrder { get; set; } +} \ No newline at end of file diff --git a/src/Application/Staffs/Queries/GetStaffByIdQuery.cs b/src/Application/Staffs/Queries/GetStaffById/GetStaffByIdQuery.cs similarity index 75% rename from src/Application/Staffs/Queries/GetStaffByIdQuery.cs rename to src/Application/Staffs/Queries/GetStaffById/GetStaffByIdQuery.cs index 23e51098..7efed7f2 100644 --- a/src/Application/Staffs/Queries/GetStaffByIdQuery.cs +++ b/src/Application/Staffs/Queries/GetStaffById/GetStaffByIdQuery.cs @@ -1,7 +1,7 @@ using Application.Users.Queries.Physical; using MediatR; -namespace Application.Staffs.Queries; +namespace Application.Staffs.Queries.GetStaffById; public record GetStaffByIdQuery : IRequest { From a379a92927a2338c9b4cd5e8a6871f4ba3590dcf Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:37:58 +0700 Subject: [PATCH 24/26] add: get staff by room query and endpoint --- src/Api/Controllers/FoldersController.cs | 1 - src/Api/Controllers/LockersController.cs | 1 - src/Api/Controllers/StaffsController.cs | 21 ++++++++++++++++++- .../GetStaffByRoom/GetStaffByRoomQuery.cs | 9 ++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/Application/Staffs/Queries/GetStaffByRoom/GetStaffByRoomQuery.cs diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index c597fcee..a79cab8f 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -25,7 +25,6 @@ public class FoldersController : ApiControllerBase [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(StatusCodes.Status409Conflict)] public async Task>> GetById([FromRoute] Guid folderId) { var query = new GetFolderByIdQuery() diff --git a/src/Api/Controllers/LockersController.cs b/src/Api/Controllers/LockersController.cs index 80e37551..93f7d0c8 100644 --- a/src/Api/Controllers/LockersController.cs +++ b/src/Api/Controllers/LockersController.cs @@ -26,7 +26,6 @@ public class LockersController : ApiControllerBase [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(StatusCodes.Status409Conflict)] public async Task>> GetById([FromRoute] Guid lockerId) { var query = new GetLockerByIdQuery() diff --git a/src/Api/Controllers/StaffsController.cs b/src/Api/Controllers/StaffsController.cs index b2ce8125..e0b49a02 100644 --- a/src/Api/Controllers/StaffsController.cs +++ b/src/Api/Controllers/StaffsController.cs @@ -6,6 +6,7 @@ using Application.Staffs.Queries; using Application.Staffs.Queries.GetAllStaffsPaginated; using Application.Staffs.Queries.GetStaffById; +using Application.Staffs.Queries.GetStaffByRoom; using Application.Users.Queries.Physical; using Infrastructure.Identity.Authorization; using Microsoft.AspNetCore.Mvc; @@ -23,7 +24,6 @@ public class StaffsController : ApiControllerBase [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(StatusCodes.Status409Conflict)] public async Task>> GetById([FromRoute] Guid staffId) { var query = new GetStaffByIdQuery() @@ -34,6 +34,25 @@ public async Task>> GetById([FromRoute] Guid staff return Ok(Result.Succeed(result)); } + /// + /// Get a staff by room + /// + /// Id of the room to retrieve staff + /// A StaffDto of the retrieved staff + [HttpGet("get-by-room/{roomId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> GetByRoom([FromRoute] Guid roomId) + { + var query = new GetStaffByRoomQuery() + { + RoomId = roomId + }; + var result = await Mediator.Send(query); + return Ok(Result.Succeed(result)); + } + /// /// Get all staffs paginated /// diff --git a/src/Application/Staffs/Queries/GetStaffByRoom/GetStaffByRoomQuery.cs b/src/Application/Staffs/Queries/GetStaffByRoom/GetStaffByRoomQuery.cs new file mode 100644 index 00000000..0d3d8a1f --- /dev/null +++ b/src/Application/Staffs/Queries/GetStaffByRoom/GetStaffByRoomQuery.cs @@ -0,0 +1,9 @@ +using Application.Users.Queries.Physical; +using MediatR; + +namespace Application.Staffs.Queries.GetStaffByRoom; + +public record GetStaffByRoomQuery : IRequest +{ + public Guid RoomId { get; init; } +} \ No newline at end of file From 5f9bfa1eea106a727b7f546b30b04b6703327fa2 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 19:58:22 +0700 Subject: [PATCH 25/26] chore: merge from dev --- src/Api/Controllers/DepartmentsController.cs | 2 ++ src/Api/Controllers/DocumentsController.cs | 1 + src/Api/Controllers/FoldersController.cs | 16 +++++++--- src/Api/Controllers/UsersController.cs | 30 +++++++++---------- .../UpdateDocument/UpdateDocumentCommand.cs | 2 +- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/Api/Controllers/DepartmentsController.cs b/src/Api/Controllers/DepartmentsController.cs index 5a8ae2d1..98045cf7 100644 --- a/src/Api/Controllers/DepartmentsController.cs +++ b/src/Api/Controllers/DepartmentsController.cs @@ -67,6 +67,7 @@ public async Task>> GetDepartmentById([FromRo /// Id of the department to be updated /// Update department details /// A DepartmentDto of the updated department + [RequiresRole(IdentityData.Roles.Admin)] [HttpPut("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -87,6 +88,7 @@ public async Task>> UpdateDepartment([FromRou /// /// Id of the department to be deleted /// A DepartmentDto of the deleted department + [RequiresRole(IdentityData.Roles.Admin)] [HttpDelete("{departmentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/src/Api/Controllers/DocumentsController.cs b/src/Api/Controllers/DocumentsController.cs index 20abf951..41f8fb3d 100644 --- a/src/Api/Controllers/DocumentsController.cs +++ b/src/Api/Controllers/DocumentsController.cs @@ -80,6 +80,7 @@ public async Task>> GetDocumentById(Guid id) /// Id of the document to be updated /// Update document details /// A DocumentDto of the updated document + [RequiresRole(IdentityData.Roles.Admin)] [HttpPut("{documentId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/src/Api/Controllers/FoldersController.cs b/src/Api/Controllers/FoldersController.cs index 3d23b1a3..8ea03dd6 100644 --- a/src/Api/Controllers/FoldersController.cs +++ b/src/Api/Controllers/FoldersController.cs @@ -21,6 +21,7 @@ public class FoldersController : ApiControllerBase /// /// Id of the folder to be retrieved /// A FolderDto of the retrieved folder + [RequiresRole(IdentityData.Roles.Admin, IdentityData.Roles.Staff)] [HttpGet("{folderId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -40,6 +41,7 @@ public async Task>> GetById([FromRoute] Guid fold /// /// Get all folders query parameters /// A paginated list of FolderDto + [RequiresRole(IdentityData.Roles.Admin, IdentityData.Roles.Staff)] [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -64,7 +66,7 @@ public async Task>>> GetAllPaginate /// /// Add folder details /// A FolderDto of the added folder - [RequiresRole(IdentityData.Roles.Admin, IdentityData.Roles.Staff)] + [RequiresRole(IdentityData.Roles.Admin)] [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] @@ -80,16 +82,21 @@ public async Task>> AddFolder([FromBody] AddFolde /// /// Remove a folder /// - /// Remove folder details + /// Id of the folder to be removed /// A FolderDto of the removed folder - [HttpPut("disable")] + [RequiresRole(IdentityData.Roles.Admin)] + [HttpDelete("{folderId:guid}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status409Conflict)] - public async Task>> RemoveFolder([FromBody] RemoveFolderCommand command) + public async Task>> RemoveFolder([FromRoute] Guid folderId) { + var command = new RemoveFolderCommand() + { + FolderId = folderId, + }; var result = await Mediator.Send(command); return Ok(Result.Succeed(result)); } @@ -99,6 +106,7 @@ public async Task>> RemoveFolder([FromBody] Remov /// /// Enable folder details /// A FolderDto of the enabled folder + [RequiresRole(IdentityData.Roles.Admin, IdentityData.Roles.Staff)] [HttpPut("enable")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] diff --git a/src/Api/Controllers/UsersController.cs b/src/Api/Controllers/UsersController.cs index 40006221..87e13042 100644 --- a/src/Api/Controllers/UsersController.cs +++ b/src/Api/Controllers/UsersController.cs @@ -73,21 +73,21 @@ public async Task>> AddUser([FromBody] AddUserComma return Ok(Result.Succeed(result)); } - [RequiresRole(IdentityData.Roles.Admin)] - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - public async Task>>> GetUsersByName(string? searchTerm, int? page, int? size) - { - var query = new GetUsersByNameQuery - { - SearchTerm = searchTerm, - Page = page, - Size = size - }; - var result = await Mediator.Send(query); - return Ok(Result>.Succeed(result)); - } + // [RequiresRole(IdentityData.Roles.Admin)] + // [HttpGet] + // [ProducesResponseType(StatusCodes.Status200OK)] + // [ProducesResponseType(StatusCodes.Status403Forbidden)] + // public async Task>>> GetUsersByName(string? searchTerm, int? page, int? size) + // { + // var query = new GetUsersByNameQuery + // { + // SearchTerm = searchTerm, + // Page = page, + // Size = size + // }; + // var result = await Mediator.Send(query); + // return Ok(Result>.Succeed(result)); + // } [RequiresRole(IdentityData.Roles.Admin)] [HttpPost("disable")] diff --git a/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs b/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs index eb315e59..d7b06736 100644 --- a/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs +++ b/src/Application/Documents/Commands/UpdateDocument/UpdateDocumentCommand.cs @@ -7,6 +7,6 @@ public record UpdateDocumentCommand : IRequest { public Guid DocumentId { get; init; } public string Title { get; init; } = null!; - public string Description { get; init; } = null!; + public string? Description { get; init; } public string DocumentType { get; init; } = null!; } \ No newline at end of file From 77db38c41ec5cb2fdc90ff358c2d0bc46d9e092c Mon Sep 17 00:00:00 2001 From: Nguyen Quang Chien Date: Sat, 27 May 2023 20:01:01 +0700 Subject: [PATCH 26/26] add: enable user command and endpoint --- src/Api/Controllers/UsersController.cs | 21 +++++++++++++++++++ .../Commands/EnableUser/EnableUserCommand.cs | 9 ++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/Application/Users/Commands/EnableUser/EnableUserCommand.cs diff --git a/src/Api/Controllers/UsersController.cs b/src/Api/Controllers/UsersController.cs index 87e13042..f7d93173 100644 --- a/src/Api/Controllers/UsersController.cs +++ b/src/Api/Controllers/UsersController.cs @@ -4,6 +4,7 @@ using Application.Identity; using Application.Users.Commands.AddUser; using Application.Users.Commands.DisableUser; +using Application.Users.Commands.EnableUser; using Application.Users.Commands.UpdateUser; using Application.Users.Queries; using Application.Users.Queries.GetAllUsersPaginated; @@ -88,6 +89,26 @@ public async Task>> AddUser([FromBody] AddUserComma // var result = await Mediator.Send(query); // return Ok(Result>.Succeed(result)); // } + + /// + /// Disable a user + /// + /// Id of the user to be enabled + /// A UserDto of the enabled user + [RequiresRole(IdentityData.Roles.Admin)] + [HttpPost("enable/{userId:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task>> EnableUser([FromRoute] Guid userId) + { + var command = new EnableUserCommand() + { + UserId = userId + }; + var result = await Mediator.Send(command); + return Ok(Result.Succeed(result)); + } [RequiresRole(IdentityData.Roles.Admin)] [HttpPost("disable")] diff --git a/src/Application/Users/Commands/EnableUser/EnableUserCommand.cs b/src/Application/Users/Commands/EnableUser/EnableUserCommand.cs new file mode 100644 index 00000000..047f13d5 --- /dev/null +++ b/src/Application/Users/Commands/EnableUser/EnableUserCommand.cs @@ -0,0 +1,9 @@ +using Application.Users.Queries; +using MediatR; + +namespace Application.Users.Commands.EnableUser; + +public record EnableUserCommand : IRequest +{ + public Guid UserId { get; init; } +} \ No newline at end of file