Skip to content

Commit

Permalink
Scaffold/s86 (#4241)
Browse files Browse the repository at this point in the history
* Regenerated scaffold

* Updated LeaseTenant->LeaseStakeholder. Fixed compilation issues and renamed files

* Typo fix

* Typo fix
  • Loading branch information
FuriousLlama committed Aug 2, 2024
1 parent 6063f78 commit b1a835a
Show file tree
Hide file tree
Showing 54 changed files with 1,097 additions and 494 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
namespace Pims.Api.Areas.Lease.Controllers
{
/// <summary>
/// LeaseTenantController class, provides endpoints for interacting with lease tenants.
/// LeaseStakeholderController class, provides endpoints for interacting with lease stakeholder.
/// </summary>
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Area("leases")]
[Route("v{version:apiVersion}/[area]")]
[Route("[area]")]
public class LeaseTenantController : ControllerBase
public class LeaseStakeholderController : ControllerBase
{
#region Variables
private readonly ILeaseService _leaseService;
Expand All @@ -34,13 +34,13 @@ public class LeaseTenantController : ControllerBase
#region Constructors

/// <summary>
/// Creates a new instance of a LeaseTenantController class, initializes it with the specified arguments.
/// Creates a new instance of a LeaseStakeholderController class, initializes it with the specified arguments.
/// </summary>
/// <param name="leaseService"></param>
/// <param name="mapper"></param>
/// <param name="logger"></param>
///
public LeaseTenantController(ILeaseService leaseService, IMapper mapper, ILogger<PropertyImprovementController> logger)
public LeaseStakeholderController(ILeaseService leaseService, IMapper mapper, ILogger<PropertyImprovementController> logger)
{
_leaseService = leaseService;
_mapper = mapper;
Expand All @@ -51,52 +51,52 @@ public LeaseTenantController(ILeaseService leaseService, IMapper mapper, ILogger
#region Endpoints

/// <summary>
/// Get the specified tenants on the passed lease.
/// Get the specified stakeholders on the passed lease.
/// </summary>
/// <returns></returns>
[HttpGet("{leaseId:long}/tenants")]
[HttpGet("{leaseId:long}/stakeholders")]
[HasPermission(Permissions.LeaseView)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<LeaseTenantModel>), 200)]
[ProducesResponseType(typeof(IEnumerable<LeaseStakeholderModel>), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult GetTenants(long leaseId)
public IActionResult GetStakeholders(long leaseId)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTenantController),
nameof(GetTenants),
nameof(LeaseStakeholderController),
nameof(GetStakeholders),
User.GetUsername(),
DateTime.Now);

var updatedLease = _leaseService.GetTenantsByLeaseId(leaseId);
var updatedLease = _leaseService.GetStakeholdersByLeaseId(leaseId);

return new JsonResult(_mapper.Map<IEnumerable<LeaseTenantModel>>(updatedLease));
return new JsonResult(_mapper.Map<IEnumerable<LeaseStakeholderModel>>(updatedLease));
}

/// <summary>
/// Update the specified tenants on the passed lease.
/// Update the specified stakeholders on the passed lease.
/// </summary>
/// <returns></returns>
[HttpPut("{leaseId:long}/tenants")]
[HttpPut("{leaseId:long}/stakeholders")]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<LeaseTenantModel>), 200)]
[ProducesResponseType(typeof(IEnumerable<LeaseStakeholderModel>), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdateTenants(long leaseId, IEnumerable<LeaseTenantModel> tenants)
public IActionResult UpdateStakeholders(long leaseId, IEnumerable<LeaseStakeholderModel> stakeholders)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTenantController),
nameof(UpdateTenants),
nameof(LeaseStakeholderController),
nameof(UpdateStakeholders),
User.GetUsername(),
DateTime.Now);

