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 6322 - lease and license refactor #3253

Merged
merged 6 commits into from
Jun 27, 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

This file was deleted.

106 changes: 106 additions & 0 deletions source/backend/api/Areas/Leases/Controllers/InsuranceController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Pims.Api.Areas.Lease.Controllers;
using Pims.Api.Models.Concepts;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Extensions;
using Pims.Core.Json;
using Pims.Dal.Entities;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;

namespace Pims.Api.Areas.Leases.Controllers
{
/// <summary>
/// InsuranceController class, provides endpoints for interacting with insurances.
/// </summary>
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Area("insurances")]
[Route("v{version:apiVersion}/leases/{leaseId}/[area]")]
[Route("/leases/{leaseId}/[area]")]
public class InsuranceController : 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 InsuranceController class, initializes it with the specified arguments.
/// </summary>
/// <param name="mapper"></param>
/// <param name="leaseService"></param>
/// <param name="logger"></param>
///
public InsuranceController(IMapper mapper, ILeaseService leaseService, ILogger<InsuranceController> logger)
{
_mapper = mapper;
_leaseService = leaseService;
_logger = logger;
}
#endregion

#region Endpoints

/// <summary>
/// Updates a list of insurance for a lease.
/// </summary>
/// <returns></returns>
[HttpPut]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<InsuranceModel>), 200)]
[SwaggerOperation(Tags = new[] { "insurance" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdateInsurance(int leaseId, IEnumerable<InsuranceModel> insurances)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(InsuranceController),
nameof(UpdateInsurance),
User.GetUsername(),
DateTime.Now);

var updatedEntities = _leaseService.UpdateInsuranceByLeaseId(leaseId, _mapper.Map<IEnumerable<PimsInsurance>>(insurances));

var insuranceModels = _mapper.Map<IEnumerable<InsuranceModel>>(updatedEntities);

return new JsonResult(insuranceModels);
}

/// <summary>
/// Get a list of insurance for a lease.
/// </summary>
/// <returns></returns>
[HttpGet]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<InsuranceModel>), 200)]
[SwaggerOperation(Tags = new[] { "insurance" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult GetInsurance(int leaseId)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(PropertyImprovementController),
nameof(GetInsurance),
User.GetUsername(),
DateTime.Now);

var insuranceModels = _mapper.Map<IEnumerable<InsuranceModel>>(_leaseService.GetInsuranceByLeaseId(leaseId));

return new JsonResult(insuranceModels);
}
#endregion
}
}
20 changes: 2 additions & 18 deletions source/backend/api/Areas/Leases/Controllers/LeaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,9 @@ public LeaseController(ILeaseService leaseService, IMapper mapper)
[HttpGet("{id:long}")]
[HasPermission(Permissions.LeaseView)]
[Produces("application/json")]
[ProducesResponseType(typeof(Models.Lease.LeaseModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
public IActionResult GetLease(int id)
{
var lease = _leaseService.GetById(id);
var mapped = _mapper.Map<Models.Lease.LeaseModel>(lease);
return new JsonResult(mapped);
}

/// <summary>
/// Get the lease for the specified primary key 'id'.
/// </summary>
/// <returns></returns>
[HttpGet("concept/{id:long}")]
[HasPermission(Permissions.LeaseView)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<Api.Models.Concepts.LeaseModel>), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
public IActionResult GetLeaseConcept(int id)
public IActionResult GetLease(int id)
{
var lease = _leaseService.GetById(id);
var mapped = _mapper.Map<Api.Models.Concepts.LeaseModel>(lease);
Expand All @@ -83,7 +67,7 @@ public IActionResult GetLeaseConcept(int id)
[HttpPost]
[HasPermission(Permissions.LeaseAdd)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<Models.Lease.LeaseModel>), 200)]
[ProducesResponseType(typeof(IEnumerable<Api.Models.Concepts.LeaseModel>), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
public IActionResult AddLease(Api.Models.Concepts.LeaseModel leaseModel, [FromQuery] string[] userOverrideCodes)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System.Collections.Generic;
using System;
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Pims.Api.Models.Concepts;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Extensions;
using Pims.Core.Json;
using Pims.Dal.Entities;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;
Expand All @@ -24,6 +28,7 @@ public class LeasePaymentController : ControllerBase
#region Variables
private readonly ILeasePaymentService _leasePaymentService;
private readonly IMapper _mapper;
private readonly ILogger _logger;
#endregion

#region Constructors
Expand All @@ -33,11 +38,13 @@ public class LeasePaymentController : ControllerBase
/// </summary>
/// <param name="leasePaymentService"></param>
/// <param name="mapper"></param>
/// <param name="logger"></param>
///
public LeasePaymentController(ILeasePaymentService leasePaymentService, IMapper mapper)
public LeasePaymentController(ILeasePaymentService leasePaymentService, IMapper mapper, ILogger<LeasePaymentController> logger)
{
_leasePaymentService = leasePaymentService;
_mapper = mapper;
_logger = logger;
}
#endregion

Expand All @@ -50,14 +57,22 @@ public LeasePaymentController(ILeasePaymentService leasePaymentService, IMapper
[HttpPost("{leaseId:long}/payment")]
[HasPermission(Permissions.LeaseAdd)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<Models.Lease.LeaseModel>), 200)]
[ProducesResponseType(typeof(PaymentModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
public IActionResult AddPayment(long leaseId, [FromBody] Models.Lease.PaymentModel paymentModel)
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult AddPayment(long leaseId, [FromBody] PaymentModel paymentModel)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(AddPayment),
User.GetUsername(),
DateTime.Now);

var paymentEntity = _mapper.Map<PimsLeasePayment>(paymentModel);
var updatedLease = _leasePaymentService.AddPayment(leaseId, paymentModel.LeaseRowVersion, paymentEntity);
var updatedLease = _leasePaymentService.AddPayment(leaseId, paymentEntity);

return new JsonResult(_mapper.Map<Models.Lease.LeaseModel>(updatedLease));
return new JsonResult(_mapper.Map<PaymentModel>(updatedLease));
}

/// <summary>
Expand All @@ -67,14 +82,22 @@ public IActionResult AddPayment(long leaseId, [FromBody] Models.Lease.PaymentMod
[HttpPut("{leaseId:long}/payment/{paymentId:long}")]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<Models.Lease.LeaseModel>), 200)]
[ProducesResponseType(typeof(PaymentModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
public IActionResult UpdatePayment(long leaseId, long paymentId, [FromBody] Models.Lease.PaymentModel paymentModel)
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdatePayment(long leaseId, long paymentId, [FromBody] PaymentModel paymentModel)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(UpdatePayment),
User.GetUsername(),
DateTime.Now);

var paymentEntity = _mapper.Map<PimsLeasePayment>(paymentModel);
var updatedLease = _leasePaymentService.UpdatePayment(leaseId, paymentId, paymentModel.LeaseRowVersion, paymentEntity);
var updatedLease = _leasePaymentService.UpdatePayment(leaseId, paymentId, paymentEntity);

return new JsonResult(_mapper.Map<Models.Lease.LeaseModel>(updatedLease));
return new JsonResult(_mapper.Map<PaymentModel>(updatedLease));
}

/// <summary>
Expand All @@ -84,14 +107,22 @@ public IActionResult UpdatePayment(long leaseId, long paymentId, [FromBody] Mode
[HttpDelete("{leaseId:long}/payment")]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<Models.Lease.LeaseModel>), 200)]
[ProducesResponseType(typeof(bool), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
public IActionResult DeletePayment(long leaseId, Models.Lease.PaymentModel paymentModel)
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult DeletePayment(long leaseId, PaymentModel paymentModel)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(DeletePayment),
User.GetUsername(),
DateTime.Now);

var paymentEntity = _mapper.Map<PimsLeasePayment>(paymentModel);
var updatedLease = _leasePaymentService.DeletePayment(leaseId, paymentModel.LeaseRowVersion, paymentEntity);
var deleted = _leasePaymentService.DeletePayment(leaseId, paymentEntity);

return new JsonResult(_mapper.Map<Models.Lease.LeaseModel>(updatedLease));
return new JsonResult(deleted);
}
#endregion
}
Expand Down
Loading