Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Application/ApplicationServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Application.Features.Auth.Services;
using Application.Features.Service.Services;
using Application.Features.Tenant.Services;
using Domain.Interfaces;
using Microsoft.Extensions.DependencyInjection;
namespace Application;

Expand All @@ -16,6 +17,7 @@ public static IServiceCollection AddApplication(this IServiceCollection services
services.AddScoped<IUserService,UserService>();
services.AddScoped<IPasswordRecoveryService, PasswordRecoveryService>();
services.AddScoped<TenantServiceContract,TenantService>();
services.AddScoped<TenantProviderContract, TenantProvider>();
return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Application.Features.Tenant.Interfaces;

public interface TenantContextContract
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ namespace Application.Features.Tenant.Interfaces;
public interface TenantRepositoryContract
{
Task RegisterTenant(Domain.Entities.Tenant tenant);
Task<Domain.Entities.Tenant> GetCurrentTenantAsync();
Task<bool> IsSubscriptionValidAsync();
Task SaveAsync();
}
10 changes: 10 additions & 0 deletions Application/Features/Tenant/Services/TenantProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Domain.Interfaces;

namespace Application.Features.Tenant.Services;

public class TenantProvider : TenantProviderContract
{
private Guid _tenantId;
public Guid GetTenantId() => _tenantId;
public void SetTenantId(Guid tenantId) => _tenantId = tenantId;
}
5 changes: 3 additions & 2 deletions Application/Features/Tenant/Services/TenantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<string> Register(RegisterTenantDTO dto)
// Todo : Date manager
// Todo : if for duplicate slug
var tenant = new Domain.Entities.Tenant(dto.Name,dto.Slug,dto.SubscriptionExpireDate);

var userId=_userContext.UserId;
var user = await _userRepository.GetUserByIdAsync(userId);

Expand All @@ -40,7 +40,8 @@ public async Task<string> Register(RegisterTenantDTO dto)
user.ChangeRoleTo(UserRole.Admin);
user.AssignTenantToUser(tenant.Id);
await _tenantRepository.SaveAsync();


var tenantId = await _tenantRepository.GetCurrentTenantAsync();
return $"{tenant.Name} Registered belong to user {user.FullName} created";
}
}
3 changes: 2 additions & 1 deletion Domain/Entities/Appointment.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Domain.Enums;
using Domain.Interfaces;

namespace Domain.Entities
{
public class Appointment
public class Appointment:TenantEntityContract
{
public Guid AppointmentId { get; private set; }
public Guid UserId { get; private set; }
Expand All @@ -11,12 +12,12 @@
public DateTime StartTime { get; private set; }
public DateTime EndTime { get; private set; }
public AppointmentStatus Status { get; private set; }
public Guid TenantId { get; set; }

Check warning on line 15 in Domain/Entities/Appointment.cs

View workflow job for this annotation

GitHub Actions / build

'Appointment.TenantId' hides inherited member 'TenantEntityContract.TenantId'. Use the new keyword if hiding was intended.
public Tenant Tenant { get; set; }

public ICollection<AppointmentServiceLink> AppointmentServices { get; private set; } = new List<AppointmentServiceLink>();

private Appointment() { } // For EF

Check warning on line 20 in Domain/Entities/Appointment.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Tenant' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 20 in Domain/Entities/Appointment.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Title' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public Appointment(Guid userId, DateTime startTime, DateTime endTime, string title)
{
Expand Down
6 changes: 4 additions & 2 deletions Domain/Entities/Refreshtoken.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using Domain.Interfaces;

namespace Domain.Entities;

public class RefreshToken
public class RefreshToken:TenantEntityContract
{
public Guid Id { get; set; }

public string Token { get; set; } = null!;
public DateTime ExpiresAt { get; set; }
public bool IsRevoked { get; set; }

public Guid TenantId { get; set; }

Check warning on line 12 in Domain/Entities/Refreshtoken.cs

View workflow job for this annotation

GitHub Actions / build

'RefreshToken.TenantId' hides inherited member 'TenantEntityContract.TenantId'. Use the new keyword if hiding was intended.
public Guid UserId { get; set; }
public User User { get; set; } = null!;
}
4 changes: 3 additions & 1 deletion Domain/Entities/Service.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Domain.Interfaces;

namespace Domain.Entities;

public class Service
public class Service:TenantEntityContract
{
public Guid Id { get; private set; }
public string Title { get; private set; }
public int DurationMinutes { get; private set; }
public Guid TenantId { get; set; }

Check warning on line 10 in Domain/Entities/Service.cs

View workflow job for this annotation

GitHub Actions / build

'Service.TenantId' hides inherited member 'TenantEntityContract.TenantId'. Use the new keyword if hiding was intended.
public Tenant Tenant { get; set; }
public ICollection<AppointmentServiceLink> AppointmentServices { get; set; }=new List<AppointmentServiceLink>();

Expand Down
3 changes: 2 additions & 1 deletion Domain/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Domain.Enums;
using Domain.Interfaces;

namespace Domain.Entities;

public class User
public class User:TenantEntityContract
{
public Guid Id { get; private set; }
public string FullName { get; private set; }
Expand All @@ -13,12 +14,12 @@
public string? PasswordResetCodeHash { get; private set; }
public DateTime? PasswordResetCodeExpireAt { get; private set; }
public int PasswordResetAttemptsCount { get; private set; }
public Guid? TenantId { get; private set; }

Check warning on line 17 in Domain/Entities/User.cs

View workflow job for this annotation

GitHub Actions / build

'User.TenantId' hides inherited member 'TenantEntityContract.TenantId'. Use the new keyword if hiding was intended.
public Tenant? Tenant { get; set; }
public ICollection<RefreshToken> RefreshTokens { get; private set; } = new List<RefreshToken>();
public ICollection<Appointment> Appointments { get; private set; } = new List<Appointment>();

public User()

Check warning on line 22 in Domain/Entities/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 22 in Domain/Entities/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'PhoneNumber' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 22 in Domain/Entities/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Email' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 22 in Domain/Entities/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'FullName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
}

Expand Down
6 changes: 6 additions & 0 deletions Domain/Interfaces/TenantEntityContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Domain.Interfaces;

public class TenantEntityContract
{
public Guid TenantId { get; set; }
}
7 changes: 7 additions & 0 deletions Domain/Interfaces/TenantProviderContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Domain.Interfaces;

public interface TenantProviderContract
{
Guid GetTenantId();
void SetTenantId(Guid tenantId);
}
Loading
Loading