var tenantEntities = _mapper.Map<ICollection<Pims.Dal.Entities.PimsLeaseTenant>>(tenants);
var updatedLease = _leaseService.UpdateTenantsByLeaseId(leaseId, tenantEntities);
var stakeholderEntities = _mapper.Map<ICollection<Pims.Dal.Entities.PimsLeaseStakeholder>>(stakeholders);
var updatedLease = _leaseService.UpdateStakeholdersByLeaseId(leaseId, stakeholderEntities);

return new JsonResult(_mapper.Map<IEnumerable<LeaseTenantModel>>(updatedLease));
return new JsonResult(_mapper.Map<IEnumerable<LeaseStakeholderModel>>(updatedLease));
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public IEnumerable<LeaseModel> GetCrossJoinLeases(Lease.Models.Search.LeaseFilte
var allLeases = page.Items
.SelectMany(l => l.PimsLeasePeriods.DefaultIfEmpty(), (lease, period) => (lease, period))
.SelectMany(lt => lt.lease.PimsPropertyLeases.DefaultIfEmpty(), (leasePeriod, property) => (leasePeriod.period, leasePeriod.lease, property))
.SelectMany(ltp => ltp.lease.PimsLeaseTenants.DefaultIfEmpty(), (leasePeriodProperty, tenant) => (leasePeriodProperty.period, leasePeriodProperty.lease, leasePeriodProperty.property, tenant));
.SelectMany(ltp => ltp.lease.PimsLeaseStakeholders.DefaultIfEmpty(), (leasePeriodProperty, tenant) => (leasePeriodProperty.period, leasePeriodProperty.lease, leasePeriodProperty.property, tenant));
var flatLeases = _mapper.Map<IEnumerable<LeaseModel>>(allLeases);
return flatLeases;
}
Expand Down
6 changes: 3 additions & 3 deletions source/backend/api/Areas/Reports/Mapping/Lease/LeaseMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class LeaseMap : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<(Entity.PimsLeasePeriod period, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseTenant tenant), Model.LeaseModel>()
config.NewConfig<(Entity.PimsLeasePeriod period, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseStakeholder stakeholder), Model.LeaseModel>()
.AfterMapping((src, dest) =>
{
MapLease(src, dest);
});
}

