-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/borrow #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/borrow #159
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
470f603
add: base
ChienNQuang 96b0679
add: request borrow
ChienNQuang 0ff5cc9
add: a couple more things
ChienNQuang c8b5236
Merge branch 'dev' into feat/borrow
ChienNQuang cc9519f
add: base for borrow
ChienNQuang db9a796
Merge branch 'dev' into feat/borrow
ChienNQuang b2510d2
update: divide get all borrow requests as admin and staff
ChienNQuang 46b6b85
just update my progress here
ChienNQuang 6b6c381
update once more?
ChienNQuang d629e33
add: base ground for borrow endpoints
ChienNQuang 5d59bbf
add: validation and fix simple logic in borrowing document
ChienNQuang abca5b3
refactor: a bit
ChienNQuang ccd42b7
final touch
ChienNQuang e937a56
fix my wholie life
ChienNQuang 7f909c0
jk im good
ChienNQuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| using Api.Controllers.Payload.Requests.Borrows; | ||
| using Application.Borrows.Commands; | ||
| using Application.Borrows.Queries; | ||
| using Application.Common.Interfaces; | ||
| using Application.Common.Models; | ||
| using Application.Common.Models.Dtos.Physical; | ||
| using Application.Identity; | ||
| using Infrastructure.Identity.Authorization; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace Api.Controllers; | ||
|
|
||
| public class BorrowsController : ApiControllerBase | ||
| { | ||
| private readonly ICurrentUserService _currentUserService; | ||
| public BorrowsController(ICurrentUserService currentUserService) | ||
| { | ||
| _currentUserService = currentUserService; | ||
| } | ||
| /// <summary> | ||
| /// Borrow a document request | ||
| /// </summary> | ||
| /// <param name="request">Borrow document details</param> | ||
| /// <returns>A BorrowDto of the requested borrow</returns> | ||
| [RequiresRole(IdentityData.Roles.Employee)] | ||
| [HttpPost] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<BorrowDto>>> BorrowDocument([FromBody] BorrowDocumentRequest request) | ||
| { | ||
| var borrowerId = _currentUserService.GetCurrentUser().Id; | ||
| var command = new BorrowDocument.Command() | ||
| { | ||
| BorrowerId = borrowerId, | ||
| DocumentId = request.DocumentId, | ||
| BorrowFrom = request.BorrowFrom, | ||
| BorrowTo = request.BorrowTo, | ||
| Reason = request.Reason, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<BorrowDto>.Succeed(result)); | ||
| } | ||
|
|
||
| [RequiresRole(IdentityData.Roles.Staff)] | ||
| [HttpGet("staffs")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<PaginatedList<BorrowDto>>>> GetAllRequestsAsStaffPaginated( | ||
| [FromQuery] GetAllBorrowRequestsPaginatedAsStaffQueryParameters queryParameters) | ||
| { | ||
| var departmentId = _currentUserService.GetCurrentDepartmentForStaff(); | ||
| var command = new GetAllBorrowRequestsPaginated.Query() | ||
| { | ||
| DepartmentId = departmentId, | ||
| EmployeeId = queryParameters.EmployeeId, | ||
| DocumentId = queryParameters.DocumentId, | ||
| Page = queryParameters.Page, | ||
| Size = queryParameters.Size, | ||
| SortBy = queryParameters.SortBy, | ||
| SortOrder = queryParameters.SortOrder, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<PaginatedList<BorrowDto>>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get all borrow requests as admin paginated | ||
| /// </summary> | ||
| /// <param name="queryParameters"></param> | ||
| /// <returns></returns> | ||
| [RequiresRole(IdentityData.Roles.Admin)] | ||
| [HttpGet] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<PaginatedList<BorrowDto>>>> GetAllRequestsAsAdminPaginated( | ||
| [FromQuery] GetAllBorrowRequestsPaginatedAsAdminQueryParameters queryParameters) | ||
| { | ||
| var command = new GetAllBorrowRequestsPaginated.Query() | ||
| { | ||
| DepartmentId = queryParameters.DepartmentId, | ||
| EmployeeId = queryParameters.EmployeeId, | ||
| DocumentId = queryParameters.DocumentId, | ||
| Page = queryParameters.Page, | ||
| Size = queryParameters.Size, | ||
| SortBy = queryParameters.SortBy, | ||
| SortOrder = queryParameters.SortOrder, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<PaginatedList<BorrowDto>>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get all borrow requests as employee paginated | ||
| /// </summary> | ||
| /// <param name="queryParameters"></param> | ||
| /// <returns></returns> | ||
| [RequiresRole(IdentityData.Roles.Employee)] | ||
| [HttpGet("employees")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<PaginatedList<BorrowDto>>>> GetAllRequestsAsEmployeePaginated( | ||
| [FromQuery] GetAllBorrowRequestsPaginatedAsEmployeeQueryParameters queryParameters) | ||
| { | ||
| var userId = _currentUserService.GetCurrentUser().Id; | ||
| var command = new GetAllBorrowRequestsPaginated.Query() | ||
| { | ||
| EmployeeId = userId, | ||
| DocumentId = queryParameters.DocumentId, | ||
| Page = queryParameters.Page, | ||
| Size = queryParameters.Size, | ||
| SortBy = queryParameters.SortBy, | ||
| SortOrder = queryParameters.SortOrder, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<PaginatedList<BorrowDto>>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get all borrow requests for a document paginated | ||
| /// </summary> | ||
| /// <param name="documentId"></param> | ||
| /// <param name="queryParameters"></param> | ||
| /// <returns></returns> | ||
| [RequiresRole(IdentityData.Roles.Employee)] | ||
| [HttpGet("documents/{documentId:guid}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<PaginatedList<BorrowDto>>>> GetAllRequestsForDocumentPaginated( | ||
| [FromRoute] Guid documentId, | ||
| [FromQuery] GetAllBorrowRequestsPaginatedForDocumentQueryParameters queryParameters) | ||
| { | ||
| var command = new GetAllBorrowRequestsPaginated.Query() | ||
| { | ||
| DocumentId = documentId, | ||
| Page = queryParameters.Page, | ||
| Size = queryParameters.Size, | ||
| SortBy = queryParameters.SortBy, | ||
| SortOrder = queryParameters.SortOrder, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<PaginatedList<BorrowDto>>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Approve a borrow request | ||
| /// </summary> | ||
| /// <param name="borrowId">Id of the borrow request to be approved</param> | ||
| /// <returns>A BorrowDto of the approved borrow request</returns> | ||
| [RequiresRole(IdentityData.Roles.Staff)] | ||
| [HttpPost("approve/{borrowId:guid}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<BorrowDto>>> ApproveRequest([FromRoute] Guid borrowId) | ||
| { | ||
| var command = new ApproveBorrowRequest.Command() | ||
| { | ||
| BorrowId = borrowId, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<BorrowDto>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Reject a borrow request | ||
| /// </summary> | ||
| /// <param name="borrowId">Id of the borrow request to be rejected</param> | ||
| /// <returns>A BorrowDto of the rejected borrow request</returns> | ||
| [RequiresRole(IdentityData.Roles.Staff)] | ||
| [HttpPost("reject/{borrowId:guid}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<BorrowDto>>> RejectRequest([FromRoute] Guid borrowId) | ||
| { | ||
| var command = new RejectBorrowRequest.Command() | ||
| { | ||
| BorrowId = borrowId, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<BorrowDto>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Check out a borrow request | ||
| /// </summary> | ||
| /// <param name="borrowId">Id of the borrow request to be checked out</param> | ||
| /// <returns>A BorrowDto of the checked out borrow request</returns> | ||
| [RequiresRole(IdentityData.Roles.Staff)] | ||
| [HttpPost("checkout/{borrowId:guid}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<BorrowDto>>> Checkout([FromRoute] Guid borrowId) | ||
| { | ||
| var command = new CheckoutDocument.Command() | ||
| { | ||
| BorrowId = borrowId, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<BorrowDto>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Return document | ||
| /// </summary> | ||
| /// <param name="documentId">Id of the document to be returned</param> | ||
| /// <returns>A BorrowDto of the returned document borrow request</returns> | ||
| [RequiresRole(IdentityData.Roles.Staff)] | ||
| [HttpPost("return/{documentId:guid}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<BorrowDto>>> Return([FromRoute] Guid documentId) | ||
| { | ||
| var command = new ReturnDocument.Command() | ||
| { | ||
| DocumentId = documentId, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<BorrowDto>.Succeed(result)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Update borrow request | ||
| /// </summary> | ||
| /// <param name="borrowId">Id of the borrow request to be updated</param> | ||
| /// <param name="request">Update borrow details</param> | ||
| /// <returns>A BorrowDto of the updated borrow request</returns> | ||
| [RequiresRole(IdentityData.Roles.Employee)] | ||
| [HttpPut("{borrowId:guid}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(StatusCodes.Status409Conflict)] | ||
| public async Task<ActionResult<Result<BorrowDto>>> Update( | ||
| [FromRoute] Guid borrowId, | ||
| [FromBody] UpdateBorrowRequest request) | ||
| { | ||
| var command = new UpdateBorrow.Command() | ||
| { | ||
| BorrowId = borrowId, | ||
| BorrowFrom = request.BorrowFrom, | ||
| BorrowTo = request.BorrowTo, | ||
| Reason = request.Reason, | ||
| }; | ||
| var result = await Mediator.Send(command); | ||
| return Ok(Result<BorrowDto>.Succeed(result)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Api/Controllers/Payload/Requests/Borrows/BorrowDocumentRequest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| namespace Api.Controllers.Payload.Requests.Borrows; | ||
|
|
||
| /// <summary> | ||
| /// Request details to borrow a document | ||
| /// </summary> | ||
| public class BorrowDocumentRequest | ||
| { | ||
| /// <summary> | ||
| /// Id of the document to be borrowed | ||
| /// </summary> | ||
| public Guid DocumentId { get; set; } | ||
| /// <summary> | ||
| /// Borrow from | ||
| /// </summary> | ||
| public DateTime BorrowFrom { get; set; } | ||
| /// <summary> | ||
| /// Borrow to | ||
| /// </summary> | ||
| public DateTime BorrowTo { get; set; } | ||
| /// <summary> | ||
| /// Reason of borrowing | ||
| /// </summary> | ||
| public string Reason { get; set; } = null!; | ||
| } |
14 changes: 14 additions & 0 deletions
14
...ntrollers/Payload/Requests/Borrows/GetAllBorrowRequestsPaginatedAsAdminQueryParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace Api.Controllers.Payload.Requests.Borrows; | ||
|
|
||
| /// <summary> | ||
| /// Query parameters for getting all borrow requests with pagination as admin | ||
| /// </summary> | ||
| public class GetAllBorrowRequestsPaginatedAsAdminQueryParameters : PaginatedQueryParameters | ||
| { | ||
| /// <summary> | ||
| /// Id of the department to get borrow requests in | ||
| /// </summary> | ||
| public Guid? DepartmentId { get; set; } | ||
| public Guid? DocumentId { get; set; } | ||
| public Guid? EmployeeId { get; set; } | ||
| } |
9 changes: 9 additions & 0 deletions
9
...ollers/Payload/Requests/Borrows/GetAllBorrowRequestsPaginatedAsEmployeeQueryParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace Api.Controllers.Payload.Requests.Borrows; | ||
|
|
||
| /// <summary> | ||
| /// Query parameters for getting all borrow requests with pagination as employee | ||
| /// </summary> | ||
| public class GetAllBorrowRequestsPaginatedAsEmployeeQueryParameters : PaginatedQueryParameters | ||
| { | ||
| public Guid? DocumentId { get; set; } | ||
| } |
10 changes: 10 additions & 0 deletions
10
...ntrollers/Payload/Requests/Borrows/GetAllBorrowRequestsPaginatedAsStaffQueryParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace Api.Controllers.Payload.Requests.Borrows; | ||
|
|
||
| /// <summary> | ||
| /// Query parameters for getting all borrow requests with pagination as staff | ||
| /// </summary> | ||
| public class GetAllBorrowRequestsPaginatedAsStaffQueryParameters : PaginatedQueryParameters | ||
| { | ||
| public Guid? DocumentId { get; set; } | ||
| public Guid? EmployeeId { get; set; } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...llers/Payload/Requests/Borrows/GetAllBorrowRequestsPaginatedForDocumentQueryParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Api.Controllers.Payload.Requests.Borrows; | ||
|
|
||
| public class GetAllBorrowRequestsPaginatedForDocumentQueryParameters : PaginatedQueryParameters | ||
| { | ||
|
|
||
| } |
8 changes: 8 additions & 0 deletions
8
src/Api/Controllers/Payload/Requests/Borrows/UpdateBorrowRequest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| namespace Api.Controllers.Payload.Requests.Borrows; | ||
|
|
||
| public class UpdateBorrowRequest | ||
| { | ||
| public DateTime BorrowFrom { get; init; } | ||
| public DateTime BorrowTo { get; init; } | ||
| public string Reason { get; init; } = null!; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test error message should be clearer