Skip to content

Commit

Permalink
Merge pull request #755 from bcgov/yj
Browse files Browse the repository at this point in the history
Yj
  • Loading branch information
ychung-mot authored Oct 28, 2024
2 parents c7558dd + 4d09043 commit ff669b4
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 7 deletions.
1 change: 1 addition & 0 deletions database/ddl/STR_DSS_Views_Sprint_17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SELECT do2.organization_id
, do2.local_government_type
, lgt.local_government_type_nm
, do2.business_licence_format_txt
, do2.upd_dtm
FROM dss_organization do2
left join dss_local_government_type lgt on lgt.local_government_type = do2.local_government_type
where do2.organization_type = 'LG';
49 changes: 49 additions & 0 deletions postman/str-dss.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,55 @@
}
},
"response": []
},
{
"name": "Get Local Gov",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{host}}/api/organizations/localgovs/6",
"host": [
"{{host}}"
],
"path": [
"api",
"organizations",
"localgovs",
"6"
]
}
},
"response": []
},
{
"name": "Update Local Gov",
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"organizationId\": 6,\r\n \"organizationNm\": \"Test Victoria #1\",\r\n \"localGovernmentType\": \"Municipality\",\r\n \"businessLicenceFormatTxt\": \"XXX\",\r\n \"updDtm\": \"2024-08-20T17:46:27.820716Z\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{host}}/api/organizations/localgovs/6",
"host": [
"{{host}}"
],
"path": [
"api",
"organizations",
"localgovs",
"6"
]
}
},
"response": []
}
],
"auth": {
Expand Down
32 changes: 31 additions & 1 deletion server/StrDss.Api/Controllers/OrganizationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<ActionResult<List<DropdownNumDto>>> GetOrganizationsDropdown(s
/// <param name="longitude">The longitude of the location, must be between -180 and 180 degrees.</param>
/// <param name="latitude">The latitude of the location, must be between -90 and 90 degrees.</param>
/// <returns>An object containing STR requirements for the given location, or a validation error if the input is invalid.</returns>
[ApiAuthorize] //todo: specify permission
[ApiAuthorize(Permissions.RegistryView)]
[SwaggerOperation(Tags = new string[] { Common.ApiTags.Aps })]
[HttpGet("strrequirements", Name = "GetStrRequirements")]
public async Task<ActionResult<StrRequirementsDto>> GetStrRequirements(double longitude, double latitude)
Expand Down Expand Up @@ -190,5 +190,35 @@ public async Task<ActionResult<List<LocalGovViewDto>>> GetJurisdictions(int page
var jurisdictions = await _orgService.GetJurisdictions(pageSize, pageNumber, orderBy, direction);
return Ok(jurisdictions);
}

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

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

return Ok(lg);
}

[ApiAuthorize(Permissions.JurisdictionWrite)]
[HttpPut("localgovs/{id}", Name = "UpdateLocalGov")]
public async Task<ActionResult> UpdateLocalGov(LocalGovUpdateDto dto, long id)
{
dto.OrganizationId = id;

var errors = await _orgService.UpdateLocalGovAsync(dto);

if (errors.Any())
{
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
}

return Ok();
}
}
}
4 changes: 2 additions & 2 deletions server/StrDss.Api/Controllers/RentalListingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public async Task<ActionResult> UploadTakedownConfrimation([FromForm] PlatformDa
return Ok();
}

