Skip to content

Commit

Permalink
Merge pull request #702 from bcgov/yj
Browse files Browse the repository at this point in the history
chore: added platform types validation rule
  • Loading branch information
ychung-mot authored Oct 15, 2024
2 parents bebeb2e + 4ee9f41 commit eaf050b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/StrDss.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static class PlatformFields
public const string PrimaryTakedownRequestContactEmail = "PrimaryTakedownRequestContactEmail";
public const string SecondaryNoticeOfTakedownContactEmail = "SecondaryNoticeOfTakedownContactEmail";
public const string SecondaryTakedownRequestContactEmail = "SecondaryTakedownRequestContactEmail";
public const string PlatformType = "PlatformType";
}

public static class RentalListingExport
Expand Down Expand Up @@ -235,6 +236,7 @@ public static class FieldTypes
public static class CodeSet
{
public const string LicenceStatus = "Licence Status";
public const string PlatformTypes = "Platform Types";
}

public static class StrDssIdProviders
Expand Down
11 changes: 11 additions & 0 deletions server/StrDss.Data/Repositories/CodeSetRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public async Task<List<CommonCodeDto>> LoadCodeSetAsync()
}).ToListAsync()
);

commonCodes.AddRange(await
_dbContext.DssPlatformTypes
.AsNoTracking()
.Select(x => new CommonCodeDto
{
CodeSet = CodeSet.PlatformTypes,
CodeName = x.PlatformTypeNm,
CodeValue = x.PlatformType
}).ToListAsync()
);

return commonCodes;
}
}
Expand Down
14 changes: 13 additions & 1 deletion server/StrDss.Service/OrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public interface IOrganizationService
public class OrganizationService : ServiceBase, IOrganizationService
{
private IOrganizationRepository _orgRepo;
private ICodeSetRepository _codeSetRepo;

public OrganizationService(ICurrentUser currentUser, IFieldValidatorService validator, IUnitOfWork unitOfWork, IMapper mapper, IHttpContextAccessor httpContextAccessor, ILogger<StrDssLogger> logger,
IOrganizationRepository orgRepo)
IOrganizationRepository orgRepo, ICodeSetRepository codeSetRep)
: base(currentUser, validator, unitOfWork, mapper, httpContextAccessor, logger)
{
_orgRepo = orgRepo;
_codeSetRepo = codeSetRep;
}

public async Task<List<OrganizationTypeDto>> GetOrganizationTypesAsnc()
Expand Down Expand Up @@ -99,6 +101,11 @@ public async Task<PagedDto<PlatformViewDto>> GetPlatforms(int pageSize, int page
private async Task<Dictionary<string, List<string>>> ValidatePlatformCreateDto<T>(IPlatformCreateDto dto, Dictionary<string, List<string>> errors)
where T : class, IPlatformCreateDto
{
if (!_validator.CommonCodes.Any())
{
_validator.CommonCodes = await _codeSetRepo.LoadCodeSetAsync();
}

_validator.Validate(Entities.Platform, (T)dto, errors);

if (errors.Any())
Expand Down Expand Up @@ -143,6 +150,11 @@ private async Task<Dictionary<string, List<string>>> ValidatePlatformUpdateDto<T
return errors;
}

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

_validator.Validate(Entities.Platform, (T)dto, errors);

return errors;
Expand Down
9 changes: 9 additions & 0 deletions server/StrDss.Service/PlatformValidationRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public static void LoadPlatformUpdateValidationRules(List<FieldValidationRule> r
MaxLength = 320,
RegexInfo = RegexDefs.GetRegexInfo(RegexDefs.Email)
});

rules.Add(new FieldValidationRule
{
EntityName = Entities.Platform,
FieldName = PlatformFields.PlatformType,
FieldType = FieldTypes.String,
Required = true,
CodeSet = CodeSet.PlatformTypes,
});
}
}

Expand Down

0 comments on commit eaf050b

Please sign in to comment.