Skip to content

Commit

Permalink
Reformatted error class usage
Browse files Browse the repository at this point in the history
  • Loading branch information
typecastcloud committed Jul 23, 2024
1 parent c14f154 commit 735b100
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData)

if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !Company.IsMatch(invitationData.OrganisationName))
{
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName");
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName");
}

return ExecuteInvitationInternalAsync(invitationData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task HandlePartnerRegistration(PartnerRegistrationData data)
{
if (!string.IsNullOrEmpty(data.Name) && !Company.IsMatch(data.Name))
{
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName");
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName");
}
var ownerCompanyId = _identityData.CompanyId;
var networkRepository = _portalRepositories.GetInstance<INetworkRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
}
if (!string.IsNullOrEmpty(companyWithAddress.Name) && !Company.IsMatch(companyWithAddress.Name))
{
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName");
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName");
}

return new CompanyWithAddressData(
Expand Down Expand Up @@ -146,7 +146,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
{
if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName));
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName));
}
var applications = _portalRepositories.GetInstance<IApplicationRepository>()
.GetCompanyApplicationsFilteredQuery(
Expand Down Expand Up @@ -185,7 +185,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
{
if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName));
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName));
}
var applications = _portalRepositories.GetInstance<IApplicationRepository>().GetAllCompanyApplicationsDetailsQuery(companyName);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models;

// This class contains error messages for validation expressions
public static class ValidationExpressionErrorMessages
{
public const string CompanyError = "length must be between 1 and 160 characters and not start or end with a white space";
}
1 change: 0 additions & 1 deletion src/framework/Framework.Models/ValidationExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ public static class ValidationExpressions
public const string Name = @"^.+$";
public const string Bpn = @"^(BPNL|bpnl)[\w|\d]{12}$";
public const string Company = @"^(?!.*\s$)([\wÀ-ÿ£$€¥¢@%*+\-/\\,.:;=<>!?&^#'\x22()[\]]\s?){1,160}$";
public const string CompanyError = "length must be between 1 and 160 characters and not start or end with a white space";
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Task<Guid> AddAppAsync(AppRequestModel appRequestModel)

if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider))
{
throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider));
throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider));
}

return CreateAppAsync(appRequestModel);
Expand Down Expand Up @@ -271,7 +271,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo

if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider))
{
throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider));
throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider));
}

if (appRequestModel.SalesManagerId.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId)
{
if (!string.IsNullOrWhiteSpace(companyName) && !Company.IsMatch(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}");
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}");
}

async Task<Pagination.Source<OfferCompanySubscriptionStatusResponse>?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Task<OfferAutoSetupResponseData> AutoSetupServiceAsync(OfferAutoSetupData
{
if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}");
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}");
}
async Task<Pagination.Source<OfferCompanySubscriptionStatusResponse>?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take)
{
Expand Down

0 comments on commit 735b100

Please sign in to comment.