[ApiAuthorize(Permissions.ListingRead)]
[ApiAuthorize(Permissions.BlLinkWrite)]
[HttpPut("{rentalListingId}/linkbl/{licenceId}")]
public async Task<ActionResult> LinkBizLicence(long rentalListingId, long licenceId)
{
Expand All @@ -226,7 +226,7 @@ public async Task<ActionResult> LinkBizLicence(long rentalListingId, long licenc
return Ok(listing);
}

[ApiAuthorize(Permissions.ListingRead)]
[ApiAuthorize(Permissions.BlLinkWrite)]
[HttpPut("{rentalListingId}/unlinkbl")]
public async Task<ActionResult> UnLinkBizLicence(long rentalListingId)
{
Expand Down
16 changes: 14 additions & 2 deletions server/StrDss.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class Entities
public const string Role = "Role";
public const string BizLicenceRowUntyped = "BizLicenceRowUntyped";
public const string Platform = "Platform";

public const string LocalGov = "LocalGov";
}
public static class Fields
{
Expand Down Expand Up @@ -119,6 +119,15 @@ public static class PlatformFields
public const string PlatformType = "PlatformType";
}

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 CsvCols
{
public const string MostRecentPlatformReportMonth = "Most Recent Platform Report Month";
Expand Down Expand Up @@ -406,6 +415,7 @@ public static class CodeSet
{
public const string LicenceStatus = "Licence Status";
public const string PlatformTypes = "Platform Types";
public const string LocalGovTypes = "Local Gov Types";
}

public static class StrDssIdProviders
Expand Down Expand Up @@ -516,7 +526,9 @@ 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 RegistryView = "registry_view";
public const string BlLinkWrite = "bl_link_write";
public const string JurisdictionRead = "jurisdiction_read";
public const string JurisdictionWrite = "jurisdiction_write";
}

Expand Down
1 change: 1 addition & 0 deletions server/StrDss.Data/Entities/DssDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.OrganizationType)
.HasMaxLength(25)
.HasColumnName("organization_type");
entity.Property(e => e.UpdDtm).HasColumnName("upd_dtm");
});

modelBuilder.Entity<DssLocalGovernmentType>(entity =>
Expand Down
2 changes: 2 additions & 0 deletions server/StrDss.Data/Entities/DssLocalGovVw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public partial class DssLocalGovVw
public string? LocalGovernmentTypeNm { get; set; }

public string? BusinessLicenceFormatTxt { get; set; }

public DateTime? UpdDtm { get; set; }
}
1 change: 1 addition & 0 deletions server/StrDss.Data/Mappings/ModelToEntityProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public ModelToEntityProfile()
CreateMap<PlatformUpdateDto, DssOrganization>();
CreateMap<PlatformSubCreateDto, DssOrganization>();
CreateMap<PlatformSubUpdateDto, DssOrganization>();
CreateMap<LocalGovUpdateDto, DssOrganization>();
}
}
}
12 changes: 12 additions & 0 deletions server/StrDss.Data/Repositories/CodeSetRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public async Task<List<CommonCodeDto>> LoadCodeSetAsync()
}).ToListAsync()
);


commonCodes.AddRange(await
_dbContext.DssLocalGovernmentTypes
.AsNoTracking()
.Select(x => new CommonCodeDto
{
CodeSet = CodeSet.LocalGovTypes,
CodeName = x.LocalGovernmentType,
CodeValue = x.LocalGovernmentTypeNm
}).ToListAsync()
);

return commonCodes;
}
}
Expand Down
17 changes: 17 additions & 0 deletions server/StrDss.Data/Repositories/OrganizationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface IOrganizationRepository
Task<DssOrganization> CreatePlatformSubAsync(PlatformSubCreateDto dto);
Task UpdatePlatformSubAsync(PlatformSubUpdateDto dto);
Task<PagedDto<LocalGovViewDto>> GetJurisdictions(int pageSize, int pageNumber, string orderBy, string direction);
Task UpdateLocalGovAsync(LocalGovUpdateDto dto);
Task<LocalGovViewDto?> GetLocalGov(long id);
}
public class OrganizationRepository : RepositoryBase<DssOrganization>, IOrganizationRepository
{
Expand Down Expand Up @@ -330,5 +332,20 @@ public async Task<PagedDto<LocalGovViewDto>> GetJurisdictions(int pageSize, int

return lgs;
}

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

_mapper.Map(dto, entity);
}

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

return localGov;
}
}
}
11 changes: 11 additions & 0 deletions server/StrDss.Model/OrganizationDtos/LocalGovUpdateDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace StrDss.Model.OrganizationDtos
{
public class LocalGovUpdateDto
{
public long OrganizationId { get; set; }
public string OrganizationNm { get; set; } = "";
public string LocalGovernmentType { get; set; } = "";
public string BusinessLicenceFormatTxt { get; set; } = "";
public DateTime UpdDtm { get; set; }
}
}
2 changes: 2 additions & 0 deletions server/StrDss.Model/OrganizationDtos/LocalGovViewDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public LocalGovViewDto()
}
public long OrganizationId { get; set; }
public string OrganizationNm { get; set; } = "";
public string OrganizationType { get; set; } = "";
public string LocalGovernmentType { get; set; } = "";
public string LocalGovernmentTypeNm { get; set; } = "";
public string OrganizationCd { get; set; } = "";
public string BusinessLicenceFormatTxt { get; set; } = "";
public DateTime UpdDtm { get; set; }
public virtual ICollection<JurisdictionsViewDto> Jurisdictions { get; set; }
}
}
1 change: 1 addition & 0 deletions server/StrDss.Service/FieldValidatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public FieldValidatorService()
RoleValidationRule.LoadReportValidationRules(_rules);
BizLicenceValidationRule.LoadBizLicenceValidationRules(_rules);
PlatformValidationRule.LoadPlatformUpdateValidationRules(_rules);
LocalGovValidationRules.LoadLocalGovValidationRules(_rules);
}

