-
-
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
16d00dc
commit 0d10aef
Showing
7 changed files
with
76 additions
and
52 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,26 @@ | ||
import connectMongoDB from "@utilities/mongodb"; | ||
import About from "@models/topic"; | ||
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 { | ||
title: title, | ||
desc: desc, | ||
} = await request.json(); | ||
await connectMongoDB(); | ||
await About.findByIdAndUpdate(id, { | ||
title, | ||
desc, | ||
name, | ||
}); | ||
return NextResponse.json({ message: "Updated" }, { status: 200 }); | ||
} | ||
|
||
export async function GET(request: Request, { params }: Params ) { | ||
const { id } = params; | ||
await connectMongoDB(); | ||
const about = await About.findOne({ _id: id }); | ||
return NextResponse.json({ about }, { 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,22 @@ | ||
import connectMongoDB from "@utilities/mongodb"; | ||
import Topic from "@models/topic"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function POST(request: Request, response: Response) { | ||
const { | ||
title, | ||
desc, | ||
} = await request.json(); | ||
await connectMongoDB(); | ||
await Topic.create({ | ||
title, | ||
desc, | ||
}); | ||
return NextResponse.json({message: "New topic created"}) | ||
}; | ||
|
||
export async function GET() { | ||
await connectMongoDB(); | ||
const topics = await Topic.find(); | ||
return NextResponse.json({ topics }) | ||
}; |
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
export type TopicType = { | ||
_id: string | ||
title: string, | ||
desc: string, | ||
} |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import mongoose, { Schema } from "mongoose"; | ||
|
||
const topicSchema = new Schema( | ||
{ | ||
title: String, | ||
desc: String, | ||
}, { | ||
timestamps: true, | ||
} | ||
); | ||
|
||
const Topic = mongoose.models.Topic || mongoose.model("Topic", topicSchema); | ||
|
||
export default Topic; |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// import mongoose from "mongoose"; | ||
import mongoose from "mongoose"; | ||
|
||
// const connectMongoDB = async () => { | ||
// try { | ||
// await mongoose.connect(process.env.MONGODB_URI as string); | ||
// } catch (error) { | ||
// console.log(error); | ||
// } | ||
// }; | ||
const connectMongoDB = async () => { | ||
try { | ||
await mongoose.connect(process.env.MONGODB_URI as string); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
// export default connectMongoDB; | ||
export default connectMongoDB; |