Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/app/api/blogs/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth";

export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await auth();

if (!session?.user?.id) {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401 }
);
}

const { id } = await params;

return NextResponse.json({ success: true });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Failed to delete blog" },
{ status: 400 }
);
}
}*/
25 changes: 25 additions & 0 deletions src/app/api/blogs/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
import { NextResponse } from "next/server";
import { CreateBlogSchema } from "@/schemas/CreateBlogSchema";
import { createBlogs, getBlogs } from "@/actions/blogs";
import { auth } from "@/lib/auth";

export async function POST(request: Request) {
try {
// Check authentication
const session = await auth();

if (!session?.user?.id) {
return NextResponse.json(
{ error: "Unauthorized. Please log in to create blogs." },
{ status: 401 },
);
}

const body = await request.json();

// Validate request body
const validatedData = CreateBlogSchema.parse(body);

// Validate that all blogs have the authenticated user as author
for (const blog of validatedData) {
if (blog.authorId !== session.user.id) {
return NextResponse.json(
{
error: "Forbidden. You can only create blogs as yourself.",
providedAuthorId: blog.authorId,
authenticatedUserId: session.user.id
},
{ status: 403 },
);
}
}

// Create the blogs
const blogs = await createBlogs(validatedData);

Expand Down
27 changes: 27 additions & 0 deletions src/app/api/paper/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth";

export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await auth();

if (!session?.user?.id) {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401 }
);
}

const { id } = await params;

return NextResponse.json({ success: true });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Failed to delete research paper" },
{ status: 400 }
);
}
}*/
25 changes: 25 additions & 0 deletions src/app/api/paper/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
import { NextRequest, NextResponse } from "next/server";
import { CreatePaperSchema } from "@/schemas/CreatePaperSchema";
import { createPapers, fetchPapers } from "@/actions/papers";
import { auth } from "@/lib/auth";

export async function POST(request: NextRequest) {
try {
// Check authentication
const session = await auth();

if (!session?.user?.id) {
return NextResponse.json(
{ error: "Unauthorized. Please log in to create research papers." },
{ status: 401 },
);
}

const body = await request.json();

// Validate request body
const validatedData = CreatePaperSchema.parse(body);

// Validate that authenticated user is included as an author in all papers
for (const paper of validatedData) {
if (!paper.authorIds.includes(session.user.id)) {
return NextResponse.json(
{
error: "Forbidden. You must include yourself as an author.",
providedAuthorIds: paper.authorIds,
authenticatedUserId: session.user.id
},
{ status: 403 },
);
}
}

// Create the paper
const paper = await createPapers(validatedData);

Expand Down
2 changes: 1 addition & 1 deletion src/app/u/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const EditProfilePage = async ({ params }: PageProps) => {
Edit Profile
</h1>
<p className="text-muted-foreground">
Update your profile information and social links
Update your profile, information, social links, publish blogs, and add research papers
</p>
</div>

Expand Down
Loading