Fixed errors with delete of users

This commit is contained in:
2026-04-26 16:55:20 +01:00
parent 401541999c
commit 6b9342491f
3 changed files with 32 additions and 14 deletions
@@ -1,11 +1,13 @@
using BeReadyBackend.Repositories;
using BeReadyBackend.Models;
using BeReadyBackend.Repositories;
using BeReadyBackend.Services;
using BeReadyBackend.Specifications.Friends;
using BeReadyBackend.Specifications.Users;
using FastEndpoints;
namespace BeReadyBackend.Endpoints.Users;
public class DeleteUserEndpoint(UsersRepository usersRepository, UserService userService) : EndpointWithoutRequest
public class DeleteUserEndpoint(UsersRepository usersRepository, UserFriendsRepository userFriendsRepository, UserService userService) : EndpointWithoutRequest
{
public override void Configure()
{
@@ -16,6 +18,9 @@ public class DeleteUserEndpoint(UsersRepository usersRepository, UserService use
{
int userId = userService.GetUserIdFromToken();
List<UserFriend> friends = await userFriendsRepository.ListAsync(new GetAllFriendsRelationsByIdSpec(userId), ct);
await userFriendsRepository.DeleteRangeAsync(friends, ct);
await usersRepository.DeleteAsync((await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(userId), ct))!, ct);
await Send.NoContentAsync(ct);
}
@@ -40,7 +40,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("Achievements");
b.ToTable("Achievements", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.Designation", b =>
@@ -57,7 +57,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("Designations");
b.ToTable("Designations", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.Group", b =>
@@ -77,7 +77,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("Groups");
b.ToTable("Groups", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.Message", b =>
@@ -107,7 +107,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("UserId");
b.ToTable("Messages");
b.ToTable("Messages", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.Post", b =>
@@ -134,7 +134,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("UserId");
b.ToTable("Posts");
b.ToTable("Posts", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.RandomChallenge", b =>
@@ -161,7 +161,7 @@ namespace BeReadyBackend.Migrations
b.HasKey("Id");
b.ToTable("RandomChallenges");
b.ToTable("RandomChallenges", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.User", b =>
@@ -217,7 +217,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("DesignationId");
b.ToTable("Users");
b.ToTable("Users", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.UserAchievement", b =>
@@ -232,7 +232,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("AchievementId");
b.ToTable("UserAchievements");
b.ToTable("UserAchievements", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.UserFriend", b =>
@@ -250,7 +250,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("FriendId");
b.ToTable("UserFriends");
b.ToTable("UserFriends", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.UserGroup", b =>
@@ -269,7 +269,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("GroupId");
b.ToTable("UserGroups");
b.ToTable("UserGroups", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.UserPost", b =>
@@ -284,7 +284,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("PostId");
b.ToTable("UserPosts");
b.ToTable("UserPosts", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.UserRandomChallenge", b =>
@@ -302,7 +302,7 @@ namespace BeReadyBackend.Migrations
b.HasIndex("RandomChallengeId");
b.ToTable("UserRandomChallenges");
b.ToTable("UserRandomChallenges", (string)null);
});
modelBuilder.Entity("BeReadyBackend.Models.Message", b =>
@@ -0,0 +1,13 @@
using Ardalis.Specification;
using BeReadyBackend.Models;
namespace BeReadyBackend.Specifications.Friends;
public class GetAllFriendsRelationsByIdSpec : Specification<UserFriend>
{
public GetAllFriendsRelationsByIdSpec(int userId)
{
Query
.Where(x => x.UserId == userId || x.FriendId == userId);
}
}