diff --git a/next.config.mjs b/next.config.mjs
index 0c60234..b805cdc 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -2,14 +2,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
- async rewrites() {
- return [
- {
- source: '/api/quote',
- destination: 'https://zenquotes.io/api/random',
- },
- ]
- },
+
}
export default nextConfig;
diff --git a/prisma/migrations/20241029084744_/migration.sql b/prisma/migrations/20241029084744_/migration.sql
new file mode 100644
index 0000000..fb66fdc
--- /dev/null
+++ b/prisma/migrations/20241029084744_/migration.sql
@@ -0,0 +1,13 @@
+-- CreateTable
+CREATE TABLE "Notes" (
+ "id" TEXT NOT NULL,
+ "content" TEXT NOT NULL,
+ "userId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "Notes_pkey" PRIMARY KEY ("id")
+);
+
+-- AddForeignKey
+ALTER TABLE "Notes" ADD CONSTRAINT "Notes_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
diff --git a/prisma/migrations/20241029092746_tags/migration.sql b/prisma/migrations/20241029092746_tags/migration.sql
new file mode 100644
index 0000000..9184c67
--- /dev/null
+++ b/prisma/migrations/20241029092746_tags/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Diary" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index b62d214..dd6b4a1 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -37,10 +37,12 @@ model Diary {
content String
user User @relation(fields: [userId], references: [id])
userId String
+ tags String[] @default([]) // Ensure tags are stored as an array of strings
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
+
model Notes {
id String @id @default(uuid())
content String
diff --git a/src/app/api/diary/[...id]/route.js b/src/app/api/diary/[...id]/route.js
index a1f37e8..4a671bd 100644
--- a/src/app/api/diary/[...id]/route.js
+++ b/src/app/api/diary/[...id]/route.js
@@ -35,12 +35,13 @@ export async function PATCH(req, { params }) {
}
const { id } = params;
const body = await req.json();
- const { title, content } = body;
+ const { title, content, tags } = body; // Include tags here
try {
const user = await prisma.user.findUnique({
where: {
clerkId: userId,
- }, select: {
+ },
+ select: {
id: true
}
});
@@ -51,7 +52,8 @@ export async function PATCH(req, { params }) {
},
data: {
title,
- content
+ content,
+ tags: tags || [] // Update tags as well
},
});
return Response.json({ message: "diary updated successfully" });
@@ -59,4 +61,4 @@ export async function PATCH(req, { params }) {
console.log(err);
return Response.json({ error: "Error updating diary" });
}
-}
\ No newline at end of file
+}
diff --git a/src/app/api/diary/route.js b/src/app/api/diary/route.js
index b9c44bc..62969c5 100644
--- a/src/app/api/diary/route.js
+++ b/src/app/api/diary/route.js
@@ -8,19 +8,26 @@ export async function GET(req) {
}
let user = await prisma.user.findUnique({
where: { clerkId: userId },
- })
+ });
let diaries = await prisma.diary.findMany({
where: {
userId: user.id,
},
+ select: { // Optionally, select only the fields you want
+ id: true,
+ title: true,
+ content: true,
+ tags: true, // Ensure tags are selected
+ userId: true,
+ },
});
return Response.json({ diaries });
}
+
export async function POST(req) {
const { userId } = getAuth(req);
-
const body = await req.json();
if (!userId) {
@@ -28,28 +35,29 @@ export async function POST(req) {
}
try {
- let clerkUser = await clerkClient.users.getUser(userId)
+ let clerkUser = await clerkClient.users.getUser(userId);
clerkUser = {
id: userId,
name: clerkUser.firstName + " " + clerkUser.lastName,
email: clerkUser.primaryEmailAddress.emailAddress,
- }
+ };
let user = await prisma.user.findUnique({
where: { clerkId: clerkUser.id },
- })
+ });
if (!user) {
user = await prisma.user.create({
data: {
clerkId: clerkUser.id,
- name: clerkUser.name || '', // Use fullName if available
- email: clerkUser.email || '', // Use emailAddress if available
+ name: clerkUser.name || '',
+ email: clerkUser.email || '',
},
- })
+ });
}
const diary = await prisma.diary.create({
data: {
title: body.title,
content: body.content,
+ tags: body.tags || [], // Add this line to save tags
userId: user.id,
},
});
diff --git a/src/app/daily-quote/page.jsx b/src/app/daily-quote/page.jsx
index 0e78b57..fdd4866 100644
--- a/src/app/daily-quote/page.jsx
+++ b/src/app/daily-quote/page.jsx
@@ -7,29 +7,31 @@ import { RiFileCopyLine } from "react-icons/ri";
export default function DailyQuote() {
const [quote, setQuote] = useState("Loading...");
const [author, setAuthor] = useState("Anonymous");
- const [error, setError] = useState();
const [copied, setCopied] = useState(false);
+ const [category, setCategory] = useState("life"); // Default category
+ // Fetch quote based on category
useEffect(() => {
- async function fetchData() {
- try {
- const response = await axios.get("/api/quote");
- setQuote(response.data[0].q);
- setAuthor(response.data[0].a);
- } catch (error) {
- setError(error);
- }
- }
-
- fetchData();
- }, []);
+ fetchQuote();
+ }, [category]);
- const getNewQuote = async () => {
+ const fetchQuote = async () => {
setQuote("Loading...");
setCopied(false);
- const response = await axios.get("/api/quote");
- setQuote(response.data[0].q);
- setAuthor(response.data[0].a);
+ try {
+ const response = await axios.get(
+ `https://api-get-quotes.vercel.app/api/v1/category/${category}`
+ );
+ const quotesArray = response.data.quotes; // Access the quotes array from the response
+
+ // Select a random quote from the quotes array
+ const randomIndex = Math.floor(Math.random() * quotesArray.length);
+ setQuote(quotesArray[randomIndex].quote);
+ setAuthor(quotesArray[randomIndex].author);
+ } catch (error) {
+ setQuote("Could not fetch quote");
+ setAuthor("Unknown");
+ }
};
const copyQuote = async () => {
@@ -49,19 +51,34 @@ export default function DailyQuote() {
+ {/* Category Selector */}
+
+ {["life", "motivation", "love", "courage", "Inspiration", "Friendship", "Hope", "Wisdom", "Nature"].map((cat) => (
+
+ ))}
+
+
-
-
- {quote}
-
+
+
{quote}
- {author}
@@ -72,7 +89,11 @@ export default function DailyQuote() {
Copy
- {copied &&
Copied successfully!
}
+ {copied && (
+
+ Copied successfully!
+
+ )}