-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d74eb18
commit bbe032d
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import connectMongoDB from "@utilities/mongodb"; | ||
import Project from "@models/project"; | ||
import { Params } from "next/dist/shared/lib/router/utils/route-matcher"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function PUT(request: Request, { params }: Params) { | ||
const { id } = params; | ||
const { | ||
src: src, | ||
projectTitle: projectTitle, | ||
projectDesc: projectDesc, | ||
href: href, | ||
} = await request.json(); | ||
await connectMongoDB(); | ||
await Project.findByIdAndUpdate(id, { | ||
src, | ||
projectTitle, | ||
projectDesc, | ||
href, | ||
}); | ||
return NextResponse.json({ message: "Project me updated" }, { status: 200 }); | ||
}; | ||
|
||
export async function GET(request: Request, { params }: Params ) { | ||
const { id } = params; | ||
await connectMongoDB(); | ||
const projects = await Project.findOne({ _id: id }); | ||
return NextResponse.json({ projects }, { status: 200 }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import connectMongoDB from "@utilities/mongodb"; | ||
import Project from "@models/project"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function POST(request: Request, response: Response) { | ||
const { | ||
src, | ||
projectTitle, | ||
projectDesc, | ||
href, | ||
} = await request.json(); | ||
await connectMongoDB(); | ||
await Project.create({ | ||
src, | ||
projectTitle, | ||
projectDesc, | ||
href, | ||
}); | ||
return NextResponse.json({message: "Project created"}) | ||
}; | ||
|
||
export async function GET() { | ||
await connectMongoDB(); | ||
const projects = await Project.find(); | ||
return NextResponse.json({ projects }) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Url } from "next/dist/shared/lib/router/router" | ||
|
||
export type ProjectType = { | ||
_id?: string | ||
src: Url, | ||
projectTitle: string, | ||
projectDesc: string, | ||
href: string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import mongoose, { Schema } from "mongoose"; | ||
|
||
const projectSchema = new Schema( | ||
{ | ||
src: String, | ||
projectTitle: String, | ||
projectDesc: String, | ||
href: String, | ||
}, { | ||
timestamps: true, | ||
} | ||
); | ||
|
||
const Project = mongoose.models.Project || mongoose.model("Project", projectSchema); | ||
|
||
export default Project; |