public IEnumerable<FieldValidationRule> GetFieldValidationRules(string entityName)
Expand Down
49 changes: 49 additions & 0 deletions server/StrDss.Service/LocalGovValidationRules.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using StrDss.Common;

namespace StrDss.Service
{
public class LocalGovValidationRules
{
public static void LoadLocalGovValidationRules(List<FieldValidationRule> rules)
{
rules.Add(new FieldValidationRule
{
EntityName = Entities.LocalGov,
FieldName = LocalGovFields.OrganizationCd,
FieldType = FieldTypes.String,
Required = true,
MaxLength = 25,
MinLength = 1,
});

rules.Add(new FieldValidationRule
{
EntityName = Entities.LocalGov,
FieldName = LocalGovFields.OrganizationNm,
FieldType = FieldTypes.String,
Required = true,
MaxLength = 250,
MinLength = 1,
});

rules.Add(new FieldValidationRule
{
EntityName = Entities.LocalGov,
FieldName = LocalGovFields.LocalGovernmentType,
FieldType = FieldTypes.String,
Required = true,
CodeSet = CodeSet.LocalGovTypes,
});

rules.Add(new FieldValidationRule
{
EntityName = Entities.LocalGov,
FieldName = LocalGovFields.BusinessLicenceFormatTxt,
FieldType = FieldTypes.String,
Required = false,
MaxLength = 50,
MinLength = 1,
});
}
}
}
46 changes: 44 additions & 2 deletions server/StrDss.Service/OrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using StrDss.Data.Repositories;
using StrDss.Model;
using StrDss.Model.OrganizationDtos;
using StrDss.Model.UserDtos;
using System.Threading.Tasks;

namespace StrDss.Service
{
Expand All @@ -30,6 +28,8 @@ public interface IOrganizationService
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);
Task<LocalGovViewDto?> GetLocalGov(long id);
Task<Dictionary<string, List<string>>> UpdateLocalGovAsync(LocalGovUpdateDto dto);
}
public class OrganizationService : ServiceBase, IOrganizationService
{
Expand Down Expand Up @@ -253,5 +253,47 @@ public async Task<PagedDto<LocalGovViewDto>> GetJurisdictions(int pageSize, int
{
return await _orgRepo.GetJurisdictions(pageSize, pageNumber, orderBy, direction);
}
public async Task<LocalGovViewDto?> GetLocalGov(long id)
{
return await _orgRepo.GetLocalGov(id);
}

public async Task<Dictionary<string, List<string>>> UpdateLocalGovAsync(LocalGovUpdateDto dto)
{
var errors = new Dictionary<string, List<string>>();

await ValidateLocalGovUpdateDto(dto, errors);

if (errors.Any())
{
return errors;
}

await _orgRepo.UpdateLocalGovAsync(dto);

_unitOfWork.Commit();

return errors;
}

private async Task<Dictionary<string, List<string>>> ValidateLocalGovUpdateDto(LocalGovUpdateDto dto, Dictionary<string, List<string>> errors)
{
var localGov = await _orgRepo.GetLocalGov(dto.OrganizationId);

if (localGov == null)
{
errors.AddItem("OrganizationId", $"Local government with ID {dto.OrganizationId} does not exist");
return errors;
}

if (!_validator.CommonCodes.Any())
{
_validator.CommonCodes = await _codeSetRepo.LoadCodeSetAsync();
}

_validator.Validate(Entities.LocalGov, dto, errors);

return errors;
}
}
}

0 comments on commit ff669b4

Please sign in to comment.