Skip to content
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-5718 : Add view update remove form 8 expropriation #3402

Merged
merged 20 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Pims.Api.Areas.CompensationRequisition.Controllers;
using Pims.Api.Models;
using Pims.Api.Models.Concepts;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Exceptions;
using Pims.Core.Extensions;
using Pims.Core.Json;
using Pims.Dal.Entities;
using Pims.Dal.Exceptions;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;
Expand Down Expand Up @@ -240,7 +240,7 @@
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(CompensationRequisitionController),
nameof(AcquisitionFileController),

Check warning on line 243 in source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs#L243

Added line #L243 was not covered by tests
nameof(AddCompensationRequisition),
User.GetUsername(),
DateTime.Now);
Expand All @@ -252,6 +252,60 @@
return new JsonResult(_mapper.Map<CompensationRequisitionModel>(newCompensationRequisition));
}

/// <summary>
/// Get all Expropriation Payments from the Acquisition File.
/// </summary>
/// <param name="id">Acquisition File Id.</param>
/// <returns>List of all Expropriation Payments created for the acquisition file.</returns>
[HttpGet("{id:long}/expropriation-payments")]
[HasPermission(Permissions.AcquisitionFileView)]
[Produces("application/json")]
[ProducesResponseType(typeof(List<ExpropriationPaymentModel>), 200)]
[SwaggerOperation(Tags = new[] { "expropriation-payments" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult GetAcquisitionFileExpropriationPayments([FromRoute] long id)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(AcquisitionFileController),
nameof(GetAcquisitionFileExpropriationPayments),
User.GetUsername(),
DateTime.Now);
_logger.LogInformation($"Dispatching to service: {_acquisitionService.GetType()}");

Check warning on line 274 in source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs#L267-L274

Added lines #L267 - L274 were not covered by tests

var pimsForm8s = _acquisitionService.GetAcquisitionExpropriationPayments(id);
var form8s = _mapper.Map<List<ExpropriationPaymentModel>>(pimsForm8s);

Check warning on line 277 in source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs#L276-L277

Added lines #L276 - L277 were not covered by tests

return new JsonResult(form8s);
}

Check warning on line 280 in source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs#L279-L280

Added lines #L279 - L280 were not covered by tests

/// <summary>
/// Creates a new Form8 for the acquisition file.
/// </summary>
/// <param name="id">Acquisition File Id.</param>
/// <param name="expropriationPayment">Form8 Data Model.</param>
/// <returns></returns>
[HttpPost("{id:long}/expropriation-payments")]
[HasPermission(Permissions.AcquisitionFileEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(ExpropriationPaymentModel), 201)]
[SwaggerOperation(Tags = new[] { "expropriation-payments" })]
public IActionResult AddExpropriationPayment([FromRoute] long id, [FromBody] ExpropriationPaymentModel expropriationPayment)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(AcquisitionFileController),
nameof(AddExpropriationPayment),
User.GetUsername(),
DateTime.Now);
_logger.LogInformation($"Dispatching to service: {_acquisitionService.GetType()}");

Check warning on line 301 in source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs#L294-L301

Added lines #L294 - L301 were not covered by tests

var expPaymentEntity = _mapper.Map<PimsExpropriationPayment>(expropriationPayment);
var newExpPaymentEntity = _acquisitionService.AddExpropriationPayment(id, expPaymentEntity);

Check warning on line 304 in source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs#L303-L304

Added lines #L303 - L304 were not covered by tests

return new JsonResult(_mapper.Map<ExpropriationPaymentModel>(newExpPaymentEntity));
}

Check warning on line 307 in source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/Acquisition/Controllers/AcquisitionFileController.cs#L306-L307

Added lines #L306 - L307 were not covered by tests

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Pims.Api.Helpers.Exceptions;
using Pims.Api.Models.Concepts;
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.ExpropriationPayment
{
/// <summary>
/// ExpropriationPaymentController class, provides endpoints to handle expropriation payments.
/// </summary>
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Area("expropriation-payments")]
[Route("v{version:apiVersion}/[area]")]
[Route("[area]")]
public class ExpropriationPaymentController : ControllerBase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This controller has the exact some name as the one above. Its a bit confusing, maybe the above one could be plural? or reference the acquisition file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed one controller

{
private readonly IMapper _mapper;
private readonly ILogger _logger;
private readonly IExpropriationPaymentService _expropriationPaymentService;

public ExpropriationPaymentController(IMapper mapper, ILogger<ExpropriationPaymentController> logger, IExpropriationPaymentService expropriationPaymentService)
{
_mapper = mapper;
_logger = logger;
_expropriationPaymentService = expropriationPaymentService;
}

Check warning on line 37 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L32-L37

Added lines #L32 - L37 were not covered by tests

/// <summary>
/// Get The Expropriation Payment (Form8) by Id.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id:long}")]
[HasPermission(Permissions.AcquisitionFileView)]
[Produces("application/json")]
[ProducesResponseType(typeof(ExpropriationPaymentModel), 200)]
[SwaggerOperation(Tags = new[] { "expropriation-payments" })]
public IActionResult GetExpropriationPaymentById([FromRoute] long id)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(ExpropriationPaymentController),
nameof(GetExpropriationPaymentById),
User.GetUsername(),
DateTime.Now);
_logger.LogInformation("Dispatching to service: {Service}", _expropriationPaymentService.GetType());

