Skip to content

Commit

Permalink
fix: #dev async fix 3
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbator committed Nov 23, 2024
1 parent 5c1150b commit 5ef4ed9
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion rag-2-backend/Infrastructure/Dao/RefreshTokenDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class RefreshTokenDao(DatabaseContext context)
{
public virtual async Task RemoveTokensForUser(User user)
{
context.Attach(user);
var unusedTokens = await context.RefreshTokens.Where(r => r.User.Id == user.Id).ToListAsync();
context.RefreshTokens.RemoveRange(unusedTokens);
await context.SaveChangesAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class AccountConfirmationToken
{
[Key] [MaxLength(100)] public required string Token { get; init; }
public required DateTime Expiration { get; set; }
public required User User { get; init; }

[ForeignKey("UserId")] public required User User { get; init; }
}
7 changes: 5 additions & 2 deletions rag-2-backend/Infrastructure/Database/Entity/GameRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ namespace rag_2_backend.Infrastructure.Database.Entity;
public class GameRecord
{
[Key] public int Id { get; init; }
public required Game Game { get; init; }
public required User User { get; init; }

[ForeignKey("GameId")] public required Game Game { get; init; }

[ForeignKey("UserId")] public required User User { get; init; }

public required List<GameRecordValue> Values { get; init; }
public List<Player>? Players { get; init; }
public DateTime Started { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class PasswordResetToken
{
[Key] [MaxLength(100)] public required string Token { get; init; }
public required DateTime Expiration { get; set; }
public required User User { get; init; }

[ForeignKey("UserId")] public required User User { get; init; }
}
3 changes: 2 additions & 1 deletion rag-2-backend/Infrastructure/Database/Entity/RefreshToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class RefreshToken
{
[Key] [MaxLength(100)] public required string Token { get; init; }
public required DateTime Expiration { get; init; }
public required User User { get; init; }

[ForeignKey("UserId")] public required User User { get; init; }
}
4 changes: 3 additions & 1 deletion rag-2-backend/Infrastructure/Database/Entity/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public User(string email)
public int StudyCycleYearB { get; set; }
public bool Banned { get; set; }
public DateTime LastPlayed { get; set; }
public Course? Course { get; set; }

[ForeignKey("CourseId")] public Course? Course { get; set; }

[MaxLength(100)] public string? Group { get; set; }
}
1 change: 0 additions & 1 deletion rag-2-backend/Infrastructure/Module/Auth/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public async Task LogoutUser(string token)
private async Task<RefreshToken> GenerateRefreshToken(double refreshTokenExpirationTimeDays,
Database.Entity.User user)
{
databaseContext.Attach(user);
var refreshToken = new RefreshToken
{
User = user,
Expand Down
2 changes: 0 additions & 2 deletions rag-2-backend/Infrastructure/Module/User/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ private async Task UpdateUserProperties(
int? studyCycleYearA, int? studyCycleYearB, int? courseId, string? group, Database.Entity.User user
)
{
context.Attach(user);

if (user.Role == Role.Student && (
!studyCycleYearA.HasValue || !studyCycleYearB.HasValue || !courseId.HasValue ||
string.IsNullOrWhiteSpace(group))
Expand Down
2 changes: 1 addition & 1 deletion rag-2-backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"),
b => { b.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null); });
}, ServiceLifetime.Transient);
});
builder.Services.AddSingleton<IConnectionMultiplexer>(
ConnectionMultiplexer.Connect(builder.Configuration.GetSection("Redis:ConnectionString").Value ?? "")
);
Expand Down

0 comments on commit 5ef4ed9

Please sign in to comment.