-
Notifications
You must be signed in to change notification settings - Fork 24
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
PSP-8316 | Lease consultation updates #4281
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1643178
Added view and containers on the frontend for consultations. Updated …
FuriousLlama 9b375ed
Cleanup
FuriousLlama cbbbe9e
Regenerated snaps
FuriousLlama 7a2c7b0
Merge branch 'dev' into features/psp-8316
FuriousLlama 6ea47cc
Merge branch 'features/psp-8316' of https://github.com/FuriousLlama/P…
FuriousLlama df3bff5
Merge branch 'dev' into features/psp-8316
FuriousLlama 1bacd6f
Improvements
FuriousLlama c7f705f
Merge branch 'features/psp-8316' of https://github.com/FuriousLlama/P…
FuriousLlama bd94ed3
Merge branch 'dev' into features/psp-8316
FuriousLlama 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
199 changes: 199 additions & 0 deletions
199
source/backend/api/Areas/Leases/Controllers/ConsultationController.cs
This file contains 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,199 @@ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using MapsterMapper; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Pims.Api.Helpers.Exceptions; | ||
using Pims.Api.Models.Concepts.Lease; | ||
using Pims.Api.Policies; | ||
using Pims.Api.Services; | ||
using Pims.Core.Extensions; | ||
using Pims.Core.Json; | ||
using Pims.Dal.Security; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace Pims.Api.Areas.Lease.Controllers | ||
{ | ||
/// <summary> | ||
/// ConsultationController class, provides endpoints for interacting with lease files consultation. | ||
/// </summary> | ||
[Authorize] | ||
[ApiController] | ||
[ApiVersion("1.0")] | ||
[Area("leases")] | ||
[Route("v{version:apiVersion}/[area]")] | ||
[Route("[area]")] | ||
public class ConsultationController : ControllerBase | ||
{ | ||
#region Variables | ||
private readonly ILeaseService _leaseService; | ||
private readonly IMapper _mapper; | ||
private readonly ILogger _logger; | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
/// <summary> | ||
/// Creates a new instance of a ConsultationController class, initializes it with the specified arguments. | ||
/// </summary> | ||
/// <param name="leaseService"></param> | ||
/// <param name="mapper"></param> | ||
/// <param name="logger"></param> | ||
public ConsultationController(ILeaseService leaseService, IMapper mapper, ILogger<ConsultationController> logger) | ||
{ | ||
_leaseService = leaseService; | ||
_mapper = mapper; | ||
_logger = logger; | ||
} | ||
#endregion | ||
|
||
#region Endpoints | ||
|
||
/// <summary> | ||
/// Get the lease file consultation. | ||
/// </summary> | ||
/// <returns>The consultation items.</returns> | ||
[HttpGet("{id:long}/consultations")] | ||
[HasPermission(Permissions.LeaseView)] | ||
[Produces("application/json")] | ||
[ProducesResponseType(typeof(IEnumerable<ConsultationLeaseModel>), 200)] | ||
[SwaggerOperation(Tags = new[] { "leasefile" })] | ||
public IActionResult GetLeaseConsultations([FromRoute] long id) | ||
{ | ||
_logger.LogInformation( | ||
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}", | ||
nameof(ConsultationController), | ||
nameof(GetLeaseConsultations), | ||
User.GetUsername(), | ||
DateTime.Now); | ||
|
||
|
||
var consultation = _leaseService.GetConsultations(id); | ||
return new JsonResult(_mapper.Map<IEnumerable<ConsultationLeaseModel>>(consultation)); | ||
} | ||
|
||
/// <summary> | ||
/// Create the lease file consultation to the lease file. | ||
/// </summary> | ||
/// <returns>The consultation items.</returns> | ||
[HttpPost("{leaseId:long}/consultations")] | ||
[HasPermission(Permissions.LeaseEdit)] | ||
[Produces("application/json")] | ||
[ProducesResponseType(typeof(ConsultationLeaseModel), 201)] | ||
[TypeFilter(typeof(NullJsonResultFilter))] | ||
[SwaggerOperation(Tags = new[] { "leasefile" })] | ||
public IActionResult AddLeaseConsultation([FromRoute] long leaseId, [FromBody] ConsultationLeaseModel consultation) | ||
{ | ||
_logger.LogInformation( | ||
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}", | ||
nameof(ConsultationController), | ||
nameof(AddLeaseConsultation), | ||
User.GetUsername(), | ||
DateTime.Now); | ||
|
||
if (leaseId != consultation.LeaseId) | ||
{ | ||
throw new BadRequestException("Invalid LeaseId."); | ||
} | ||
|
||
var newConsultation = _leaseService.AddConsultation(_mapper.Map<Dal.Entities.PimsLeaseConsultation>(consultation)); | ||
|
||
return new JsonResult(_mapper.Map<ConsultationLeaseModel>(newConsultation)); | ||
} | ||
|
||
/// <summary> | ||
/// Get the lease file consultation by Id. | ||
/// </summary> | ||
/// <returns>The consultation items.</returns> | ||
[HttpGet("{leaseId:long}/consultations/{consultationId:long}")] | ||
[HasPermission(Permissions.LeaseView)] | ||
[Produces("application/json")] | ||
[ProducesResponseType(typeof(ConsultationLeaseModel), 200)] | ||
[SwaggerOperation(Tags = new[] { "leasefile" })] | ||
public IActionResult GetLeaseConsultationById([FromRoute] long leaseId, [FromRoute] long consultationId) | ||
{ | ||
_logger.LogInformation( | ||
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}", | ||
nameof(ConsultationController), | ||
nameof(GetLeaseConsultationById), | ||
User.GetUsername(), | ||
DateTime.Now); | ||
|
||
var consultation = _leaseService.GetConsultationById(consultationId); | ||
|
||
if (consultation.LeaseConsultationId != leaseId) | ||
{ | ||
throw new BadRequestException("Invalid lease id for the given consultation."); | ||
} | ||
|
||
return new JsonResult(_mapper.Map<ConsultationLeaseModel>(consultation)); | ||
} | ||
|
||
/// <summary> | ||
/// Update the lease file consultation by Id. | ||
/// </summary> | ||
/// <returns>The consultation item updated.</returns> | ||
[HttpPut("{id:long}/consultations/{consultationId:long}")] | ||
[HasPermission(Permissions.LeaseEdit)] | ||
[Produces("application/json")] | ||
[ProducesResponseType(typeof(ConsultationLeaseModel), 200)] | ||
[TypeFilter(typeof(NullJsonResultFilter))] | ||
[SwaggerOperation(Tags = new[] { "leasefile" })] | ||
public IActionResult UpdateLeaseConsultation([FromRoute] long id, [FromRoute] long consultationId, [FromBody] ConsultationLeaseModel consultation) | ||
{ | ||
_logger.LogInformation( | ||
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}", | ||
nameof(ConsultationController), | ||
nameof(UpdateLeaseConsultation), | ||
User.GetUsername(), | ||
DateTime.Now); | ||
|
||
if (id != consultation.LeaseId) | ||
{ | ||
throw new BadRequestException("Invalid LeaseId."); | ||
} | ||
if (consultationId != consultation.Id) | ||
{ | ||
throw new BadRequestException("Invalid consultationId."); | ||
} | ||
|
||
var updatedConsultation = _leaseService.UpdateConsultation(_mapper.Map<Dal.Entities.PimsLeaseConsultation>(consultation)); | ||
|
||
return new JsonResult(_mapper.Map<ConsultationLeaseModel>(updatedConsultation)); | ||
} | ||
|
||
/// <summary> | ||
/// Delete the lease file consultation by Id. | ||
/// </summary> | ||
/// <returns>The consultation item updated.</returns> | ||
[HttpDelete("{leaseId:long}/consultations/{consultationId:long}")] | ||
[HasPermission(Permissions.LeaseEdit)] | ||
[Produces("application/json")] | ||
[ProducesResponseType(typeof(bool), 200)] | ||
[SwaggerOperation(Tags = new[] { "leasefile" })] | ||
public IActionResult DeleteLeaseConsultation([FromRoute] long leaseId, [FromRoute] long consultationId) | ||
{ | ||
_logger.LogInformation( | ||
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}", | ||
nameof(ConsultationController), | ||
nameof(DeleteLeaseConsultation), | ||
User.GetUsername(), | ||
DateTime.Now); | ||
|
||
var existingConsultation = _leaseService.GetConsultationById(consultationId); | ||
if (existingConsultation.LeaseConsultationId != leaseId) | ||
{ | ||
throw new BadRequestException("Invalid lease id for the given consultation."); | ||
} | ||
|
||
var result = _leaseService.DeleteConsultation(consultationId); | ||
|
||
return new JsonResult(result); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains 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 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
2 changes: 0 additions & 2 deletions
2
source/backend/apimodels/Models/Concepts/Deposit/SecurityDepositMap.cs
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using Mapster; | ||
using Pims.Api.Models.Base; | ||
using Pims.Core.Extensions; | ||
using Pims.Dal.Entities; | ||
|
||
namespace Pims.Api.Models.Concepts.Lease | ||
|
@@ -10,18 +11,38 @@ public void Register(TypeAdapterConfig config) | |
{ | ||
config.NewConfig<PimsLeaseConsultation, ConsultationLeaseModel>() | ||
.Map(dest => dest.Id, src => src.LeaseConsultationId) | ||
.Map(dest => dest.ConsultationType, src => src.ConsultationTypeCodeNavigation) | ||
.Map(dest => dest.ConsultationStatusType, src => src.ConsultationStatusTypeCodeNavigation) | ||
.Map(dest => dest.ParentLeaseId, src => src.LeaseId) | ||
.Map(dest => dest.LeaseId, src => src.LeaseId) | ||
.Map(dest => dest.Lease, src => src.Lease) | ||
.Map(dest => dest.PersonId, src => src.PersonId) | ||
.Map(dest => dest.Person, src => src.Person) | ||
.Map(dest => dest.OrganizationId, src => src.OrganizationId) | ||
.Map(dest => dest.Organization, src => src.Organization) | ||
.Map(dest => dest.PrimaryContactId, src => src.PrimaryContactId) | ||
.Map(dest => dest.PrimaryContact, src => src.PrimaryContact) | ||
.Map(dest => dest.ConsultationTypeCode, src => src.ConsultationTypeCodeNavigation) | ||
.Map(dest => dest.ConsultationStatusTypeCode, src => src.ConsultationStatusTypeCodeNavigation) | ||
.Map(dest => dest.OtherDescription, src => src.OtherDescription) | ||
.Map(dest => dest.RequestedOn, src => src.RequestedOn.ToNullableDateOnly()) | ||
.Map(dest => dest.IsResponseReceived, src => src.IsResponseReceived) | ||
.Map(dest => dest.ResponseReceivedDate, src => src.ResponseReceivedDate.ToNullableDateOnly()) | ||
.Map(dest => dest.Comment, src => src.Comment) | ||
.Inherits<IBaseAppEntity, BaseAuditModel>(); | ||
|
||
config.NewConfig<ConsultationLeaseModel, PimsLeaseConsultation>() | ||
.Map(dest => dest.LeaseConsultationId, src => src.Id) | ||
.Map(dest => dest.LeaseId, src => src.ParentLeaseId) | ||
.Map(dest => dest.ConsultationTypeCode, src => src.ConsultationType.Id) | ||
.Map(dest => dest.ConsultationStatusTypeCode, src => src.ConsultationStatusType.Id) | ||
.Map(dest => dest.LeaseId, src => src.LeaseId) | ||
.Map(dest => dest.PersonId, src => src.PersonId) | ||
.Map(dest => dest.OrganizationId, src => src.OrganizationId) | ||
.Map(dest => dest.Organization, src => src.Organization) | ||
.Map(dest => dest.PrimaryContactId, src => src.PrimaryContactId) | ||
.Map(dest => dest.PrimaryContact, src => src.PrimaryContact) | ||
.Map(dest => dest.ConsultationTypeCode, src => src.ConsultationTypeCode.Id) | ||
.Map(dest => dest.ConsultationStatusTypeCode, src => src.ConsultationStatusTypeCode.Id) | ||
.Map(dest => dest.OtherDescription, src => src.OtherDescription) | ||
.Map(dest => dest.RequestedOn, src => src.RequestedOn.ToNullableDateTime()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a DateOnly or a DateTime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its a datetime, however we only need dates, that's wh y the model changes it |
||
.Map(dest => dest.IsResponseReceived, src => src.IsResponseReceived) | ||
.Map(dest => dest.ResponseReceivedDate, src => src.ResponseReceivedDate.ToNullableDateTime()) | ||
.Map(dest => dest.Comment, src => src.Comment) | ||
.Inherits<BaseAuditModel, IBaseAppEntity>(); | ||
} | ||
} | ||
|
Oops, something went wrong.
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.
not sure if it matters, but:
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.
Good point, I have added validation to all the routes