Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HaikAsatryan committed Jul 4, 2024
1 parent c31026d commit e6323fc
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class SwaggerOptions
{
public Dictionary<string, SwaggerVersionOptions> Versions { get; set; } = null!;
public required Dictionary<string, SwaggerVersionOptions> Versions { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class SwaggerVersionOptions
{
public string Title { get; set; } = null!;
public string Description { get; set; } = null!;
public required string Title { get; set; }
public required string Description { get; set; }

public bool Separate { get; set; }
public string? RoutePrefix { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task Handle(AuthQuery request, CancellationToken cancellationToken)
var tokenEntity = await unitOfWork.Tokens.GetTokenByAccessTokenAsync(accessTokenHash, cancellationToken);

UnauthorizedException.ThrowIfNull(tokenEntity);
UnauthorizedException.ThrowIf(tokenEntity.User.Status is not UserStatus.Active);
UnauthorizedException.ThrowIf(tokenEntity.User!.Status is not UserStatus.Active);
UnauthorizedException.ThrowIf(tokenEntity.AccessTokenExpiresAt <= DateTime.UtcNow,
ErrorMessages.AccessTokenIsExpired);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void ValidateUserToken(Token? userToken, DateTime now)
{
NotFoundException.ThrowIfNull(userToken);

UnauthorizedException.ThrowIf(userToken.User.Status != UserStatus.Active,
UnauthorizedException.ThrowIf(userToken.User!.Status != UserStatus.Active,
ErrorMessages.ThisUserIsNotAllowedToPerformThisAction);

UnauthorizedException.ThrowIf(userToken.RefreshTokenExpiresAt < now, ErrorMessages.RefreshTokenExpired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class IdentityCookies
{
public string AccessTokenSignature { get; set; } = null!;
public string RefreshTokenSignature { get; set; } = null!;
public required string AccessTokenSignature { get; set; }
public required string RefreshTokenSignature { get; set; }
public DateTime AccessTokenExpiresAt { get; set; }
public DateTime RefreshTokenExpiresAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class LoginCommandResponse

public bool ForcePasswordChange { get; set; }
public UserRole UserRole { get; set; }
public string AccessTokenSignature { get; set; } = null!;
public required string AccessTokenSignature { get; set; }
public DateTime AccessTokenExpiration { get; set; }
public string RefreshTokenSignature { get; set; } = null!;
public required string RefreshTokenSignature { get; set; }
public DateTime RefreshTokenExpiration { get; set; }

public static LoginCommandResponse MapFromEntity(CreateTokenCommandResponse token, UserRole userRole,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class RefreshTokenCommandResponse
[PropertyBaseConverter] public long UserId { get; set; }
public bool ForcePasswordChange { get; set; }
public UserRole UserRole { get; set; }
public string AccessTokenSignature { get; set; } = null!;
public required string AccessTokenSignature { get; set; }
public DateTime AccessTokenExpiration { get; set; }
public string RefreshTokenSignature { get; set; } = null!;
public required string RefreshTokenSignature { get; set; }
public DateTime RefreshTokenExpiration { get; set; }

public static RefreshTokenCommandResponse MapFromTokenEntity(Token token,
Expand All @@ -20,7 +20,7 @@ public static RefreshTokenCommandResponse MapFromTokenEntity(Token token,
return new RefreshTokenCommandResponse
{
UserId = token.UserId,
ForcePasswordChange = oldToken.User.ForcePasswordChange,
ForcePasswordChange = oldToken.User!.ForcePasswordChange,
UserRole = oldToken.User.Role,
AccessTokenSignature = accessTokenSignature,
AccessTokenExpiration = token.AccessTokenExpiresAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task Handle(CreateUserCommand request, CancellationToken cancellati
FullName = request.FullName,
PasswordHash = passwordHash,
Role = request.UserRole,
Comment = request.Comment,
Comment = request.Comment ?? "",
CreatedByUserId = requestContext.Identity.UserId
};
unitOfWork.Users.Add(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Pandatech.CleanArchitecture.Application.Features.User.Application.Dele

public class DeleteUsersCommand : ICommand
{
[PropertyBaseConverter] public List<long> Ids { get; set; } = null!;
[PropertyBaseConverter] public required List<long> Ids { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class UpdateUserCommand : ICommand
{
[JsonIgnore] public long Id { get; set; }

public string Username { get; set; } = null!;
public string FullName { get; set; } = null!;
public required string Username { get; set; }
public required string FullName { get; set; }
public UserRole Role { get; set; }
public string? Comment { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task Handle(UpdateUserCommand request, CancellationToken cancellati
user.Username = username;
user.FullName = request.FullName;
user.Role = request.Role;
user.Comment = request.Comment;
user.Comment = request.Comment ?? "";
user.MarkAsUpdated(requestContext.Identity.UserId);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class UpdateUserPasswordCommand : ICommand
{
[JsonIgnore] public long Id { get; set; }

public string NewPassword { get; set; } = null!;
public required string NewPassword { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Pandatech.CleanArchitecture.Application.Features.User.Contracts.GetByI
public class GetUserQueryResponse
{
[PropertyBaseConverter] public long Id { get; set; }
public string Username { get; set; } = null!;
public string FullName { get; set; } = null!;
public required string Username { get; set; }
public required string FullName { get; set; }
public UserRole Role { get; set; }
public UserStatus Status { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public string? Comment { get; set; }
public string Comment { get; set; } = "";

public static GetUserQueryResponse MapFromEntity(Core.Entities.User entity)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Pandatech.CleanArchitecture.Core/DTOs/Auth/Identity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace Pandatech.CleanArchitecture.Core.DTOs.Auth;
public class Identity
{
public long UserId { get; set; }
public string Username { get; set; } = null!;
public required string Username { get; set; }
public UserStatus Status { get; set; }
public bool ForcePasswordChange { get; set; }
public string FullName { get; set; } = null!;
public required string FullName { get; set; }
public UserRole UserRole { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public long TokenId { get; set; }
public string AccessTokenSignature { get; set; } = null!;
public required string AccessTokenSignature { get; set; }
public DateTime AccessTokenExpiration { get; set; }
}
2 changes: 1 addition & 1 deletion src/Pandatech.CleanArchitecture.Core/DTOs/Auth/MetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Pandatech.CleanArchitecture.Core.DTOs.Auth;

public class MetaData
{
public string RequestId { get; set; } = null!;
public required string RequestId { get; set; }
public DateTime RequestTime { get; set; }
public SupportedLanguageType LanguageId { get; set; }
public ClientType ClientType { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/Pandatech.CleanArchitecture.Core/Entities/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ public class Token
public long Id { get; set; }
public long UserId { get; set; }
public long? PreviousTokenId { get; set; }
public byte[] AccessTokenHash { get; set; } = null!;
public byte[] RefreshTokenHash { get; set; } = null!;
public required byte[] AccessTokenHash { get; set; }
public required byte[] RefreshTokenHash { get; set; }
public DateTime AccessTokenExpiresAt { get; set; }
public DateTime RefreshTokenExpiresAt { get; set; }
public DateTime InitialRefreshTokenCreatedAt { get; set; } = DateTime.UtcNow;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
public User User { get; set; } = null!;
public User? User { get; set; }
public Token? PreviousToken { get; set; }
}
8 changes: 4 additions & 4 deletions src/Pandatech.CleanArchitecture.Core/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Pandatech.CleanArchitecture.Core.Entities;
public class User : AuditEntityBase
{
public long Id { get; set; }
public string Username { get; set; } = null!;
public string FullName { get; set; } = null!;
public byte[] PasswordHash { get; set; } = null!;
public required string Username { get; set; }
public required string FullName { get; set; }
public required byte[] PasswordHash { get; set; }
public UserRole Role { get; set; }
public UserStatus Status { get; set; } = UserStatus.Active;
public bool ForcePasswordChange { get; set; } = true;
public string? Comment { get; set; }
public string Comment { get; set; } = "";

public ICollection<Token> Tokens { get; set; } = new List<Token>();
}
6 changes: 3 additions & 3 deletions src/Pandatech.CleanArchitecture.Core/Entities/UserConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class UserConfig : AuditEntityBase
{
public long Id { get; set; }
public long UserId { get; set; }
public string Key { get; set; } = null!;
public string Value { get; set; } = null!;
public User User { get; set; } = null!;
public required string Key { get; set; }
public required string Value { get; set; }
public User? User { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Pandatech.CleanArchitecture.Core.RedisEntities;
[MessagePackObject]
public class LoggedUserRedisEntity : ICacheEntity
{
[Key(0)] public string AccessToken { get; set; } = null!;
[Key(0)] public required string AccessToken { get; set; }
[Key(1)] public DateTime UpdatedAt { get; set; }
[Key(2)] public DateTime AccessTokenExpiration { get; set; }
[Key(3)] public long UserId { get; set; }
[Key(4)] public string Username { get; set; } = null!;
[Key(5)] public string FullName { get; set; } = null!;
[Key(4)] public required string Username { get; set; }
[Key(5)] public required string FullName { get; set; }
[Key(6)] public UserRole UserRole { get; set; }
[Key(7)] public UserStatus UserStatus { get; set; }
[Key(8)] public bool ForcePasswordChange { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public UserEntityFilters()
GenerateMappings();
AddMap("Role", x => x.Role != UserRole.SuperAdmin);
AddMap("Id", x => x.Id, x => PandaBaseConverter.Base36ToBase10NotNull(x));
AddMap("FullName", x => x.FullName.ToLower(), x => x.ToLower());
AddMap("Username", x => x.Username.ToLower(), x => x.ToLower());
AddMap("Comment", x => x.Comment.ToLower(), x => x.ToLower());
AddDefaultOrderBy("FullName");
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
role = table.Column<int>(type: "integer", nullable: false),
status = table.Column<int>(type: "integer", nullable: false),
force_password_change = table.Column<bool>(type: "boolean", nullable: false),
comment = table.Column<string>(type: "text", nullable: true),
comment = table.Column<string>(type: "text", nullable: false),
created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
created_by_user_id = table.Column<long>(type: "bigint", nullable: true),
updated_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<string>("Comment")
.IsRequired()
.HasColumnType("text")
.HasColumnName("comment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public PostgresContext(DbContextOptions<PostgresContext> options) : base(options
this.UseAuditPropertyValidation();
}

public DbSet<Token> Tokens { get; set; } = null!;
public DbSet<User> Users { get; set; } = null!;
public DbSet<UserConfig> UserConfigs { get; set; } = null!;
public DbSet<Token> Tokens { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<UserConfig> UserConfigs { get; set; }
public DbSet<InboxMessage> InboxMessages { get; set; }

public DbSet<OutboxMessage> OutboxMessages { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UnitOfWork(
PostgresContext context)
: IUnitOfWork
{
private IDbContextTransaction _transaction = null!;
private IDbContextTransaction _transaction = null!;
public IUserRepository Users { get; set; } = userRepository;
public ITokenRepository Tokens { get; set; } = tokenRepository;

Expand Down

0 comments on commit e6323fc

Please sign in to comment.