Check warning on line 57 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L50-L57

Added lines #L50 - L57 were not covered by tests

var expropriationPayment = _expropriationPaymentService.GetById(id);

Check warning on line 59 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L59

Added line #L59 was not covered by tests

return new JsonResult(_mapper.Map<ExpropriationPaymentModel>(expropriationPayment));
}

Check warning on line 62 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L61-L62

Added lines #L61 - L62 were not covered by tests

/// <summary>
/// Update the Expropriation Payment instance.
/// </summary>
/// <param name="id"></param>
/// <param name="expropriationPayment"></param>
/// <returns></returns>
/// <exception cref="BadRequestException">Validate id matching</exception>
[HttpPut("{id:long}")]
[HasPermission(Permissions.AcquisitionFileEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(ExpropriationPaymentModel), 200)]
[SwaggerOperation(Tags = new[] { "expropriation-payments" })]
public IActionResult UpdateExpropriationPayment([FromRoute] long id, [FromBody] ExpropriationPaymentModel expropriationPayment)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(ExpropriationPaymentController),
nameof(UpdateExpropriationPayment),
User.GetUsername(),
DateTime.Now);
_logger.LogInformation("Dispatching to service: {Service}", _expropriationPaymentService.GetType());

Check warning on line 84 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L77-L84

Added lines #L77 - L84 were not covered by tests

if (id != expropriationPayment.Id)
{
throw new BadRequestException("Invalid expropriationPaymentId.");

Check warning on line 88 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L87-L88

Added lines #L87 - L88 were not covered by tests
}

var expPaymentEntity = _mapper.Map<Dal.Entities.PimsExpropriationPayment>(expropriationPayment);
var compensation = _expropriationPaymentService.Update(expPaymentEntity);

Check warning on line 92 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L91-L92

Added lines #L91 - L92 were not covered by tests

return new JsonResult(_mapper.Map<ExpropriationPaymentModel>(compensation));
}

Check warning on line 95 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L94-L95

Added lines #L94 - L95 were not covered by tests

/// <summary>
/// Deletes the Expropriation Payment with the matching id.
/// </summary>
/// <param name="id">Used to identify the entity to delete.</param>
/// <returns></returns>
[HttpDelete("{id:long}")]
[Produces("application/json")]
[HasPermission(Permissions.AcquisitionFileEdit)]
[ProducesResponseType(typeof(bool), 200)]
[SwaggerOperation(Tags = new[] { "expropriation-payments" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult DeleteExpropriationPayment([FromRoute] long id)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(ExpropriationPaymentController),
nameof(DeleteExpropriationPayment),
User.GetUsername(),
DateTime.Now);
_logger.LogInformation($"Dispatching to service: {_expropriationPaymentService.GetType()}");

Check warning on line 116 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L109-L116

Added lines #L109 - L116 were not covered by tests

var result = _expropriationPaymentService.Delete(id);
return new JsonResult(result);
}

Check warning on line 120 in source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/api/Areas/ExpropriationPayment/ExpropriationPaymentController.cs#L118-L120

Added lines #L118 - L120 were not covered by tests
}
}
2 changes: 2 additions & 0 deletions source/backend/api/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public IActionResult GetAll()
var acqChecklistItemStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAcquisitionChecklistItemStatusTypes());
var agreementTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAgreementTypes());
var interestHolderInterestTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllInterestHolderInterestTypes());
var expropriationPaymentItemTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllExpropriationPaymentItemTypes());

var codes = new List<object>();
codes.AddRange(areaUnitTypes);
Expand Down Expand Up @@ -204,6 +205,7 @@ public IActionResult GetAll()
codes.AddRange(acqChecklistItemStatusTypes);
codes.AddRange(agreementTypes);
codes.AddRange(interestHolderInterestTypes);
codes.AddRange(expropriationPaymentItemTypes);

var response = new JsonResult(codes);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Mapster;
using Pims.Api.Models.Concepts.ExpropriationPayment;
using Pims.Dal.Entities;
using Entity = Pims.Dal.Entities;

