mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-08 03:28:50 +00:00
added endpoint for getting postTags and fixed follow bug
This commit is contained in:
parent
268a00d026
commit
5ead261db2
8 changed files with 92 additions and 14 deletions
|
@ -4,7 +4,6 @@ import { StatusCodes } from "http-status-codes";
|
|||
import { JwtPayload } from "jsonwebtoken";
|
||||
import { PrismaClient, Post } from "../../prisma/app/generated/prisma/client";
|
||||
import { minioClient } from "../server";
|
||||
import { object } from "zod";
|
||||
import { uploadPostSchema } from "../schemas/postSchemas";
|
||||
dotenv.config();
|
||||
const prisma = new PrismaClient();
|
||||
|
@ -190,11 +189,20 @@ export const getPost = async (req: Request, res: Response) => {
|
|||
// get all posts from a user
|
||||
export const getUserPosts = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const user: JwtPayload | undefined = req.user;
|
||||
const username: string = req.params.username;
|
||||
const posts = await prisma.post.findMany({
|
||||
where: {
|
||||
...(user
|
||||
? {
|
||||
OR: [
|
||||
{ status: "PRIVATE", userId: user.id },
|
||||
{ status: "PUBLIC" },
|
||||
],
|
||||
}
|
||||
: { status: "PUBLIC" }),
|
||||
user: {
|
||||
username: username, // hier greifst du auf die relationierte User-Tabelle zu
|
||||
username: username,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -329,3 +337,31 @@ export const removeLike = async (req: Request, res: Response) => {
|
|||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getTags = async (req: Request, res: Response) => {
|
||||
try {
|
||||
const tags = await prisma.tag.findMany({
|
||||
take: 150,
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
posts: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
posts: {
|
||||
_count: "desc",
|
||||
},
|
||||
},
|
||||
});
|
||||
const data: string[] = tags.map((tag) => tag.name);
|
||||
res.status(StatusCodes.OK).json(data);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
|
||||
error: "Failed to retrieve tags",
|
||||
details: [{ message: "Internal server error" }],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue