diff --git a/src/app/api/messages/fetchMessages/route.ts b/src/app/api/messages/fetchMessages/route.ts index 3c0433f..97ca012 100644 --- a/src/app/api/messages/fetchMessages/route.ts +++ b/src/app/api/messages/fetchMessages/route.ts @@ -16,7 +16,11 @@ export const GET = async (request: NextRequest) => { const messages = await fetchMessages(parseInt(userId), parseInt(partnerId)); return NextResponse.json(messages); } catch (error) { - console.error(error); - return NextResponse.json({ message: "Error" }, { status: 500 }); + console.error('Detailed error:', error); + if (error instanceof Error) { + return NextResponse.json({ message: `Error: ${error.message}` }, { status: 500 }); + } else { + return NextResponse.json({ message: "Unknown error occurred" }, { status: 500 }); + } } }; diff --git a/src/app/countdown/createOrUpdateCountdown/page.tsx b/src/app/countdown/createOrUpdateCountdown/page.tsx new file mode 100644 index 0000000..c08c89e --- /dev/null +++ b/src/app/countdown/createOrUpdateCountdown/page.tsx @@ -0,0 +1,87 @@ +'use client'; + +import React, { useState } from 'react'; + +export default function TestCreateOrUpdateCountdown() { + const [relationshipId, setRelationshipId] = useState(''); + const [title, setTitle] = useState(''); + const [date, setDate] = useState(''); + const [result, setResult] = useState(null); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setResult(null); + + try { + const response = await fetch('/api/countdown/createOrUpdateCountdown', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'x-api-key': process.env.NEXT_PUBLIC_API_KEY ?? '', + }, + body: JSON.stringify({ + relationshipId, + title, + date, + }), + }); + const data = await response.json() as { message: string }; + setResult(data.message); + } catch (error) { + console.error('Error:', error); + setResult('An error occurred'); + } + }; + + return ( +
+
+

Test Create or Update Countdown

+
+
+ + setRelationshipId(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+
+ + setTitle(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+
+ + setDate(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+ +
+ {result && ( +
+ Result: {result} +
+ )} +
+
+ ); +} diff --git a/src/app/countdown/getCountdownByRelationship/page.tsx b/src/app/countdown/getCountdownByRelationship/page.tsx new file mode 100644 index 0000000..c5f8593 --- /dev/null +++ b/src/app/countdown/getCountdownByRelationship/page.tsx @@ -0,0 +1,57 @@ +'use client'; + +import React, { useState } from 'react'; + +export default function TestGetCountdownByRelationship() { + const [relationshipId, setRelationshipId] = useState(''); + const [result, setResult] = useState(null); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setResult(null); + + try { + const response = await fetch(`/api/countdown/getCountdownByRelationship?relationshipId=${relationshipId}`, { + method: 'GET', + headers: { + 'x-api-key': process.env.NEXT_PUBLIC_API_KEY ?? '', + }, + }); + const data = await response.json() as { countdown: string }; + setResult(JSON.stringify(data, null, 2)); + } catch (error) { + console.error('Error:', error); + setResult('An error occurred'); + } + }; + + return ( +
+
+

Test Get Countdown By Relationship

+
+
+ + setRelationshipId(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+ +
+ {result && ( +
+
{result}
+
+ )} +
+
+ ); +}; diff --git a/src/app/messages/fetchMessages/page.tsx b/src/app/messages/fetchMessages/page.tsx new file mode 100644 index 0000000..5de2493 --- /dev/null +++ b/src/app/messages/fetchMessages/page.tsx @@ -0,0 +1,69 @@ +"use client"; +import React, { useState } from "react"; + +export default function TestFetchMessages() { + const [userId, setUserId] = useState(""); + const [partnerId, setPartnerId] = useState(""); + const [result, setResult] = useState(null); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setResult(null); + + try { + const response = await fetch(`/api/messages/fetchMessages?userId=${userId}&partnerId=${partnerId}`, { + method: "GET", + headers: { + "x-api-key": process.env.NEXT_PUBLIC_API_KEY ?? "", + }, + }); + + const data = await response.json() as { message: string }; + setResult(JSON.stringify(data, null, 2)); + } catch (error) { + console.error("Error:", error); + setResult("An error occurred"); + } + }; + + return ( +
+
+

Test Fetch Messages

+
+
+ + setUserId(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+
+ + setPartnerId(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+ +
+ {result && ( +
+
{result}
+
+ )} +
+
+ ); +}; diff --git a/src/app/messages/sendMessage/page.tsx b/src/app/messages/sendMessage/page.tsx new file mode 100644 index 0000000..def670a --- /dev/null +++ b/src/app/messages/sendMessage/page.tsx @@ -0,0 +1,121 @@ +'use client'; + +import React, { useState } from 'react'; + +type MediaType = 'text' | 'image' | 'video' | 'audio' | 'file' | 'link'; + +export default function TestSendMessage() { + const [senderId, setSenderId] = useState(''); + const [receiverId, setReceiverId] = useState(''); + const [content, setContent] = useState(''); + const [mediaType, setMediaType] = useState(''); + const [mediaUrl, setMediaUrl] = useState(''); + const [result, setResult] = useState(null); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setResult(null); + + try { + const response = await fetch('/api/messages/sendMessage', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'x-api-key': process.env.NEXT_PUBLIC_API_KEY ?? '', + }, + body: JSON.stringify({ + senderId, + receiverId, + content, + ...(mediaType && mediaUrl && { mediaType, mediaUrl }), + }), + }); + + const data = await response.json() as {message: string} + setResult(JSON.stringify(data, null, 2)); + } catch (error) { + console.error('Error:', error); + setResult('An error occurred'); + } + }; + + return ( +
+
+

Test Send Message

+
+
+ + setSenderId(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+
+ + setReceiverId(e.target.value)} + className="border p-2 w-full bg-black" + required + /> +
+
+ +