Skip to content

Commit

Permalink
refactor seperate endpointConstants to single EndpointConstants class
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Jan 15, 2025
1 parent bfae135 commit 2738563
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
8 changes: 0 additions & 8 deletions Source/Shared/Features/EFCore/DbSetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ public static async Task<TEntity> GetEntityAsync<TEntity>(this DbSet<TEntity> db
{
throw Error.NotFound(typeof(TEntity).Name, entityId);
}
if (entity.TenantId != owningTenantId)
{
throw Error.UnAuthorized;
}

return entity;
}
Expand All @@ -29,10 +25,6 @@ public static async Task<TEntity> GetEntityAsync<TEntity, TSecond>(this IIncluda
{
throw Error.NotFound(typeof(TEntity).Name, entityId);
}
if (entity.TenantId != tenantId)
{
throw Error.UnAuthorized;
}

return entity;
}
Expand Down
6 changes: 6 additions & 0 deletions Source/Shared/Features/EFCore/ExecutionContextInterceptor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Shared.Features.Misc.Domain;
using Shared.Features.Misc.Errors;
using Shared.Features.Misc.ExecutionContext;

namespace Shared.Features.EFCore
Expand All @@ -16,6 +17,11 @@ public object InitializedInstance(
entity.ExecutionContext = materializationData
.Context
.GetService<IExecutionContext>();

if (entity.TenantId != entity.ExecutionContext.TenantId)
{
throw Error.UnAuthorized;
}
}

return instance;
Expand Down
23 changes: 23 additions & 0 deletions Source/Shared/Kernel/Constants/EndpointConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Shared.Kernel.Constants
{
public class EndpointConstants
{
public static class TenantIdentity
{
public const string UsersEndpoint = "/api/users";
public const string IdentityOperationsEndpoint = "/api/identityoperations";

public const string IdentityAccountPath = "/Identity/Account";
public const string SignUpPath = "Identity/SignUp";
public const string LoginPath = "Identity/Login";
public const string LogoutPath = "api/user/Logout";
public const string UserClaimsPath = "api/user";
}

public static class Subscriptions
{
public const string StripePremiumSubscriptionPath = "/api/stripe/subscribe/premium";
public const string StripeEnterpriseSubscriptionPath = "/api/stripe/subscribe/enterprise";
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using System.Threading.Tasks;
using System;
using System.Net.Http.Json;
using Shared.Kernel.Constants.Endpoints;
using Modules.TenantIdentity.Public.DTOs.IdentityOperations;
using Shared.Kernel.Constants.Auth;
using Shared.Kernel.Constants;

namespace Web.Client.BuildingBlocks.Auth
{
Expand Down

0 comments on commit 2738563

Please sign in to comment.