From 2c2cb819e1600482c6515ce3491c317b7bbe5b60 Mon Sep 17 00:00:00 2001 From: gibbyb Date: Tue, 22 Oct 2024 16:38:45 -0500 Subject: [PATCH] dont even know if I changed anything --- drizzle/0000_warm_edwin_jarvis.sql | 20 ++++++++++ drizzle/meta/0000_snapshot.json | 15 ++++++++ drizzle/meta/_journal.json | 13 +++++++ package.json | 4 +- public/favicon.ico | Bin 15406 -> 0 bytes public/favicon.png | Bin 0 -> 16730 bytes src/app/api/messages/get/route.ts | 41 ++++++++++++++++++++ src/app/api/messages/send/route.ts | 41 ++++++++++++++++++++ src/app/layout.tsx | 6 +-- src/app/page.tsx | 60 ++++++++++++++--------------- src/server/db/schema.ts | 2 + src/server/functions.ts | 39 +++++++++++++++++-- 12 files changed, 202 insertions(+), 39 deletions(-) create mode 100644 drizzle/0000_warm_edwin_jarvis.sql create mode 100644 drizzle/meta/0000_snapshot.json create mode 100644 drizzle/meta/_journal.json delete mode 100755 public/favicon.ico create mode 100755 public/favicon.png create mode 100644 src/app/api/messages/get/route.ts create mode 100644 src/app/api/messages/send/route.ts diff --git a/drizzle/0000_warm_edwin_jarvis.sql b/drizzle/0000_warm_edwin_jarvis.sql new file mode 100644 index 0000000..09b3813 --- /dev/null +++ b/drizzle/0000_warm_edwin_jarvis.sql @@ -0,0 +1,20 @@ +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(); diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json new file mode 100644 index 0000000..944a48e --- /dev/null +++ b/drizzle/meta/0000_snapshot.json @@ -0,0 +1,15 @@ +{ + "id": "ba7dd70a-8dd6-41be-b1d2-158ab83ba830", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": {}, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json new file mode 100644 index 0000000..8ca6fba --- /dev/null +++ b/drizzle/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1729627211020, + "tag": "0000_warm_edwin_jarvis", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index e83ae79..0d6f7a2 100755 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "dev": "next dev", "lint": "next lint", "start": "next start", - "go": "pnpm dev", - "go:prod": "pnpm build && pnpm start" + "go": "next dev", + "go:prod": "next build && next start" }, "dependencies": { "@t3-oss/env-nextjs": "^0.10.1", diff --git a/public/favicon.ico b/public/favicon.ico deleted file mode 100755 index 60c702aac13409c82c4040f8fee9603eb84aa10c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15406 zcmeHOX^b4j6>hH&u3!wtgoMM(Da<7x5Rn8Tjvq)?zybua1c*c20{$U^Aj%>HD9R-z zBuWB;ARB>eYK+y}Dk#s*$8Q(p+iLA_;N7bn84x`l%#I{rywlCmbkAPayBK)27Rhm!$WXNYV+Q zK^4@P%189Q__>DsD^FL?7r_P=JJvIlKl+CJ62dyd9WqHP5Sp7xG3? zPX~|xApI@EB+@r<8Zj2@M^QA-H<*IF*CS2am*|i;*E8hDd|es0ZRN*eT}q4f={qph zUyoWUdZ+R8ip52QA+%;l|Sa2^7!PrYAH1GAw4nmfKx zy1+M;Td^MB<(cfVs$m?`u57IHH)D=|NWm@3zi7tCFgENLSn7k=Pdv~@u`r2!VJ-Hn z5cXiS66w9>LT56iNCfU;)=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%-T=dC&PcQue_TD(`)d{Ti zpVECPFYhF77eC3Qa|(3&+O+N)x;5nYT$7zD;-a%M-T>Z>_WovzZD*cO#ky(fPVm!M z4>50XE?F;*jp_Cb#^0xcejdVtG(4@Ab%LME8grb(VULnMQ(qTr?XlS4sA=Z%WpG}t z#@)bAGHE<}Ce}x+=VD)Aj=U1KY1`*%OSkaTSaNZniT#y)LG`(S^d#o(f0N$S=E0Xm z69nua-)1-RfN`**lRLwjZKf-mfScCTMmtQlmSkn&*%Qh=t8_ZBe~{3IHMCdn2^iBb zU@Z0dnsO%gtl?N6Y{&Y!ir&Ac*2mk5ac|mxL_VZh2;?)RIUwSqJpgNKaYjEF@;@WI zV;5<~G|ty}hr~8c`6=kme>Q^rmKXb<0b#1W2{PGdGuxm%Zdt`cMch0MyXbn%Lwe)X zm_Ofrn*7V_#@MFAI1Y+wEV-6^4ls%5b>Nb>VQu|ugs~#hQ+hYypVk$7do)3>4&JN5 z*Qv&IioJq8V&L9GYy;NYm7v3!Od*?f)&p$Ie z=7xjyDDv&@jzB)Sqc--SY9FM2yJ2IM#O`-=V2OZPO;(?CxHJq`3Uu%~L^f2g^2 A#Q*>R diff --git a/public/favicon.png b/public/favicon.png new file mode 100755 index 0000000000000000000000000000000000000000..3d18e5602016ac2bd80d051bd1d3f59eeb8a747a GIT binary patch literal 16730 zcmV+DKo`G>P);B0?hy>|C!e-03^?c3?@ zs}MkMtM}T{qwPcz0R^>jY*au<Dp)%tI1FhBKcU_g>#0Z&h+~PVE}^uDz?y`905h z0_W6z-&Iw6t^L01U4yX5fC>P0E9t}mXMPh*!wE&BRhi>K_*xcEI@&mjG;U3-0y8{<& zk=U@f0_Z_>Gf9-s0e>FMfcz^Ke2w^cZ?AhhpazZstscTL@420ggcVgvuFUi9Nolf;6H(Z4o=&TaHDSI z4IP|wkq}t)0dz6CiF1MP0jY>YC;%7A8h#kj{EM{7q5gR9kJrjY z{4!!W7HNS+1JH%&H#rfTUjR#^mZi)tY|fFlu_bCj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Efl;AW|Q-6$Fh_L8c10Wagn5G-H z0W)3X2dH4{!fD?v+*OV%=}CIl0F?P<)B@C{V0TA6z+4g@tXKd>K;`zRMF^8Fyz`ns zy1)QHysH=2BITNuKo|Kjo2Fatp%&?F13;Hp?`|~!U;=~==vgD6INTAn5Mk2O20$*E zco=vhYB}nXv!U3u@aPT$FqMc}g7!(3J0ADS5uvwe0J@*t#4W&d)MC`7WI?veR{;P?4_3|e zLW9nS<T2>+w*!VHL20Y~r23eNhV%D7M0i>=RhtJAvn-7N;&M|2Jw8I>mx8001OQ zUxH{_FgJh#U&G}@xp?B6z+Xo#P~ZrEB^OVB6VG}+=og4@qSj9OCa#ZKh)%I!41jzr zyA{#vqL!lyx1yXa>n7hLpPbwcAZz$8!p|a>D>#JT@dq{n$YtZBvTo`xu{ayJHDbxC z@h|cb7EC?#1!DjV_GhD(U@yv@C>P4Q$(PHelk?-vJuV}@Ps!%+xK!5f|6b(c$zRF3 z$(JKs0Q^28$>x$HQCcv|e^_7!KrR`-8|0@Ei}7nz-XNDwo+Xz~e%J3svX(ng{-u+G zg~Uy=mYe)Vi`J0Z>Dh6KrbJ95tiObXWx4sa4{PV}DhwGIo@09-wA0_{C%6lcqm(d zI}mQe((lW~Q-Pmz>t>ds+y@*I^w=S>3y;&~BAyO81JF&VB5dN?*!ly6@9_uTIQPtdk@&J`0J;qQ zD*dFm9XK^=S?2H%NzRftv)~+Q-OQo^=tA^*4yVLz#K$T4G{V`knx~=`WRd1rP?3PW zg1nU{v3WH#9$*t9yHL(sRQ~Q{(ExNQ@-`kuIS(RTa!(+fFKfG?1Jfc^Su_A$jI8B8 zJT3$#BA9*>xIk9(+X&`fBp?=j06l2z@G06i@ { + 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 } + ); + } + } +}; diff --git a/src/app/api/messages/send/route.ts b/src/app/api/messages/send/route.ts new file mode 100644 index 0000000..5e5323d --- /dev/null +++ b/src/app/api/messages/send/route.ts @@ -0,0 +1,41 @@ +'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 } + ); + } + } +}; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 42ed47c..d797777 100755 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -4,9 +4,9 @@ import { GeistSans } from "geist/font/sans"; import { type Metadata } from "next"; export const metadata: Metadata = { - title: "Create T3 App", - description: "Generated by create-t3-app", - icons: [{ rel: "icon", url: "/favicon.ico" }], + title: "Is Madeline the Cutest?", + description: "Answering the easiest question in the world!", + icons: [{ rel: "icon", url: "/favicon.png" }], }; export default function RootLayout({ diff --git a/src/app/page.tsx b/src/app/page.tsx index 773fef1..54a891a 100755 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,37 +1,35 @@ -import Link from "next/link"; +"use client"; +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() { + const [currentText, setCurrentText] = useState(""); + useEffect(() => { + setCurrentText(interestingYes() ?? "Absolutely, yes."); + }, []); + const handleClick = () => { + setCurrentText(interestingYes() ?? "Absolutely, yes."); + }; return ( -
-
-

- Create T3 App -

-
- -

First Steps →

-
- Just the basics - Everything you need to know to set up your - database and authentication. -
- - -

Documentation →

-
- Learn more about Create T3 App, the libraries it uses, and how to - deploy it. -
- -
-
+
+

+ {currentText} +

); } diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts index a0cf622..25fa70e 100755 --- a/src/server/db/schema.ts +++ b/src/server/db/schema.ts @@ -1,4 +1,5 @@ // https://orm.drizzle.team/docs/sql-schema-declaration +import { db } from '~/server/db'; import { sql } from "drizzle-orm"; import { boolean, @@ -161,3 +162,4 @@ export const quickReplyOptions = pgTable( quickReplyIdIndex: index('qr_options_quick_reply_id_idx').on(table.quickReplyId), }) ); + diff --git a/src/server/functions.ts b/src/server/functions.ts index fce176b..d5348b8 100755 --- a/src/server/functions.ts +++ b/src/server/functions.ts @@ -1,7 +1,7 @@ import 'server-only'; import { db } from '~/server/db'; import * as schema from '~/server/db/schema'; -import { eq, and, or, like, not } from 'drizzle-orm'; +import { eq, and, or, like, not, desc, sql } from 'drizzle-orm'; import { User, Relationship, UserRelationship, @@ -227,7 +227,7 @@ export const updateRelationshipStatus = async ( } const relationship = relationships[0] as Relationship; // Everything above is just getting info - if (userId === relationship.requestorId) { + if (userId === relationship.requestorId && status === 'accepted') { throw new Error('The requestor cannot accept the relationship they requested.'); } if (status === 'accepted') { @@ -255,7 +255,7 @@ export const updateRelationshipStatus = async ( return relationshipData; } else if (status === 'rejected') { await db.delete(schema.userRelationships) - .where(eq(schema.userRelationships.id, userRelationship.id)); + .where(eq(schema.userRelationships.relationshipId, relationship.id)); await db.delete(schema.relationships) .where(eq(schema.relationships.id, relationship.id)); return null; @@ -325,3 +325,36 @@ 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; + } +};