From 27174bef1853ea065345242527c46809fd60673a Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Thu, 25 Dec 2025 13:12:56 +0100 Subject: [PATCH] feat(backend): add follow/unfollow endpoints and live follower counts --- backend/src/posts/posts.service.ts | 13 ++++++++++--- backend/src/users/users.service.ts | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 backend/src/users/users.service.ts diff --git a/backend/src/posts/posts.service.ts b/backend/src/posts/posts.service.ts index cd4cafb..e304b4c 100644 --- a/backend/src/posts/posts.service.ts +++ b/backend/src/posts/posts.service.ts @@ -28,10 +28,17 @@ export class PostsService { }, }, author: { - select: { - name: true, - }, + select: { + name: true, + _count: { + select: { + followers: true, + following: true, }, + }, + }, +}, + } as const; // Sichtbarkeit diff --git a/backend/src/users/users.service.ts b/backend/src/users/users.service.ts new file mode 100644 index 0000000..37fbe98 --- /dev/null +++ b/backend/src/users/users.service.ts @@ -0,0 +1,23 @@ +async getUserProfile(userId: number) { + const [user, followersCount, followingCount] = await Promise.all([ + this.prisma.user.findUnique({ + where: { id: userId }, + select: { + id: true, + name: true, + }, + }), + this.prisma.follow.count({ + where: { followingId: userId }, + }), + this.prisma.follow.count({ + where: { followerId: userId }, + }), + ]); + + return { + ...user, + followersCount, + followingCount, + }; +}