namespace Pims.Api.Models.Concepts
{
public class ExpropriationPaymentItemMap : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<PimsExpropPmtPmtItem, ExpropriationPaymentItemModel>()
.Map(dest => dest.Id, src => src.Internal_Id)
.Map(dest => dest.ExpropriationPaymentId, src => src.ExpropriationPaymentId)
.Map(dest => dest.PaymentItemTypeCode, src => src.PaymentItemTypeCode)
.Map(dest => dest.PaymentItemType, src => src.PaymentItemTypeCodeNavigation)
.Map(dest => dest.IsGstRequired, src => src.IsGstRequired)
.Map(dest => dest.PretaxAmount, src => src.PretaxAmt)
.Map(dest => dest.TaxAmount, src => src.TaxAmt)
.Map(dest => dest.TotalAmount, src => src.TotalAmt)
.Map(dest => dest.IsDisabled, src => src.IsDisabled)
.Map(dest => dest.RowVersion, src => src.ConcurrencyControlNumber)
.Inherits<Entity.IBaseEntity, BaseModel>();

config.NewConfig<ExpropriationPaymentItemModel, PimsExpropPmtPmtItem>()
.Map(dest => dest.Internal_Id, src => src.Id)
.Map(dest => dest.ExpropriationPaymentId, src => src.ExpropriationPaymentId)
.Map(dest => dest.PaymentItemTypeCode, src => src.PaymentItemTypeCode)
.Map(dest => dest.IsGstRequired, src => src.IsGstRequired)
.Map(dest => dest.PretaxAmt, src => src.PretaxAmount)
.Map(dest => dest.TaxAmt, src => src.TaxAmount)
.Map(dest => dest.TotalAmt, src => src.TotalAmount)
.Map(dest => dest.IsDisabled, src => src.IsDisabled)
.Map(dest => dest.ConcurrencyControlNumber, src => src.RowVersion)
.Inherits<BaseModel, IBaseEntity>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Pims.Api.Models.Concepts.ExpropriationPayment
{
public class ExpropriationPaymentItemModel : BaseAppModel
{
public long? Id { get; set; }

public long? ExpropriationPaymentId { get; set; }

public string PaymentItemTypeCode { get; set; }

public TypeModel<string> PaymentItemType { get; set; }

public bool? IsGstRequired { get; set; }

public decimal? PretaxAmount { get; set; }

public decimal? TaxAmount { get; set; }

public decimal? TotalAmount { get; set; }

public bool? IsDisabled { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Mapster;
using Pims.Dal.Entities;

namespace Pims.Api.Models.Concepts
{
public class ExpropriationPaymentMap : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<PimsExpropriationPayment, ExpropriationPaymentModel>()
.Map(dest => dest.Id, src => src.Internal_Id)
.Map(dest => dest.AcquisitionFileId, src => src.AcquisitionFileId)
.Map(dest => dest.AcquisitionOwnerId, src => src.AcquisitionOwnerId)
.Map(dest => dest.AcquisitionOwner, src => src.AcquisitionOwner)
.Map(dest => dest.InterestHolderId, src => src.InterestHolderId)
.Map(dest => dest.InterestHolder, src => src.InterestHolder)
.Map(dest => dest.ExpropriatingAuthorityId, src => src.ExpropriatingAuthority)
.Map(dest => dest.ExpropriatingAuthority, src => src.ExpropriatingAuthorityNavigation)
.Map(dest => dest.Description, src => src.Description)
.Map(dest => dest.IsDisabled, src => src.IsDisabled)
.Map(dest => dest.RowVersion, src => src.ConcurrencyControlNumber)
.Map(dest => dest.PaymentItems, src => src.PimsExpropPmtPmtItems)
.Inherits<IBaseEntity, BaseModel>();

config.NewConfig<ExpropriationPaymentModel, PimsExpropriationPayment>()
.Map(dest => dest.Internal_Id, src => src.Id)
.Map(dest => dest.AcquisitionFileId, src => src.AcquisitionFileId)
.Map(dest => dest.AcquisitionOwnerId, src => src.AcquisitionOwnerId)
.Map(dest => dest.InterestHolderId, src => src.InterestHolderId)
.Map(dest => dest.ExpropriatingAuthority, src => src.ExpropriatingAuthorityId)
.Map(dest => dest.Description, src => src.Description)
.Map(dest => dest.IsDisabled, src => src.IsDisabled)
.Map(dest => dest.ConcurrencyControlNumber, src => src.RowVersion)
.Map(dest => dest.PimsExpropPmtPmtItems, src => src.PaymentItems)
.Inherits<BaseModel, IBaseEntity>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using Pims.Api.Models.Concepts.ExpropriationPayment;

namespace Pims.Api.Models.Concepts
{
public class ExpropriationPaymentModel : BaseAppModel
{
public long? Id { get; set; }

public long AcquisitionFileId { get; set; }

public long? AcquisitionOwnerId { get; set; }

public AcquisitionFileOwnerModel AcquisitionOwner { get; set; }

public long? InterestHolderId { get; set; }

public InterestHolderModel InterestHolder { get; set; }

public long? ExpropriatingAuthorityId { get; set; }

public OrganizationModel ExpropriatingAuthority { get; set; }

public string Description { get; set; }

public bool? IsDisabled { get; set; }

public List<ExpropriationPaymentItemModel> PaymentItems { get; set; }

}
}
1 change: 0 additions & 1 deletion source/backend/api/Models/Concepts/Take/TakeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class TakeModel : BaseAppModel

public float? LandActArea { get; set; }


public DateTime? LandActEndDt { get; set; }

public AcquisitionFileModel PropertyAcquisitionFile { get; set; }
Expand Down
Loading
Loading