Compare commits

..

No commits in common. "2c2cb819e1600482c6515ce3491c317b7bbe5b60" and "4c3688b065fe4e728db07889ea41327f23812f11" have entirely different histories.

15 changed files with 48 additions and 221 deletions

View File

@ -1,20 +0,0 @@
CREATE OR REPLACE FUNCTION notify_new_message()
RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
PERFORM pg_notify(
'new_message',
json_build_object(
'id', NEW.id,
'text', NEW.text,
'senderId', NEW.senderId,
'receiverId', NEW.receiverId,
'createdAt', NEW.createdAt
)::text
);
RETURN NEW;
END;
$$;
CREATE TRIGGER message_insert_trigger
AFTER INSERT ON messages
FOR EACH ROW EXECUTE FUNCTION notify_new_message();

View File

@ -1,15 +0,0 @@
{
"id": "ba7dd70a-8dd6-41be-b1d2-158ab83ba830",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {},
"enums": {},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@ -1,13 +0,0 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1729627211020,
"tag": "0000_warm_edwin_jarvis",
"breakpoints": true
}
]
}

View File

@ -12,8 +12,8 @@
"dev": "next dev", "dev": "next dev",
"lint": "next lint", "lint": "next lint",
"start": "next start", "start": "next start",
"go": "next dev", "go": "pnpm dev",
"go:prod": "next build && next start" "go:prod": "pnpm build && pnpm start"
}, },
"dependencies": { "dependencies": {
"@t3-oss/env-nextjs": "^0.10.1", "@t3-oss/env-nextjs": "^0.10.1",

BIN
public/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,41 +0,0 @@
'use server';
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { getMessages } from '~/server/functions';
import { middleware } from '~/middleware';
import type { Message } from '~/server/types';
export const GET = async (request: NextRequest) => {
const middlewareResponse = await middleware(request);
if (middlewareResponse) return middlewareResponse;
try {
const url = new URL(request.url);
const userId = Number.parseInt(url.searchParams.get('userId') ?? '');
const limit = Number.parseInt(url.searchParams.get('limit') ?? '');
const offset = Number.parseInt(url.searchParams.get('offset') ?? '0');
if (!userId || isNaN(userId) || !limit || isNaN(limit) || isNaN(offset)) {
console.log('userId: ', userId, 'limit: ', limit, 'offset: ', offset);
return NextResponse.json(
{ message: 'Missing userId, limit, or offset' }, { status: 400 }
);
}
const messages: Message[] | undefined = await getMessages(userId, limit, offset);
if (messages === undefined) {
return NextResponse.json(
{ message: 'No messages found' }, { status: 404 }
);
}
return NextResponse.json(messages);
} catch (error) {
console.error('Error getting messages:', error);
if (error instanceof Error) {
return NextResponse.json(
{ message: error.message }, { status: 500 }
);
} else {
return NextResponse.json(
{ message: 'Unknown error occurred' }, { status: 500 }
);
}
}
};

View File

@ -1,41 +0,0 @@
'use server'
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { sendMessage } from '~/server/functions';
import { middleware } from '~/middleware';
import type { Message } from '~/server/types';
export const POST = async (request: NextRequest) => {
const middlewareResponse = await middleware(request);
if (middlewareResponse) return middlewareResponse;
try {
const body = await request.json() as {
message: Message;
};
const { message } = body;
if (!message) {
console.log('Message:', message);
return NextResponse.json(
{ message: 'Missing message' }, { status: 400 }
);
}
const newMessage: Message | null = await sendMessage(message);
if (!newMessage) {
return NextResponse.json(
{ message: 'Error sending message' }, { status: 500 }
);
}
return NextResponse.json(newMessage);
} catch (error) {
console.error('Error sending message:', error);
if (error instanceof Error) {
return NextResponse.json(
{ message: error.message }, { status: 500 }
);
} else {
return NextResponse.json(
{ message: 'Unknown error occurred' }, { status: 500 }
);
}
}
};

View File

@ -9,17 +9,14 @@ export const POST = async (request: NextRequest) => {
const middlewareResponse = await middleware(request); const middlewareResponse = await middleware(request);
if (middlewareResponse) return middlewareResponse; if (middlewareResponse) return middlewareResponse;
try { try {
const body = await request.json() as { const url = new URL(request.url);
userId: number; const userId = Number.parseInt(url.searchParams.get('userId') ?? '');
targetUserId: number; const partnerId = Number.parseInt(url.searchParams.get('partnerId') ?? '');
}; if (!userId || !partnerId || isNaN(userId) || isNaN(partnerId))
const { userId, targetUserId } = body;
console.log('User ID:', userId, 'Partner ID:', targetUserId);
if (!userId || !targetUserId || isNaN(userId) || isNaN(targetUserId))
return NextResponse.json( return NextResponse.json(
{ message: 'Missing userId or targetUserId' }, { status: 400 } { message: 'Missing userId or partnerId' }, { status: 400 }
); );
const relationshipData: RelationshipData | null = await createRelationshipRequest(userId, targetUserId); const relationshipData: RelationshipData | null = await createRelationshipRequest(userId, partnerId);
if (!relationshipData) { if (!relationshipData) {
return NextResponse.json( return NextResponse.json(
{ message: 'Error creating relationship request' }, { status: 500 } { message: 'Error creating relationship request' }, { status: 500 }

View File

@ -9,12 +9,9 @@ export const POST = async (request: NextRequest) => {
const middlewareResponse = await middleware(request); const middlewareResponse = await middleware(request);
if (middlewareResponse) return middlewareResponse; if (middlewareResponse) return middlewareResponse;
try { try {
const body = await request.json() as { const url = new URL(request.url);
userId: number; const userId = Number.parseInt(url.searchParams.get('userId') ?? '');
status: string; const status = url.searchParams.get('status');
};
const { userId, status } = body;
console.log('User ID:', userId, 'Status:', status);
if (!userId || !status || isNaN(userId)) if (!userId || !status || isNaN(userId))
return NextResponse.json( return NextResponse.json(
{ message: 'Missing userId or status' }, { status: 400 } { message: 'Missing userId or status' }, { status: 400 }
@ -24,7 +21,7 @@ export const POST = async (request: NextRequest) => {
await updateRelationshipStatus(userId, theStatus); await updateRelationshipStatus(userId, theStatus);
if (!relationshipData || relationshipData === undefined) { if (!relationshipData || relationshipData === undefined) {
return NextResponse.json( return NextResponse.json(
{ message: 'Error updating relationship status.' }, { status: 500 } { message: 'Error updating relationship status' }, { status: 500 }
); );
} }
return NextResponse.json(relationshipData); return NextResponse.json(relationshipData);

View File

@ -4,9 +4,9 @@ import { GeistSans } from "geist/font/sans";
import { type Metadata } from "next"; import { type Metadata } from "next";
export const metadata: Metadata = { export const metadata: Metadata = {
title: "Is Madeline the Cutest?", title: "Create T3 App",
description: "Answering the easiest question in the world!", description: "Generated by create-t3-app",
icons: [{ rel: "icon", url: "/favicon.png" }], icons: [{ rel: "icon", url: "/favicon.ico" }],
}; };
export default function RootLayout({ export default function RootLayout({

View File

@ -1,35 +1,37 @@
"use client"; import Link from "next/link";
import { useState, useEffect } from "react";
const interestingYes = () => {
const yesArray = [
"Absolutely, yes.",
"Without a doubt.",
"Of course.",
"Definitely.",
"Obviously!",
"Certainly!",
"Positively.",
"100%",
];
return yesArray[Math.floor(Math.random() * yesArray.length)];
}
export default function HomePage() { export default function HomePage() {
const [currentText, setCurrentText] = useState("");
useEffect(() => {
setCurrentText(interestingYes() ?? "Absolutely, yes.");
}, []);
const handleClick = () => {
setCurrentText(interestingYes() ?? "Absolutely, yes.");
};
return ( return (
<main className="flex min-h-screen flex-col items-center justify-center <main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c] text-white">
bg-gradient-to-b from-pink-500 to-orange-400 text-white cursor-pointer"> <div className="container flex flex-col items-center justify-center gap-12 px-4 py-16">
<h3 className="text-5xl font-extrabold tracking-tight <h1 className="text-5xl font-extrabold tracking-tight text-white sm:text-[5rem]">
text-white sm:text-[5rem] text-center" onClick={handleClick}> Create <span className="text-[hsl(280,100%,70%)]">T3</span> App
{currentText} </h1>
</h3> <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8">
<Link
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
href="https://create.t3.gg/en/usage/first-steps"
target="_blank"
>
<h3 className="text-2xl font-bold">First Steps </h3>
<div className="text-lg">
Just the basics - Everything you need to know to set up your
database and authentication.
</div>
</Link>
<Link
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
href="https://create.t3.gg/en/introduction"
target="_blank"
>
<h3 className="text-2xl font-bold">Documentation </h3>
<div className="text-lg">
Learn more about Create T3 App, the libraries it uses, and how to
deploy it.
</div>
</Link>
</div>
</div>
</main> </main>
); );
} }

View File

@ -1,5 +1,4 @@
// https://orm.drizzle.team/docs/sql-schema-declaration // https://orm.drizzle.team/docs/sql-schema-declaration
import { db } from '~/server/db';
import { sql } from "drizzle-orm"; import { sql } from "drizzle-orm";
import { import {
boolean, boolean,
@ -162,4 +161,3 @@ export const quickReplyOptions = pgTable(
quickReplyIdIndex: index('qr_options_quick_reply_id_idx').on(table.quickReplyId), quickReplyIdIndex: index('qr_options_quick_reply_id_idx').on(table.quickReplyId),
}) })
); );

View File

@ -1,7 +1,7 @@
import 'server-only'; import 'server-only';
import { db } from '~/server/db'; import { db } from '~/server/db';
import * as schema from '~/server/db/schema'; import * as schema from '~/server/db/schema';
import { eq, and, or, like, not, desc, sql } from 'drizzle-orm'; import { eq, and, or, like, not } from 'drizzle-orm';
import { User, import { User,
Relationship, Relationship,
UserRelationship, UserRelationship,
@ -226,10 +226,6 @@ export const updateRelationshipStatus = async (
throw new Error('Relationship not found'); throw new Error('Relationship not found');
} }
const relationship = relationships[0] as Relationship; const relationship = relationships[0] as Relationship;
// Everything above is just getting info
if (userId === relationship.requestorId && status === 'accepted') {
throw new Error('The requestor cannot accept the relationship they requested.');
}
if (status === 'accepted') { if (status === 'accepted') {
await db.update(schema.relationships) await db.update(schema.relationships)
.set({ isAccepted: true }) .set({ isAccepted: true })
@ -255,7 +251,7 @@ export const updateRelationshipStatus = async (
return relationshipData; return relationshipData;
} else if (status === 'rejected') { } else if (status === 'rejected') {
await db.delete(schema.userRelationships) await db.delete(schema.userRelationships)
.where(eq(schema.userRelationships.relationshipId, relationship.id)); .where(eq(schema.userRelationships.id, userRelationship.id));
await db.delete(schema.relationships) await db.delete(schema.relationships)
.where(eq(schema.relationships.id, relationship.id)); .where(eq(schema.relationships.id, relationship.id));
return null; return null;
@ -325,36 +321,3 @@ export const createRelationshipRequest = async (userId: number, partnerId: numbe
} }
}; };
export const getMessages = async (userId: number, limit: number, offset: number) => {
try {
const messages = await db.select().from(schema.messages)
.where(or(
eq(schema.messages.senderId, userId),
eq(schema.messages.receiverId, userId)
))
.limit(limit)
.offset(offset)
.orderBy(desc(schema.messages.createdAt), desc(schema.messages.id));
return messages as Message[];
} catch (error) {
console.error('Error getting messages:', error);
throw error;
}
};
export const sendMessage = async (message: Message) => {
try {
const [newMessage] = await db.insert(schema.messages).values({
senderId: message.senderId,
receiverId: message.receiverId,
text: message.text,
hasLocation: message.hasLocation,
hasMedia: message.hasMedia,
hasQuickReply: message.hasQuickReply,
}).returning();
return newMessage as Message;
} catch (error) {
console.error('Error sending message:', error);
throw error;
}
};