Skip to content

Commit

Permalink
Merge pull request #759 from bcgov/yj
Browse files Browse the repository at this point in the history
Yj
  • Loading branch information
ychung-mot authored Oct 29, 2024
2 parents 08d08ae + 3fa961d commit adaa374
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 16 deletions.
10 changes: 4 additions & 6 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18.16.0-slim as builder-app
FROM node:18.16.0 as builder-app

ARG generate_sourcemap=false
WORKDIR /app
Expand All @@ -10,11 +10,9 @@ COPY . .

RUN npm run build -- --configuration production --output-hashing=none

FROM nginx:stable-alpine as builder-modules

# Ensure that the version of nginx of the builder image is compatible with the nginx version of the main image.
ENV NGINX_VERSION 1.24.0
FROM nginx:1.27.2-alpine as builder-modules

ENV NGINX_VERSION 1.27.2
ENV MORE_HEADERS_VERSION=0.34
ENV MORE_HEADERS_GITREPO=openresty/headers-more-nginx-module

Expand Down Expand Up @@ -44,7 +42,7 @@ RUN mkdir -p ${DOWNLOADS} && \
./configure --with-compat $CONFARGS --add-dynamic-module=${HEADERS_MORE_MODULE} && \
make && make install

FROM nginx:stable-alpine3.17-slim
FROM nginx:1.27.2-alpine

ENV NGINX_DIR /usr/share/nginx

Expand Down
8 changes: 3 additions & 5 deletions frontend/Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ COPY . .

RUN npm run build -- --configuration production --output-hashing=none

FROM nginx:stable-alpine as builder-modules

# Ensure that the version of nginx of the builder image is compatible with the nginx version of the main image.
ENV NGINX_VERSION 1.24.0
FROM nginx:1.27.2-alpine as builder-modules

ENV NGINX_VERSION 1.27.2
ENV MORE_HEADERS_VERSION=0.34
ENV MORE_HEADERS_GITREPO=openresty/headers-more-nginx-module

Expand Down Expand Up @@ -44,7 +42,7 @@ RUN mkdir -p ${DOWNLOADS} && \
./configure --with-compat $CONFARGS --add-dynamic-module=${HEADERS_MORE_MODULE} && \
make && make install

FROM nginx:stable-alpine3.17-slim
FROM nginx:1.27.2-alpine

ENV NGINX_DIR /usr/share/nginx

Expand Down
14 changes: 14 additions & 0 deletions server/StrDss.Api/Controllers/OrganizationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,19 @@ public async Task<ActionResult> UpdateLocalGov(LocalGovUpdateDto dto, long id)

return Ok();
}

