Skip to content

Commit d2ff31f

Browse files
authored
Merge pull request #634 from bcgov/yj
chore: Get Str Requirements
2 parents 77f96a4 + d9a901f commit d2ff31f

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

server/StrDss.Api/Controllers/OrganizationsController.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,30 @@ public async Task<ActionResult<List<DropdownNumDto>>> GetOrganizationsDropdown(s
4343
{
4444
return Ok(await _orgService.GetOrganizationsDropdownAsync(type));
4545
}
46+
47+
[ApiAuthorize]
48+
[HttpGet("strrequirements", Name = "GetStrRequirements")]
49+
public async Task<ActionResult<StrRequirementsDto>> GetStrRequirements(double longitude, double latitude)
50+
{
51+
var errors = new Dictionary<string, List<string>>();
52+
53+
if (longitude < -180 || longitude > 180)
54+
errors.AddItem("logitude", "Longitude must be between -180 and 180 degrees.");
55+
56+
if (latitude < -90 || latitude > 90)
57+
errors.AddItem("latitude", "Longitude must be between -180 and 180 degrees.");
58+
59+
if (errors.Any())
60+
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext, "One or more validation errors occurred.");
61+
62+
var strRequirement = await _orgService.GetStrRequirements(longitude, latitude);
63+
64+
if (strRequirement == null)
65+
{
66+
return NotFound();
67+
}
68+
69+
return Ok(await _orgService.GetStrRequirements(longitude, latitude));
70+
}
4671
}
4772
}

server/StrDss.Data/Repositories/OrganizationRepository.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AutoMapper;
2+
using AutoMapper.Features;
23
using Microsoft.EntityFrameworkCore;
34
using Microsoft.Extensions.Configuration;
45
using Microsoft.Extensions.Logging;
@@ -20,6 +21,7 @@ public interface IOrganizationRepository
2021
Task<OrganizationDto> GetOrganizationByOrgCdAsync(string orgCd);
2122
Task<long?> GetContainingOrganizationId(Point point);
2223
Task<long?> GetManagingOrgId(long orgId);
24+
Task<StrRequirementsDto?> GetStrRequirements(double longitude, double latitude);
2325
}
2426
public class OrganizationRepository : RepositoryBase<DssOrganization>, IOrganizationRepository
2527
{
@@ -122,5 +124,27 @@ public async Task<OrganizationDto> GetOrganizationByOrgCdAsync(string orgCd)
122124
var org = await _dbSet.AsNoTracking().FirstOrDefaultAsync(x => x.OrganizationId == orgId);
123125
return org?.ManagingOrganizationId;
124126
}
127+
128+
public async Task<StrRequirementsDto?> GetStrRequirements(double longitude, double latitude)
129+
{
130+
var point = new Point(longitude, latitude) { SRID = 4326 };
131+
132+
var strRequirement = await _dbContext.DssOrganizations
133+
.FromSqlRaw(@"
134+
SELECT organization_nm, is_principal_residence_required, is_business_licence_required
135+
FROM dss_organization
136+
WHERE organization_id = dss_containing_organization_id({0})", point)
137+
138+
.Select(o => new StrRequirementsDto
139+
{
140+
OrganizationNm = o.OrganizationNm,
141+
IsPrincipalResidenceRequired = o.IsPrincipalResidenceRequired,
142+
IsBusinessLicenceRequired = o.IsBusinessLicenceRequired,
143+
IsStrProhibited = null
144+
})
145+
.FirstOrDefaultAsync();
146+
147+
return strRequirement;
148+
}
125149
}
126150
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace StrDss.Model
2+
{
3+
public class StrRequirementsDto
4+
{
5+
public string OrganizationNm { get; set; }
6+
public bool? IsPrincipalResidenceRequired { get; set; }
7+
public bool? IsBusinessLicenceRequired { get; set; }
8+
public bool? IsStrProhibited { get; set; }
9+
}
10+
}

server/StrDss.Service/OrganizationService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface IOrganizationService
1717
Task<List<DropdownNumDto>> GetOrganizationsDropdownAsync(string? type);
1818
Task<OrganizationDto?> GetOrganizationByIdAsync(long id);
1919
Task<long?> GetContainingOrganizationId(Point point);
20+
Task<StrRequirementsDto?> GetStrRequirements(double longitude, double latitude);
2021
}
2122
public class OrganizationService : ServiceBase, IOrganizationService
2223
{
@@ -53,5 +54,10 @@ public async Task<List<DropdownNumDto>> GetOrganizationsDropdownAsync(string? ty
5354
{
5455
return await _orgRepo.GetContainingOrganizationId(point);
5556
}
57+
58+
public async Task<StrRequirementsDto?> GetStrRequirements(double longitude, double latitude)
59+
{
60+
return await _orgRepo.GetStrRequirements(longitude, latitude);
61+
}
5662
}
5763
}

0 commit comments

Comments
 (0)