Skip to content

Commit

Permalink
Merge pull request #737 from bcgov/yj
Browse files Browse the repository at this point in the history
feat(dss-949)
  • Loading branch information
ychung-mot authored Oct 23, 2024
2 parents 8c5be53 + e3f5aac commit 1410ffc
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 2 deletions.
8 changes: 8 additions & 0 deletions server/StrDss.Api/Controllers/OrganizationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,13 @@ public async Task<ActionResult> UpdatePlatformSub(PlatformSubUpdateDto dto, long

return Ok();
}

[ApiAuthorize(Permissions.JurisdictionRead)]
[HttpGet("jurisdictions")]
public async Task<ActionResult<List<PlatformViewDto>>> 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);
}
}
}
2 changes: 2 additions & 0 deletions server/StrDss.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions server/StrDss.Data/Mappings/EntityToModelProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public EntityToModelProfile()
CreateMap<DssOrganization, PlatformCreateDto>();
CreateMap<DssPlatformVw, PlatformViewDto>();
CreateMap<DssPlatformType, PlatformTypeDto>();

CreateMap<DssOrganization, LocalGovViewDto>();
CreateMap<DssOrganization, JurisdictionsViewDto>();

}
}
}
20 changes: 18 additions & 2 deletions server/StrDss.Data/Repositories/OrganizationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IOrganizationRepository
Task UpdatePlatformAsync(PlatformUpdateDto dto);
Task<DssOrganization> CreatePlatformSubAsync(PlatformSubCreateDto dto);
Task UpdatePlatformSubAsync(PlatformSubUpdateDto dto);

Task<PagedDto<LocalGovViewDto>> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction);
}
public class OrganizationRepository : RepositoryBase<DssOrganization>, IOrganizationRepository
{
Expand Down Expand Up @@ -151,7 +151,7 @@ public async Task<OrganizationDto> 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)

Expand Down Expand Up @@ -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<PagedDto<LocalGovViewDto>> 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<DssOrganization, LocalGovViewDto>(query, pageSize, pageNumber, orderBy, direction);

foreach (var lg in lgs.SourceList)
{
lg.Jurisdictions = _mapper.Map<List<JurisdictionsViewDto>>
(await _dbSet.AsNoTracking().Where(x => x.ManagingOrganizationId == lg.OrganizationId).ToListAsync());
}

return lgs;
}
}
}
17 changes: 17 additions & 0 deletions server/StrDss.Model/OrganizationDtos/JurisdictionsViewDto.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
15 changes: 15 additions & 0 deletions server/StrDss.Model/OrganizationDtos/LocalGovViewDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace StrDss.Model.OrganizationDtos
{
public class LocalGovViewDto
{
public LocalGovViewDto()
{
Jurisdictions = new List<JurisdictionsViewDto>();
}
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<JurisdictionsViewDto> Jurisdictions { get; set; }
}
}
6 changes: 6 additions & 0 deletions server/StrDss.Service/OrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface IOrganizationService
Task<Dictionary<string, List<string>>> UpdatePlatformAsync(PlatformUpdateDto dto);
Task<(Dictionary<string, List<string>>, long)> CreatePlatformSubAsync(PlatformSubCreateDto dto);
Task<Dictionary<string, List<string>>> UpdatePlatformSubAsync(PlatformSubUpdateDto dto);
Task<PagedDto<LocalGovViewDto>> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction);
}
public class OrganizationService : ServiceBase, IOrganizationService
{
Expand Down Expand Up @@ -238,5 +239,10 @@ public async Task<Dictionary<string, List<string>>> UpdatePlatformSubAsync(Platf

return errors;
}

public async Task<PagedDto<LocalGovViewDto>> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction)
{
return await _orgRepo.GetJurisdictions(pageSize, pageNumber, orderBy, direction);
}
}
}

0 comments on commit 1410ffc

Please sign in to comment.