[ApiAuthorize(Permissions.JurisdictionRead)]
[HttpGet("localgovs/jurisdictions/{id}")]
public async Task<ActionResult<LocalGovViewDto>> GetJurisdiction(long id)
{
var jurisdiction = await _orgService.GetJurisdiction(id);

if (jurisdiction == null)
{
return NotFound();
}

return Ok(jurisdiction);
}
}
}
16 changes: 13 additions & 3 deletions server/StrDss.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class Entities
public const string BizLicenceRowUntyped = "BizLicenceRowUntyped";
public const string Platform = "Platform";
public const string LocalGov = "LocalGov";
public const string Jurisdiction = "Jurisdiction";
}
public static class Fields
{
Expand Down Expand Up @@ -109,7 +110,6 @@ public static class BizLicenceRowFields

public static class PlatformFields
{
public const string OrganizationId = "OrganizationId";
public const string OrganizationCd = "OrganizationCd";
public const string OrganizationNm = "OrganizationNm";
public const string PrimaryNoticeOfTakedownContactEmail = "PrimaryNoticeOfTakedownContactEmail";
Expand All @@ -121,13 +121,21 @@ public static class PlatformFields

public static class LocalGovFields
{
public const string OrganizationId = "OrganizationId";
public const string OrganizationCd = "OrganizationCd";
public const string OrganizationNm = "OrganizationNm";
public const string LocalGovernmentType = "LocalGovernmentType";
public const string BusinessLicenceFormatTxt = "BusinessLicenceFormatTxt";
}

public static class JurisdictionFields
{
public const string ManagingOrganizationId = "ManagingOrganizationId";
public const string IsPrincipalResidenceRequired = "IsPrincipalResidenceRequired";
public const string IsStrProhibited = "IsStrProhibited";
public const string IsBusinessLicenceRequired = "IsBusinessLicenceRequired";
public const string EconomicRegionDsc = "EconomicRegionDsc";
}

public static class CsvCols
{
public const string MostRecentPlatformReportMonth = "Most Recent Platform Report Month";
Expand Down Expand Up @@ -409,13 +417,15 @@ public static class FieldTypes
public const string String = "S";
public const string Decimal = "N";
public const string Date = "D";
public const string Bool = "B";
}

public static class CodeSet
{
public const string LicenceStatus = "Licence Status";
public const string PlatformTypes = "Platform Types";
public const string LocalGovTypes = "Local Gov Types";
public const string LocalGovTypes = "Local Government Types";
public const string EconomicRegions = "Economic Regions";
}

public static class StrDssIdProviders
Expand Down
1 change: 1 addition & 0 deletions server/StrDss.Data/Mappings/ModelToEntityProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public ModelToEntityProfile()
CreateMap<PlatformSubCreateDto, DssOrganization>();
CreateMap<PlatformSubUpdateDto, DssOrganization>();
CreateMap<LocalGovUpdateDto, DssOrganization>();
CreateMap<JurisdictionUpdateDto, DssOrganization>();
}
}
}
11 changes: 11 additions & 0 deletions server/StrDss.Data/Repositories/CodeSetRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public async Task<List<CommonCodeDto>> LoadCodeSetAsync()
}).ToListAsync()
);

commonCodes.AddRange(await
_dbContext.DssEconomicRegions
.AsNoTracking()
.Select(x => new CommonCodeDto
{
CodeSet = CodeSet.EconomicRegions,
CodeName = x.EconomicRegionDsc,
CodeValue = x.EconomicRegionNm
}).ToListAsync()
);

return commonCodes;
}
}
Expand Down
21 changes: 20 additions & 1 deletion server/StrDss.Data/Repositories/OrganizationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface IOrganizationRepository
Task<PagedDto<LocalGovViewDto>> GetLocalGovs(int pageSize, int pageNumber, string orderBy, string direction);
Task UpdateLocalGovAsync(LocalGovUpdateDto dto);
Task<LocalGovViewDto?> GetLocalGov(long id);
Task<JurisdictionsViewDto?> GetJurisdiction(long id);
Task UpdateJurisdictionAsync(JurisdictionUpdateDto dto);
}
public class OrganizationRepository : RepositoryBase<DssOrganization>, IOrganizationRepository
{
Expand Down Expand Up @@ -343,9 +345,26 @@ public async Task UpdateLocalGovAsync(LocalGovUpdateDto dto)

public async Task<LocalGovViewDto?> GetLocalGov(long id)
{
var localGov = _mapper.Map<LocalGovViewDto>(await _dbContext.DssLocalGovVws.AsNoTracking().FirstOrDefaultAsync(x => x.OrganizationId == id));
var localGov = _mapper.Map<LocalGovViewDto>
(await _dbContext.DssLocalGovVws.AsNoTracking().FirstOrDefaultAsync(x => x.OrganizationId == id));

return localGov;
}

public async Task<JurisdictionsViewDto?> GetJurisdiction(long id)
{
var jurisdiction = _mapper.Map<JurisdictionsViewDto>
(await _dbSet.AsNoTracking().FirstOrDefaultAsync(x => x.OrganizationType == OrganizationTypes.LGSub && x.OrganizationId == id));

return jurisdiction;
}

public async Task UpdateJurisdictionAsync(JurisdictionUpdateDto dto)
{
var entity = await _dbSet
.FirstAsync(x => x.OrganizationId == dto.OrganizationId);

_mapper.Map(dto, entity);
}
}
}
13 changes: 13 additions & 0 deletions server/StrDss.Model/OrganizationDtos/JurisdictionUpdateDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace StrDss.Model.OrganizationDtos
{
public class JurisdictionUpdateDto
{
public long OrganizationId { get; set; }
public long? ManagingOrganizationId { get; set; }
public bool? IsPrincipalResidenceRequired { get; set; }
public bool? IsStrProhibited { get; set; }
public bool? IsBusinessLicenceRequired { get; set; }
public string? EconomicRegionDsc { get; set; }
public DateTime UpdDtm { get; set; }
}
}
3 changes: 2 additions & 1 deletion server/StrDss.Model/OrganizationDtos/JurisdictionsViewDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ public class JurisdictionsViewDto
public string OrganizationNm { get; set; } = null!;
[JsonPropertyName("shapeFileId")]
public string OrganizationCd { get; set; } = null!;
public long? ManagingOrganizationId { get; set; }
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; }
public DateTime UpdDtm { get; set; }
}
}
32 changes: 32 additions & 0 deletions server/StrDss.Service/FieldValidatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public Dictionary<string, List<string>> Validate<T>(string entityName, string fi
case FieldTypes.Decimal:
messages.AddRange(ValidateNumberField(rule, val));
break;
case FieldTypes.Bool:
messages.AddRange(ValidateBoolField(rule, val));
break;
default:
throw new NotImplementedException($"Validation for {rule.FieldType} is not implemented.");
}
Expand Down Expand Up @@ -236,5 +239,34 @@ private List<string> ValidateNumberField<T>(FieldValidationRule rule, T val, int

return messages;
}
private List<string> ValidateBoolField<T>(FieldValidationRule rule, T val, int rowNum = 0)
{
var messages = new List<string>();
var rowNumPrefix = rowNum == 0 ? "" : $"Row # {rowNum}: ";
var field = rule.FieldName.WordToWords();

if (rule.Required && val is null)
{
messages.Add($"{rowNumPrefix}{field} field is required.");
return messages;
}

if (!rule.Required && (val is null || val!.ToString()!.IsEmpty()))
return messages;

bool boolVal;
if (val is bool boolValue)
{
boolVal = boolValue;
}
else
{
messages.Add($"{rowNumPrefix}{field} field must be a boolean value (true or false).");
return messages;
}

return messages;
}

}
}
43 changes: 43 additions & 0 deletions server/StrDss.Service/JurisdictionValidationRules.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using StrDss.Common;

