refactor: restructure controllers and update user references for ProgramManager
This commit is contained in:
@@ -10,7 +10,7 @@ using GozareshgirProgramManager.Domain.ProjectAgg.Repositories;
|
||||
using GozareshgirProgramManager.Domain.SalaryPaymentSettingAgg.DTOs;
|
||||
using GozareshgirProgramManager.Domain.SalaryPaymentSettingAgg.Enums;
|
||||
using GozareshgirProgramManager.Domain.SalaryPaymentSettingAgg.Repositories;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
using MediatR;
|
||||
using PersianTools.Core;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -14,10 +14,12 @@ namespace GozareshgirProgramManager.Application.Modules.Checkouts.Queries.GetUse
|
||||
public class GetUserToGroupCreatingQueryHandler : IBaseQueryHandler<GetUserToGroupCreatingQuery, GetUserToGroupCreatingResponse>
|
||||
{
|
||||
private readonly IProgramManagerDbContext _context;
|
||||
private readonly IGozareshgirDbContext _gozareshgirDbContext;
|
||||
|
||||
public GetUserToGroupCreatingQueryHandler(IProgramManagerDbContext context)
|
||||
public GetUserToGroupCreatingQueryHandler(IProgramManagerDbContext context, IGozareshgirDbContext gozareshgirDbContext)
|
||||
{
|
||||
_context = context;
|
||||
_gozareshgirDbContext = gozareshgirDbContext;
|
||||
}
|
||||
|
||||
public async Task<OperationResult<GetUserToGroupCreatingResponse>> Handle(GetUserToGroupCreatingQuery request, CancellationToken cancellationToken)
|
||||
@@ -48,13 +50,14 @@ public class GetUserToGroupCreatingQueryHandler : IBaseQueryHandler<GetUserToGro
|
||||
var lastMonthStart = lastMonth;
|
||||
var lastMonthEnd = lastMonth;
|
||||
|
||||
|
||||
var query =
|
||||
await (from u in _context.Users
|
||||
|
||||
// LEFT JOIN
|
||||
// تنظیمات حقوق
|
||||
join s in _context.SalaryPaymentSettings
|
||||
on u.Id equals s.UserId into sJoin
|
||||
on u.Id equals s.AccountId into sJoin
|
||||
from s in sJoin.DefaultIfEmpty()
|
||||
|
||||
// LEFT JOIN
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CreateSalarySettingsCommandHandler : IBaseCommandHandler<CreateSala
|
||||
public async Task<OperationResult> Handle(CreateSalarySettingsCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if(_salaryPaymentSettingRepository.Exists(x=>x.UserId == request.UserId))
|
||||
if(_salaryPaymentSettingRepository.Exists(x=>x.AccountId == request.UserId))
|
||||
return OperationResult.Failure(" برای این پرسنل قبلا تنظیمات ایجاد شده است");
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GetSalarySettingToEditQueryHandler : IBaseQueryHandler<GetSalarySet
|
||||
{
|
||||
Id = x.Id,
|
||||
HolidayWorking = x.HolidayWorking,
|
||||
UserId = x.UserId,
|
||||
UserId = x.AccountId,
|
||||
MonthlySalary = x.MonthlySalary.ToMoney(),
|
||||
|
||||
WorkingHoursList = x.WorkingHoursList.Select(wh => new WorkingHoursListDto
|
||||
|
||||
@@ -21,7 +21,7 @@ public class GetUserListWhoHaveSettingsQueryHandler : IBaseQueryHandler<GetUserL
|
||||
var query = await (
|
||||
from u in _context.Users
|
||||
join s in _context.SalaryPaymentSettings
|
||||
on u.Id equals s.UserId into settingsGroup
|
||||
on u.Id equals s.AccountId into settingsGroup
|
||||
select new GetUserWhoHaveSettingsDto
|
||||
{
|
||||
UserId = u.Id,
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using GozareshgirProgramManager.Domain.CheckoutAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.CustomerAgg;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.RoleAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.RoleUserAgg;
|
||||
using GozareshgirProgramManager.Domain.SalaryPaymentSettingAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.SkillAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GozareshgirProgramManager.Application._Common.Interfaces;
|
||||
@@ -14,9 +11,6 @@ public interface IProgramManagerDbContext
|
||||
{
|
||||
DbSet<Checkout> Checkouts { set; get; }
|
||||
DbSet<SalaryPaymentSetting?> SalaryPaymentSettings { set; get; }
|
||||
DbSet<Role> Roles { get; set; }
|
||||
DbSet<User> Users { get; set; }
|
||||
DbSet<UserRefreshToken> RefreshTokens { get; set; }
|
||||
DbSet<Customer> Customers { get; }
|
||||
DbSet<Project> Projects { get; set; }
|
||||
DbSet<ProjectPhase> ProjectPhases { get; set; }
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.PermissionAgg.Entities;
|
||||
using System.Security.Principal;
|
||||
using System.Xml.Linq;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.RoleAgg.Entities;
|
||||
|
||||
public class Role : EntityBase<long>
|
||||
{
|
||||
/// <summary>
|
||||
/// نام نقش
|
||||
/// </summary>
|
||||
public string RoleName { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// لیست پرمیشن کد ها
|
||||
/// </summary>
|
||||
public List<Permission> Permissions { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// ای دی نقش در گزارشگیر
|
||||
/// </summary>
|
||||
public long? GozareshgirRoleId { get; private set; }
|
||||
|
||||
|
||||
protected Role()
|
||||
{
|
||||
}
|
||||
|
||||
public Role(string roleName,long? gozareshgirRolId, List<Permission> permissions)
|
||||
{
|
||||
RoleName = roleName;
|
||||
Permissions = permissions;
|
||||
GozareshgirRoleId = gozareshgirRolId;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Edit(string roleName, List<Permission> permissions)
|
||||
{
|
||||
RoleName = roleName;
|
||||
Permissions = permissions;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.RoleAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.RoleAgg.Repositories;
|
||||
|
||||
public interface IRoleRepository : IRepository<long, Role>
|
||||
{
|
||||
Task<Role?> GetByGozareshgirRoleIdAsync(long? gozareshgirRolId);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.RoleUserAgg;
|
||||
|
||||
public class RoleUser
|
||||
{
|
||||
public RoleUser(long roleId)
|
||||
{
|
||||
RoleId = roleId;
|
||||
}
|
||||
|
||||
public long Id { get; private set; }
|
||||
public long RoleId { get; private set; }
|
||||
|
||||
|
||||
public User User { get; set; }
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.SalaryPaymentSettingAgg.Entities;
|
||||
|
||||
@@ -13,13 +12,13 @@ public class SalaryPaymentSetting : EntityBase<long>
|
||||
/// برای اولین بار
|
||||
/// </summary>
|
||||
/// <param name="holidayWorking"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="accountId"></param>
|
||||
/// <param name="monthlySalary"></param>
|
||||
/// <param name="workingHoursList"></param>
|
||||
public SalaryPaymentSetting(bool holidayWorking, long userId, double monthlySalary, List<WorkingHours> workingHoursList)
|
||||
public SalaryPaymentSetting(bool holidayWorking, long accountId, double monthlySalary, List<WorkingHours> workingHoursList)
|
||||
{
|
||||
HolidayWorking = holidayWorking;
|
||||
UserId = userId;
|
||||
AccountId = accountId;
|
||||
MonthlySalary = monthlySalary;
|
||||
WorkingHoursList = workingHoursList;
|
||||
StartSettingDate = new DateTime(2025, 3, 21);
|
||||
@@ -28,14 +27,14 @@ public class SalaryPaymentSetting : EntityBase<long>
|
||||
/// افزودن تنظیمات جدید
|
||||
/// </summary>
|
||||
/// <param name="holidayWorking"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="accountId"></param>
|
||||
/// <param name="monthlySalary"></param>
|
||||
/// <param name="workingHoursList"></param>
|
||||
/// <param name="startSettingDate"></param>
|
||||
public SalaryPaymentSetting(bool holidayWorking, long userId, List<WorkingHours> workingHoursList, DateTime startSettingDate)
|
||||
public SalaryPaymentSetting(bool holidayWorking, long accountId, List<WorkingHours> workingHoursList, DateTime startSettingDate)
|
||||
{
|
||||
HolidayWorking = holidayWorking;
|
||||
UserId = userId;
|
||||
AccountId = accountId;
|
||||
|
||||
WorkingHoursList = workingHoursList;
|
||||
StartSettingDate = startSettingDate;
|
||||
@@ -56,7 +55,7 @@ public class SalaryPaymentSetting : EntityBase<long>
|
||||
/// <summary>
|
||||
/// آی دی کاربر
|
||||
/// </summary>
|
||||
public long UserId { get; private set; }
|
||||
public long AccountId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// دستمزد ماهانه
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.PermissionAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.RoleAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.RoleUserAgg;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// کاربر
|
||||
/// </summary>
|
||||
public class User : EntityBase<long>
|
||||
{
|
||||
/// <summary>
|
||||
/// ایجاد
|
||||
/// </summary>
|
||||
/// <param name="fullName"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <param name="mobile"></param>
|
||||
/// <param name="email"></param>
|
||||
/// <param name="accountId"></param>
|
||||
/// <param name="roles"></param>
|
||||
public User(string fullName, string userName, string password, string mobile, string? email, long? accountId, List<RoleUser> roles)
|
||||
{
|
||||
FullName = fullName;
|
||||
UserName = userName;
|
||||
Password = password;
|
||||
Mobile = mobile;
|
||||
Email = email;
|
||||
IsActive = true;
|
||||
AccountId = accountId;
|
||||
RoleUser = roles;
|
||||
}
|
||||
|
||||
protected User()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// نام و نام خانوادگی
|
||||
/// </summary>
|
||||
public string FullName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// نام کاربری
|
||||
/// </summary>
|
||||
public string UserName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// گذرواژه
|
||||
/// </summary>
|
||||
public string Password { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// مسیر عکس پروفایل
|
||||
/// </summary>
|
||||
public string ProfilePhotoPath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// شماره موبایل
|
||||
/// </summary>
|
||||
public string Mobile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ایمیل
|
||||
/// </summary>
|
||||
public string? Email { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// فعال/غیر فعال بودن یوزر
|
||||
/// </summary>
|
||||
public bool IsActive { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// کد یکبارمصرف ورود
|
||||
/// </summary>
|
||||
public string? VerifyCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// آی دی کاربر در گزارشگیر
|
||||
/// </summary>
|
||||
public long? AccountId { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// لیست پرمیشن کد ها
|
||||
/// </summary>
|
||||
public List<RoleUser> RoleUser { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// لیست توکنهای تازهسازی
|
||||
/// </summary>
|
||||
private List<UserRefreshToken> _refreshTokens = new();
|
||||
public IReadOnlyCollection<UserRefreshToken> RefreshTokens => _refreshTokens.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// آپدیت کاربر
|
||||
/// </summary>
|
||||
/// <param name="fullName"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="mobile"></param>
|
||||
/// <param name="roles"></param>
|
||||
/// <param name="isActive"></param>
|
||||
public void Edit(string fullName, string userName, string mobile, List<RoleUser> roles, bool isActive)
|
||||
{
|
||||
FullName = fullName;
|
||||
UserName = userName;
|
||||
Mobile = mobile;
|
||||
RoleUser = roles;
|
||||
IsActive = isActive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// غیرفعال سازی
|
||||
/// </summary>
|
||||
public void DeActive()
|
||||
{
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// فعال سازی
|
||||
/// </summary>
|
||||
public void ReActive()
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// افزودن توکن تازهسازی
|
||||
/// </summary>
|
||||
public void AddRefreshToken(string token, DateTime expiresAt, string? ipAddress = null, string? userAgent = null)
|
||||
{
|
||||
var refreshToken = new UserRefreshToken(Id, token, expiresAt, ipAddress, userAgent);
|
||||
_refreshTokens.Add(refreshToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// لغو توکن تازهسازی
|
||||
/// </summary>
|
||||
public void RevokeRefreshToken(string token)
|
||||
{
|
||||
var refreshToken = _refreshTokens.FirstOrDefault(x => x.Token == token);
|
||||
if (refreshToken == null)
|
||||
throw new InvalidOperationException("توکن یافت نشد");
|
||||
|
||||
refreshToken.Revoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// لغو تمام توکنهای فعال
|
||||
/// </summary>
|
||||
public void RevokeAllRefreshTokens()
|
||||
{
|
||||
foreach (var token in _refreshTokens.Where(x => x.IsActive))
|
||||
{
|
||||
token.Revoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// پاکسازی توکنهای منقضی شده
|
||||
/// </summary>
|
||||
public void RemoveExpiredRefreshTokens()
|
||||
{
|
||||
_refreshTokens.RemoveAll(x => !x.IsActive);
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// توکن تازهسازی برای احراز هویت
|
||||
/// </summary>
|
||||
public class UserRefreshToken : EntityBase<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// سازنده محافظت شده برای EF Core
|
||||
/// </summary>
|
||||
protected UserRefreshToken()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ایجاد توکن تازهسازی
|
||||
/// </summary>
|
||||
public UserRefreshToken(long userId, string token, DateTime expiresAt, string? ipAddress = null, string? userAgent = null)
|
||||
{
|
||||
UserId = userId;
|
||||
Token = token;
|
||||
ExpiresAt = expiresAt;
|
||||
IpAddress = ipAddress;
|
||||
UserAgent = userAgent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// شناسه کاربر
|
||||
/// </summary>
|
||||
public long UserId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// توکن تازهسازی
|
||||
/// </summary>
|
||||
public string Token { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// تاریخ انقضا
|
||||
/// </summary>
|
||||
public DateTime ExpiresAt { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// تاریخ لغو
|
||||
/// </summary>
|
||||
public DateTime? RevokedAt { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// آیپی کاربر
|
||||
/// </summary>
|
||||
public string? IpAddress { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// User Agent مرورگر
|
||||
/// </summary>
|
||||
public string? UserAgent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// آیا منقضی شده؟
|
||||
/// </summary>
|
||||
public bool IsExpired => DateTime.Now >= ExpiresAt;
|
||||
|
||||
/// <summary>
|
||||
/// آیا لغو شده؟
|
||||
/// </summary>
|
||||
public bool IsRevoked => RevokedAt.HasValue;
|
||||
|
||||
/// <summary>
|
||||
/// آیا فعال است؟
|
||||
/// </summary>
|
||||
public bool IsActive => !IsRevoked && !IsExpired;
|
||||
|
||||
/// <summary>
|
||||
/// لغو توکن
|
||||
/// </summary>
|
||||
public void Revoke()
|
||||
{
|
||||
if (IsRevoked)
|
||||
throw new InvalidOperationException("توکن قبلاً لغو شده است");
|
||||
|
||||
RevokedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// کاربر صاحب توکن
|
||||
/// </summary>
|
||||
public User User { get; private set; }
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.UserAgg.Events;
|
||||
|
||||
public record UserCreatedEvent(long UserId, string FirstName, string LastName, string Email) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public record UserPersonalInfoUpdatedEvent(long UserId, string OldFirstName, string OldLastName, string NewFirstName, string NewLastName) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public record UserEmailUpdatedEvent(long UserId, string OldEmail, string NewEmail) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public record UserWorkInfoUpdatedEvent(long UserId, string? Department, string? Position) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public record UserDeactivatedEvent(long UserId, string? Reason) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public record UserActivatedEvent(long UserId) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public record UserLoggedInEvent(long UserId, DateTime LoginTime) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.UserAgg.Repositories;
|
||||
|
||||
public interface IUserRefreshTokenRepository : IRepository<Guid, UserRefreshToken>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.UserAgg.Entities;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.UserAgg.Repositories;
|
||||
|
||||
public interface IUserRepository: IRepository<long, User>
|
||||
{
|
||||
Task<User?> GetByIdAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// یافتن کاربر با آی دی اکانت گزارشگیر او
|
||||
/// </summary>
|
||||
/// <param name="accountId"></param>
|
||||
/// <returns></returns>
|
||||
Task<User?> GetByGozareshgirAccountId(long accountId);
|
||||
Task<User?> GetByEmailAsync(string email);
|
||||
Task<User?> GetByMobileAsync(string mobile);
|
||||
Task<IEnumerable<User>> GetAllAsync();
|
||||
Task<IEnumerable<User>> GetActiveUsersAsync();
|
||||
|
||||
Task<User> AddAsync(User user);
|
||||
void Update(User user);
|
||||
void Delete(User user);
|
||||
Task<bool> ExistsAsync(long id);
|
||||
Task<bool> UsernameExistsAsync(string username);
|
||||
Task<bool> EmailExistsAsync(string email);
|
||||
Task<bool> MobileExistsAsync(string mobile);
|
||||
Task<User?> GetUserWithRolesByIdAsync(long userId, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,13 +31,9 @@ public class ProgramManagerDbContext : DbContext, IProgramManagerDbContext
|
||||
|
||||
public DbSet<TaskSectionActivity> TaskSectionActivities { get; set; } = null!;
|
||||
public DbSet<TaskSectionAdditionalTime> TaskSectionAdditionalTimes { get; set; } = null!;
|
||||
|
||||
public DbSet<User> Users { get; set; } = null!;
|
||||
public DbSet<UserRefreshToken> RefreshTokens { get; set; } = null!;
|
||||
|
||||
public DbSet<Checkout> Checkouts { get; set; } = null!;
|
||||
public DbSet<SalaryPaymentSetting?> SalaryPaymentSettings { get; set; } = null!;
|
||||
public DbSet<Role> Roles { get; set; } = null!;
|
||||
|
||||
public DbSet<Skill> Skills { get; set; } = null!;
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
|
||||
@@ -19,16 +19,16 @@ public class SalaryPaymentSettingRepository : RepositoryBase<long, SalaryPayment
|
||||
|
||||
public async Task<SalaryPaymentSetting?> GetSalarySettingByUserId(long userId)
|
||||
{
|
||||
return await _context.SalaryPaymentSettings.FirstOrDefaultAsync(x => x.UserId == userId);
|
||||
return await _context.SalaryPaymentSettings.FirstOrDefaultAsync(x => x.AccountId == userId);
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<UserSalarySettingDto>> GetAllSettings(List<long> userIdList)
|
||||
{
|
||||
_context.SalaryPaymentSettings.AsNoTracking();
|
||||
var query = await _context.SalaryPaymentSettings.Where(s=> userIdList.Contains(s.UserId))
|
||||
var query = await _context.SalaryPaymentSettings.Where(s=> userIdList.Contains(s.AccountId))
|
||||
.Join(_context.Users.AsNoTracking(),
|
||||
setting => setting.UserId,
|
||||
setting => setting.AccountId,
|
||||
user => user.Id,
|
||||
(setting, user) => new { setting, user }
|
||||
)
|
||||
|
||||
@@ -9,14 +9,12 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
/// <summary>
|
||||
/// کنترلر احراز هویت
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class AuthController :AdminBaseController
|
||||
public class AuthController : ProgramManagerBaseController
|
||||
{
|
||||
private readonly IAuthHelper _authHelper;
|
||||
private readonly IMediator _mediator;
|
||||
@@ -7,9 +7,9 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
public class CheckoutController : AdminBaseController
|
||||
public class CheckoutController : ProgramManagerBaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
@@ -14,9 +14,9 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
public class ProjectController : AdminBaseController
|
||||
public class ProjectController : ProgramManagerBaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application.Modules.Roles.Commands.CreateRole;
|
||||
using GozareshgirProgramManager.Application.Modules.Roles.Commands.EditRole;
|
||||
using GozareshgirProgramManager.Application.Modules.Roles.Queries.GetRoles;
|
||||
@@ -6,9 +6,9 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
public class RoleController : AdminBaseController
|
||||
public class RoleController : ProgramManagerBaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application.Modules.SalaryPaymentSettings.Commands.CreateSalarySettings;
|
||||
using GozareshgirProgramManager.Application.Modules.SalaryPaymentSettings.Commands.EditSalarySettings;
|
||||
using GozareshgirProgramManager.Application.Modules.SalaryPaymentSettings.Queries.GetSalarySettingToEdit;
|
||||
@@ -8,9 +8,9 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
public class SalaryPaymentSettingsController : AdminBaseController
|
||||
public class SalaryPaymentSettingsController : ProgramManagerBaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
@@ -4,9 +4,9 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
public class SkillController:AdminBaseController
|
||||
public class SkillController : ProgramManagerBaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application.Modules.Users.Commands.CreateUser;
|
||||
using GozareshgirProgramManager.Application.Modules.Users.Commands.EditUser;
|
||||
using GozareshgirProgramManager.Application.Modules.Users.Queries.GetSingleUser;
|
||||
@@ -8,9 +8,9 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
public class UserController : AdminBaseController
|
||||
public class UserController : ProgramManagerBaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
13
ServiceHost/BaseControllers/ProgramManagerBaseController.cs
Normal file
13
ServiceHost/BaseControllers/ProgramManagerBaseController.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace ServiceHost.BaseControllers;
|
||||
|
||||
[Authorize(Policy = "AdminArea")]
|
||||
[Area("Admin")]
|
||||
[ApiExplorerSettings(GroupName = "ProgramManager")]
|
||||
[Route("api/admin/programmanager/[controller]")]
|
||||
public class ProgramManagerBaseController:ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -242,36 +242,38 @@ builder.Services.AddSwaggerGen(options =>
|
||||
options.SwaggerDoc("Admin", new OpenApiInfo { Title = "API - Admin", Version = "v1" });
|
||||
options.SwaggerDoc("Client", new OpenApiInfo { Title = "API - Client", Version = "v1" });
|
||||
options.SwaggerDoc("Camera", new OpenApiInfo { Title = "API - Camera", Version = "v1" });
|
||||
options.SwaggerDoc("ProgramManager", new OpenApiInfo { Title = "API - ProgramManager", Version = "v1" });
|
||||
|
||||
|
||||
options.DocInclusionPredicate((docName, apiDesc) =>
|
||||
string.Equals(docName, apiDesc.GroupName, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
|
||||
// اضافه کردن پشتیبانی از JWT در Swagger
|
||||
options.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
|
||||
{
|
||||
Name = "Authorization",
|
||||
Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer",
|
||||
BearerFormat = "JWT",
|
||||
In = Microsoft.OpenApi.Models.ParameterLocation.Header,
|
||||
Description = "لطفاً 'Bearer [space] token' را وارد کنید."
|
||||
});
|
||||
|
||||
options.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new Microsoft.OpenApi.Models.OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new Microsoft.OpenApi.Models.OpenApiReference
|
||||
{
|
||||
Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
Array.Empty<string>()
|
||||
}
|
||||
});
|
||||
// // اضافه کردن پشتیبانی از JWT در Swagger
|
||||
// options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
// {
|
||||
// Name = "Authorization",
|
||||
// Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey,
|
||||
// Scheme = "Bearer",
|
||||
// BearerFormat = "JWT",
|
||||
// In = Microsoft.OpenApi.Models.ParameterLocation.Header,
|
||||
// Description = "لطفاً 'Bearer [space] token' را وارد کنید."
|
||||
// });
|
||||
//
|
||||
// options.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement
|
||||
// {
|
||||
// {
|
||||
// new Microsoft.OpenApi.Models.OpenApiSecurityScheme
|
||||
// {
|
||||
// Reference = new Microsoft.OpenApi.Models.OpenApiReference
|
||||
// {
|
||||
// Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme,
|
||||
// Id = "Bearer"
|
||||
// }
|
||||
// },
|
||||
// Array.Empty<string>()
|
||||
// }
|
||||
// });
|
||||
|
||||
options.EnableAnnotations();
|
||||
});
|
||||
@@ -405,6 +407,7 @@ if (app.Environment.IsDevelopment())
|
||||
options.DocExpansion(DocExpansion.None);
|
||||
options.SwaggerEndpoint("/swagger/General/swagger.json", "API - General");
|
||||
options.SwaggerEndpoint("/swagger/Admin/swagger.json", "API - Admin");
|
||||
options.SwaggerEndpoint("/swagger/ProgramManager/swagger.json", "API - ProgramManager");
|
||||
options.SwaggerEndpoint("/swagger/Client/swagger.json", "API - Client");
|
||||
options.SwaggerEndpoint("/swagger/Camera/swagger.json", "API - Camera");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user