private static void MapLease((Entity.PimsLeasePeriod period, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseTenant tenant) src, Model.LeaseModel dest)
private static void MapLease((Entity.PimsLeasePeriod period, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseStakeholder stakeholder) src, Model.LeaseModel dest)
{
var leaseExpiryDate = src.lease.GetExpiryDate();
dest.LFileNo = src.lease.LFileNo;
Expand Down Expand Up @@ -46,7 +46,7 @@ private static void MapLease((Entity.PimsLeasePeriod period, Entity.PimsLease le
dest.CivicAddress = src.property?.Property?.Address?.FormatAddress(true);
dest.Pid = src.property?.Property?.Pid;
dest.Pin = src.property?.Property?.Pin;
dest.TenantName = src.tenant?.GetTenantName();
dest.TenantName = src.stakeholder?.GetStakeholderName();
dest.FinancialGain = src.lease.IsFinancialGain.BoolToYesNoUnknown();
dest.PublicBenefit = src.lease.IsPublicBenefit.BoolToYesNoUnknown();
}
Expand Down
4 changes: 2 additions & 2 deletions source/backend/api/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public IActionResult GetAll()
var acquisitionPhysFileStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAcquisitionPhysFileStatusTypes());
var acquisitionTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAcquisitionTypes());
var acqFilePersonProfileTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAcqFileTeamProfileTypes());
var tenantTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllTenantTypes());
var leaseStakeholderTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeaseStakeholderTypes());
var acqFundingTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAcquisitionFundingTypes());
var projectStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllProjectStatusTypes());
var formTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllFormTypes());
Expand Down Expand Up @@ -189,7 +189,7 @@ public IActionResult GetAll()
codes.AddRange(acquisitionPhysFileStatusTypes);
codes.AddRange(acquisitionTypes);
codes.AddRange(acqFilePersonProfileTypes);
codes.AddRange(tenantTypes);
codes.AddRange(leaseStakeholderTypes);
codes.AddRange(acqFundingTypes);
codes.AddRange(projectStatusTypes);
codes.AddRange(formTypes);
Expand Down
3 changes: 1 addition & 2 deletions source/backend/api/Models/Report/LeasePaymentReportMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.HistoricalFiles, src => GetHistoricalFileNumbers(src.LeasePeriod.Lease))
.Map(dest => dest.LeaseStatus, src => src.LeasePeriod.Lease.LeaseStatusTypeCodeNavigation.Description)
.Map(dest => dest.PropertyList, src => string.Join(",", src.LeasePeriod.Lease.PimsPropertyLeases.Select(x => GetFallbackPropertyIdentifier(x))))
.Map(dest => dest.TenantList, src => string.Join(",", src.LeasePeriod.Lease.PimsLeaseTenants.Where(t => t != null && t.TenantTypeCode == "TEN").Select(x => x != null && x.Person != null ? x.Person.GetFullName(false) : x != null && x.Organization != null ? x.Organization.OrganizationName : string.Empty)))
.Map(dest => dest.TenantList, src => string.Join(",", src.LeasePeriod.Lease.PimsLeaseStakeholders.Where(t => t != null && t.LeaseStakeholderTypeCode == "TEN").Select(x => x != null && x.Person != null ? x.Person.GetFullName(false) : x != null && x.Organization != null ? x.Organization.OrganizationName : string.Empty)))
.Map(dest => dest.PayableOrReceivable, src => src.LeasePeriod.Lease.LeasePayRvblTypeCodeNavigation.Description)
.Map(dest => dest.Program, src => src.LeasePeriod.Lease.LeaseProgramTypeCode.ToUpper() == "OTHER" && !string.IsNullOrEmpty(src.LeasePeriod.Lease.OtherLeaseProgramType) ? $"{src.LeasePeriod.Lease.LeaseProgramTypeCodeNavigation.Description} - {src.LeasePeriod.Lease.OtherLeaseProgramType}" : src.LeasePeriod.Lease.LeaseProgramTypeCodeNavigation.Description)
//.Map(dest => dest.Purpose, src => src.LeasePeriod.Lease.LeasePurposeTypeCode.ToUpper() == "OTHER" && !string.IsNullOrEmpty(src.LeasePeriod.Lease.OtherLeasePurposeType) ? $"{src.LeasePeriod.Lease.LeasePurposeTypeCodeNavigation.Description} - {src.LeasePeriod.Lease.OtherLeasePurposeType}" : src.LeasePeriod.Lease.LeasePurposeTypeCodeNavigation.Description) TODO: Fix mappings
.Map(dest => dest.PeriodStart, src => src.LeasePeriod.PeriodStartDate.ToString("MMMM dd, yyyy"))
.Map(dest => dest.PeriodExpiry, src => src.LeasePeriod.PeriodExpiryDate.HasValue ? src.LeasePeriod.PeriodExpiryDate.Value.ToString("MMMM dd, yyyy") : string.Empty)
.Map(dest => dest.IsPeriodExercised, src => src.LeasePeriod.LeasePeriodStatusTypeCode == "EXER" ? "Yes" : "No")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public PimsCompensationRequisition Update(PimsCompensationRequisition compensati
{
_user.ThrowIfNotAuthorized(Permissions.CompensationRequisitionEdit);
compensationRequisition.ThrowIfNull(nameof(compensationRequisition));


/* TODO: Fix compensation requisition
_user.ThrowInvalidAccessToAcquisitionFile(_userRepository, _acqFileRepository, compensationRequisition.AcquisitionFileId);
_logger.LogInformation($"Updating Compensation Requisition with id ${compensationRequisition.CompensationRequisitionId}");
Expand Down Expand Up @@ -93,6 +96,8 @@ public PimsCompensationRequisition Update(PimsCompensationRequisition compensati
return null;
}
*/
return null;
}

public bool DeleteCompensation(long compensationId)
Expand All @@ -102,6 +107,7 @@ public bool DeleteCompensation(long compensationId)

var currentCompensation = _compensationRequisitionRepository.GetById(compensationId);

/* TODO: Fix compensation requisition
var currentAcquisitionStatus = GetCurrentAcquisitionStatus(currentCompensation.AcquisitionFileId);
if (!_statusSolver.CanEditOrDeleteCompensation(currentAcquisitionStatus, currentCompensation.IsDraft) && !_user.HasPermission(Permissions.SystemAdmin))
Expand All @@ -111,8 +117,9 @@ public bool DeleteCompensation(long compensationId)
var fileFormToDelete = _compensationRequisitionRepository.TryDelete(compensationId);
_compensationRequisitionRepository.CommitTransaction();

return fileFormToDelete;
*/
return true;
}

public IEnumerable<PimsPropertyAcquisitionFile> GetProperties(long id)
Expand Down
4 changes: 2 additions & 2 deletions source/backend/api/Services/ILeaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public interface ILeaseService

IEnumerable<PimsPropertyImprovement> UpdateImprovementsByLeaseId(long leaseId, IEnumerable<PimsPropertyImprovement> pimsPropertyImprovements);

IEnumerable<PimsLeaseTenant> GetTenantsByLeaseId(long leaseId);
IEnumerable<PimsLeaseStakeholder> GetStakeholdersByLeaseId(long leaseId);

IEnumerable<PimsLeaseTenant> UpdateTenantsByLeaseId(long leaseId, IEnumerable<PimsLeaseTenant> pimsLeaseTenants);
IEnumerable<PimsLeaseStakeholder> UpdateStakeholdersByLeaseId(long leaseId, IEnumerable<PimsLeaseStakeholder> pimsLeaseStakeholders);

IEnumerable<PimsLeaseRenewal> GetRenewalsByLeaseId(long leaseId);

Expand Down
22 changes: 11 additions & 11 deletions source/backend/api/Services/LeaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LeaseService : BaseService, ILeaseService
private readonly IPropertyLeaseRepository _propertyLeaseRepository;
private readonly IEntityNoteRepository _entityNoteRepository;
private readonly IInsuranceRepository _insuranceRepository;
private readonly ILeaseTenantRepository _tenantRepository;
private readonly ILeaseStakeholderRepository _stakeholderRepository;
private readonly ILeaseRenewalRepository _renewalRepository;
private readonly IUserRepository _userRepository;
private readonly IPropertyService _propertyService;
Expand All @@ -46,7 +46,7 @@ public LeaseService(
IPropertyImprovementRepository propertyImprovementRepository,
IEntityNoteRepository entityNoteRepository,
IInsuranceRepository insuranceRepository,
ILeaseTenantRepository tenantRepository,
ILeaseStakeholderRepository stakeholderRepository,
ILeaseRenewalRepository renewalRepository,
IUserRepository userRepository,
IPropertyService propertyService,
Expand All @@ -61,7 +61,7 @@ public LeaseService(
_entityNoteRepository = entityNoteRepository;
_propertyImprovementRepository = propertyImprovementRepository;
_insuranceRepository = insuranceRepository;
_tenantRepository = tenantRepository;
_stakeholderRepository = stakeholderRepository;
_renewalRepository = renewalRepository;
_userRepository = userRepository;
_propertyService = propertyService;
Expand Down Expand Up @@ -144,27 +144,27 @@ public IEnumerable<PimsPropertyImprovement> UpdateImprovementsByLeaseId(long lea
return _propertyImprovementRepository.GetByLeaseId(leaseId);
}

public IEnumerable<PimsLeaseTenant> GetTenantsByLeaseId(long leaseId)
public IEnumerable<PimsLeaseStakeholder> GetStakeholdersByLeaseId(long leaseId)
{
_logger.LogInformation("Getting tenants on lease {leaseId}", leaseId);
_logger.LogInformation("Getting stakeholders on lease {leaseId}", leaseId);
_user.ThrowIfNotAuthorized(Permissions.LeaseView);
var pimsUser = _userRepository.GetByKeycloakUserId(_user.GetUserKey());
pimsUser.ThrowInvalidAccessToLeaseFile(_leaseRepository.GetNoTracking(leaseId).RegionCode);

return _tenantRepository.GetByLeaseId(leaseId);
return _stakeholderRepository.GetByLeaseId(leaseId);
}

public IEnumerable<PimsLeaseTenant> UpdateTenantsByLeaseId(long leaseId, IEnumerable<PimsLeaseTenant> pimsLeaseTenants)
public IEnumerable<PimsLeaseStakeholder> UpdateStakeholdersByLeaseId(long leaseId, IEnumerable<PimsLeaseStakeholder> pimsLeaseStakeholders)
{
_logger.LogInformation("Updating tenants on lease {leaseId}", leaseId);
_logger.LogInformation("Updating stakeholders on lease {leaseId}", leaseId);
_user.ThrowIfNotAuthorized(Permissions.LeaseEdit);
var pimsUser = _userRepository.GetByKeycloakUserId(_user.GetUserKey());
pimsUser.ThrowInvalidAccessToLeaseFile(_leaseRepository.GetNoTracking(leaseId).RegionCode);

_tenantRepository.Update(leaseId, pimsLeaseTenants);
_tenantRepository.CommitTransaction();
_stakeholderRepository.Update(leaseId, pimsLeaseStakeholders);
_stakeholderRepository.CommitTransaction();

return _tenantRepository.GetByLeaseId(leaseId);
return _stakeholderRepository.GetByLeaseId(leaseId);
}

public PimsLease Add(PimsLease lease, IEnumerable<UserOverrideCode> userOverrides)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
namespace Pims.Api.Models.CodeTypes
{
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
public enum LeaseTenantTypes
public enum LeaseStakeholderTypes
{

[EnumMember(Value = "ASGN")]
ASGN,

[EnumMember(Value = "OWNER")]
OWNER,
[EnumMember(Value = "OWNREP")]
OWNREP,
[EnumMember(Value = "PMGR")]
PMGR,

[EnumMember(Value = "REP")]
REP,

[EnumMember(Value = "TEN")]
TEN,

[EnumMember(Value = "UNK")]
UNK,
}
Expand Down
2 changes: 1 addition & 1 deletion source/backend/apimodels/Models/Concepts/Lease/LeaseMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.CancellationReason, src => src.CancellationReason)
.Map(dest => dest.TerminationReason, src => src.TerminationReason)
.Map(dest => dest.Project, src => src.Project)
.Map(dest => dest.Tenants, src => src.PimsLeaseTenants)
.Map(dest => dest.Stakeholders, src => src.PimsLeaseStakeholders)
.Map(dest => dest.FileChecklistItems, src => src.PimsLeaseChecklistItems)
.Map(dest => dest.PrimaryArbitrationCity, src => src.PrimaryArbitrationCity)
.Map(dest => dest.Periods, src => src.PimsLeasePeriods)
Expand Down
4 changes: 2 additions & 2 deletions source/backend/apimodels/Models/Concepts/Lease/LeaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public class LeaseModel : FileWithChecklistModel
public IEnumerable<ConsultationLeaseModel> Consultations { get; set; }

/// <summary>
/// get/set - A collection of the tenants for this lease.
/// get/set - A collection of the stakeholders for this lease.
/// </summary>
public IEnumerable<LeaseTenantModel> Tenants { get; set; }
public IEnumerable<LeaseStakeholderModel> Stakeholders { get; set; }

/// <summary>
/// get/set - A collection of the periods for this lease.
Expand Down
Loading

0 comments on commit b1a835a

Please sign in to comment.