namespace StrDss.Service
{
public class JurisdictionValidationRules
{
public static void LoadJurisdictionValidationRules(List<FieldValidationRule> rules)
{
rules.Add(new FieldValidationRule
{
EntityName = Entities.Jurisdiction,
FieldName = JurisdictionFields.IsPrincipalResidenceRequired,
FieldType = FieldTypes.Bool,
Required = true
});

rules.Add(new FieldValidationRule
{
EntityName = Entities.Jurisdiction,
FieldName = JurisdictionFields.IsStrProhibited,
FieldType = FieldTypes.Bool,
Required = true
});

rules.Add(new FieldValidationRule
{
EntityName = Entities.Jurisdiction,
FieldName = JurisdictionFields.IsBusinessLicenceRequired,
FieldType = FieldTypes.Bool,
Required = true
});

rules.Add(new FieldValidationRule
{
EntityName = Entities.Jurisdiction,
FieldName = JurisdictionFields.EconomicRegionDsc,
FieldType = FieldTypes.String,
Required = false,
CodeSet = CodeSet.EconomicRegions,
});
}
}
}
6 changes: 6 additions & 0 deletions server/StrDss.Service/OrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface IOrganizationService
Task<PagedDto<LocalGovViewDto>> GetLocalGovs(int pageSize, int pageNumber, string orderBy, string direction);
Task<LocalGovViewDto?> GetLocalGov(long id);
Task<Dictionary<string, List<string>>> UpdateLocalGovAsync(LocalGovUpdateDto dto);
Task<JurisdictionsViewDto?> GetJurisdiction(long id);
}
public class OrganizationService : ServiceBase, IOrganizationService
{
Expand Down Expand Up @@ -295,5 +296,10 @@ private async Task<Dictionary<string, List<string>>> ValidateLocalGovUpdateDto(L

return errors;
}

public async Task<JurisdictionsViewDto?> GetJurisdiction(long id)
{
return await _orgRepo.GetJurisdiction(id);
}
}
}

0 comments on commit adaa374

Please sign in to comment.