From e3f5aac3d23a738a1538ce7090e10cee0ee53c6b Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Wed, 23 Oct 2024 09:30:48 -0700 Subject: [PATCH] feat(dss-949) --- .../Controllers/OrganizationsController.cs | 8 ++++++++ server/StrDss.Common/Constants.cs | 2 ++ .../Mappings/EntityToModelProfile.cs | 4 ++++ .../Repositories/OrganizationRepository.cs | 20 +++++++++++++++++-- .../OrganizationDtos/JurisdictionsViewDto.cs | 17 ++++++++++++++++ .../OrganizationDtos/LocalGovViewDto.cs | 15 ++++++++++++++ server/StrDss.Service/OrganizationService.cs | 6 ++++++ 7 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 server/StrDss.Model/OrganizationDtos/JurisdictionsViewDto.cs create mode 100644 server/StrDss.Model/OrganizationDtos/LocalGovViewDto.cs diff --git a/server/StrDss.Api/Controllers/OrganizationsController.cs b/server/StrDss.Api/Controllers/OrganizationsController.cs index 6c52cdb8..71287dc8 100644 --- a/server/StrDss.Api/Controllers/OrganizationsController.cs +++ b/server/StrDss.Api/Controllers/OrganizationsController.cs @@ -169,5 +169,13 @@ public async Task UpdatePlatformSub(PlatformSubUpdateDto dto, long return Ok(); } + + [ApiAuthorize(Permissions.JurisdictionRead)] + [HttpGet("jurisdictions")] + public async Task>> GetJurisdictions(int pageSize = 10, int pageNumber = 1, string orderBy = "OrganizationNm", string direction = "asc") + { + var jurisdictions = await _orgService.GetJurisdictions(pageSize, pageNumber, orderBy, direction); + return Ok(jurisdictions); + } } } diff --git a/server/StrDss.Common/Constants.cs b/server/StrDss.Common/Constants.cs index 0eabadb7..66370917 100644 --- a/server/StrDss.Common/Constants.cs +++ b/server/StrDss.Common/Constants.cs @@ -347,6 +347,8 @@ public static class Permissions public const string CeuAction = "ceu_action"; public const string PlatformRead = "platform_read"; public const string PlatformWrite = "platform_write"; + public const string JurisdictionRead = "jurisdiction_read"; + public const string JurisdictionWrite = "jurisdiction_write"; } public static class UploadDeliveryTypes diff --git a/server/StrDss.Data/Mappings/EntityToModelProfile.cs b/server/StrDss.Data/Mappings/EntityToModelProfile.cs index aeb7f9ea..d3a809ae 100644 --- a/server/StrDss.Data/Mappings/EntityToModelProfile.cs +++ b/server/StrDss.Data/Mappings/EntityToModelProfile.cs @@ -54,6 +54,10 @@ public EntityToModelProfile() CreateMap(); CreateMap(); CreateMap(); + + CreateMap(); + CreateMap(); + } } } diff --git a/server/StrDss.Data/Repositories/OrganizationRepository.cs b/server/StrDss.Data/Repositories/OrganizationRepository.cs index 769822fa..9ada8627 100644 --- a/server/StrDss.Data/Repositories/OrganizationRepository.cs +++ b/server/StrDss.Data/Repositories/OrganizationRepository.cs @@ -30,7 +30,7 @@ public interface IOrganizationRepository Task UpdatePlatformAsync(PlatformUpdateDto dto); Task CreatePlatformSubAsync(PlatformSubCreateDto dto); Task UpdatePlatformSubAsync(PlatformSubUpdateDto dto); - + Task> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction); } public class OrganizationRepository : RepositoryBase, IOrganizationRepository { @@ -151,7 +151,7 @@ public async Task GetOrganizationByOrgCdAsync(string orgCd) var strRequirement = await _dbContext.DssOrganizations .FromSqlRaw(@" - SELECT p.organization_nm, c.is_principal_residence_required, c.is_business_licence_required, p.is_str_prohibited + SELECT p.organization_nm, c.is_principal_residence_required, c.is_business_licence_required, c.is_str_prohibited FROM dss_organization c, dss_organization p WHERE p.organization_id = c.managing_organization_id and c.organization_id = dss_containing_organization_id({0})", point) @@ -294,5 +294,21 @@ public async Task UpdatePlatformSubAsync(PlatformSubUpdateDto dto) UpdateContact(entity, EmailMessageTypes.TakedownRequest, dto.PrimaryTakedownRequestContactEmail, true); UpdateContact(entity, EmailMessageTypes.TakedownRequest, dto.SecondaryTakedownRequestContactEmail, false); } + + public async Task> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction) + { + var query = _dbSet.AsNoTracking() + .Where(x => x.OrganizationType == OrganizationTypes.LG && x.ManagingOrganizationId == null); + + var lgs = await Page(query, pageSize, pageNumber, orderBy, direction); + + foreach (var lg in lgs.SourceList) + { + lg.Jurisdictions = _mapper.Map> + (await _dbSet.AsNoTracking().Where(x => x.ManagingOrganizationId == lg.OrganizationId).ToListAsync()); + } + + return lgs; + } } } diff --git a/server/StrDss.Model/OrganizationDtos/JurisdictionsViewDto.cs b/server/StrDss.Model/OrganizationDtos/JurisdictionsViewDto.cs new file mode 100644 index 00000000..b9bbe5df --- /dev/null +++ b/server/StrDss.Model/OrganizationDtos/JurisdictionsViewDto.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace StrDss.Model.OrganizationDtos +{ + public class JurisdictionsViewDto + { + public long OrganizationId { get; set; } + public string OrganizationNm { get; set; } = null!; + [JsonPropertyName("shapeFileId")] + public string OrganizationCd { get; set; } = null!; + public bool? IsPrincipalResidenceRequired { get; set; } + public bool? IsStrProhibited { get; set; } + public bool? IsBusinessLicenceRequired { get; set; } + public string? EconomicRegionDsc { get; set; } + public long? ManagingOrganizationId { get; set; } + } +} diff --git a/server/StrDss.Model/OrganizationDtos/LocalGovViewDto.cs b/server/StrDss.Model/OrganizationDtos/LocalGovViewDto.cs new file mode 100644 index 00000000..fe69e119 --- /dev/null +++ b/server/StrDss.Model/OrganizationDtos/LocalGovViewDto.cs @@ -0,0 +1,15 @@ +namespace StrDss.Model.OrganizationDtos +{ + public class LocalGovViewDto + { + public LocalGovViewDto() + { + Jurisdictions = new List(); + } + public long OrganizationId { get; set; } + public string OrganizationNm { get; set; } = null!; + public string? LocalGovernmentType { get; set; } + public string OrganizationCd { get; set; } = null!; + public virtual ICollection Jurisdictions { get; set; } + } +} diff --git a/server/StrDss.Service/OrganizationService.cs b/server/StrDss.Service/OrganizationService.cs index a0f0dbba..50dc8090 100644 --- a/server/StrDss.Service/OrganizationService.cs +++ b/server/StrDss.Service/OrganizationService.cs @@ -27,6 +27,7 @@ public interface IOrganizationService Task>> UpdatePlatformAsync(PlatformUpdateDto dto); Task<(Dictionary>, long)> CreatePlatformSubAsync(PlatformSubCreateDto dto); Task>> UpdatePlatformSubAsync(PlatformSubUpdateDto dto); + Task> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction); } public class OrganizationService : ServiceBase, IOrganizationService { @@ -238,5 +239,10 @@ public async Task>> UpdatePlatformSubAsync(Platf return errors; } + + public async Task> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction) + { + return await _orgRepo.GetJurisdictions(pageSize, pageNumber, orderBy, direction); + } } }