Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
39 changes: 38 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,41 @@ server

# DO NOT REMOVE THESE FOR SECURITY
src/config.js
.env
.env

# web

# dependencies
web/node_modules
web/.pnp
web/.pnp.js

# testing
web/coverage

# next.js
web/.next/
web/out/

# production
web/build

# misc
web/.DS_Store
web/*.pem

# debug
web/npm-debug.log*
web/yarn-debug.log*
web/yarn-error.log*

# local env files
web/.env*.local
web/.env

# vercel
web/.vercel

# typescript
web/*.tsbuildinfo
web/next-env.d.ts
Binary file added web/.DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copy from .env.local on the Vercel dashboard
# https://nextjs.org/learn/dashboard-app/setting-up-your-database#create-a-postgres-database
POSTGRES_URL=
POSTGRES_PRISMA_URL=
POSTGRES_URL_NON_POOLING=
POSTGRES_USER=
POSTGRES_HOST=
POSTGRES_PASSWORD=
POSTGRES_DATABASE=
MONGODB_URI=

# `openssl rand -base64 32`
AUTH_SECRET=
AUTH_URL=http://localhost:3000/api/auth
3 changes: 3 additions & 0 deletions web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
1 change: 1 addition & 0 deletions web/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
5 changes: 5 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Next.js App Router Course - Starter

This is the starter template for the Next.js App Router Course. It contains the starting code for the dashboard application.

For more information, see the [course curriculum](https://nextjs.org/learn) on the Next.js Website.
Binary file added web/app/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions web/app/api/auth/[...nextauth]/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { handlers } from "@/auth"
export const { GET, POST } = handlers
29 changes: 29 additions & 0 deletions web/app/api/latest/commandCount/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import dbConnect, { setupChangeStream } from '@/lib/dbConnect';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, fetchCommandsLength } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const commandCount = await fetchCommandsLength();
return NextResponse.json(commandCount, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest command count' + error } },
{ status: 500 }
);
}
};
29 changes: 29 additions & 0 deletions web/app/api/latest/commandTrend/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import dbConnect, { setupChangeStream } from '@/lib/dbConnect';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, getCommandTrend } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const percent = await getCommandTrend();
return NextResponse.json(percent, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest command count' + error } },
{ status: 500 }
);
}
};
29 changes: 29 additions & 0 deletions web/app/api/latest/commands/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import dbConnect, { setupChangeStream } from '@/lib/dbConnect';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, fetchLatestCommands } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const initialCommands = await fetchLatestCommands();
return NextResponse.json(initialCommands, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest commands' + error } },
{ status: 500 }
);
}
};
33 changes: 33 additions & 0 deletions web/app/api/latest/countData/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, fetchCommandsLength, fetchTotalFishCaught, fetchUserCount, getCommandTrend, getFishTrend, getUserTrend } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const initialCommandCount = await fetchCommandsLength();
const initialCommandTrend = await getCommandTrend();
const initialUserCount = await fetchUserCount();
const initialUserTrend = await getUserTrend();
const initialFishCount = await fetchTotalFishCaught();
const initialFishTrend = await getFishTrend();
return NextResponse.json({ commands: initialCommandCount, commandTrend: initialCommandTrend, users: initialUserCount, userTrend: initialUserTrend, fish: initialFishCount, fishTrend: initialFishTrend }, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest fish count' + error } },
{ status: 500 }
);
}
};
29 changes: 29 additions & 0 deletions web/app/api/latest/fishCount/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import dbConnect, { setupChangeStream } from '@/lib/dbConnect';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, fetchTotalFishCaught } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const fishCount = await fetchTotalFishCaught();
return NextResponse.json(fishCount, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest fish count' + error } },
{ status: 500 }
);
}
};
29 changes: 29 additions & 0 deletions web/app/api/latest/fishTrend/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import dbConnect, { setupChangeStream } from '@/lib/dbConnect';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, getFishTrend } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const percent = await getFishTrend();
return NextResponse.json(percent, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest command count' + error } },
{ status: 500 }
);
}
};
29 changes: 29 additions & 0 deletions web/app/api/latest/userCount/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import dbConnect, { setupChangeStream } from '@/lib/dbConnect';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, fetchUserCount } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const userCount = await fetchUserCount();
return NextResponse.json(userCount, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest user count' + error } },
{ status: 500 }
);
}
};
29 changes: 29 additions & 0 deletions web/app/api/latest/userTrend/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import dbConnect, { setupChangeStream } from '@/lib/dbConnect';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
import { checkIfUserIsAdmin, getUserTrend } from '@/app/lib/data';
import { auth } from '@/auth';

export const GET = async (req: NextApiRequest) => {
try {
const session = await auth();
const id = session?.user?.image?.split('/')[4]?.split('.')[0] ?? '';
const admin = await checkIfUserIsAdmin(id);

if (!session || !admin) {
return NextResponse.json(
{ error: { message: 'Not authorized' } },
{ status: 401 }
);
}

const percent = await getUserTrend();
return NextResponse.json(percent, { status: 200 });

} catch (error) {
return NextResponse.json(
{ error: { message: 'Error fetching latest command count' + error } },
{ status: 500 }
);
}
};
Loading