Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghao1993 committed Sep 9, 2024
1 parent e6a11c3 commit be40b76
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions app/api/blog/detail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PostTypes } from "@/types/post";
import { getServerSession } from "next-auth";
import { getSession } from "next-auth/react";
import { authOptions } from "@/lib/auth_options";
import { message } from "antd";
export const dynamic = "force-dynamic"; // defaults to auto
export async function GET(request: Request) {
const key = new URL(request.url).searchParams.get("key");
Expand Down Expand Up @@ -65,16 +66,40 @@ export async function POST(req: Request, res: Response) {
} else {
likes_count.push(user.id);
}
const updatePost = await prisma.post.update({
where: {
blog_key: body.blog_key,
},
data: {
likes_count,
},
});

return responseHandler(updatePost);
try {
const updatePost = await prisma.post.update({
where: {
blog_key: body.blog_key,
},
data: {
likes_count,
},
});

return responseHandler(updatePost);
} catch (e) {
return responseHandler(
null,
BusinessCode.normal,
BusinessCode.abnormal,
e.message
);
}
} else {
return responseHandler(
null,
BusinessCode.normal,
BusinessCode.abnormal,
"用户查询错误"
);
}
} else {
return responseHandler(
null,
BusinessCode.normal,
BusinessCode.abnormal,
"文章不存在"
);
}
}

0 comments on commit be40b76

Please sign in to comment.