Skip to content

Commit ffc0bbd

Browse files
committed
basic functionality
1 parent 5ed0fed commit ffc0bbd

File tree

10 files changed

+1077
-140
lines changed

10 files changed

+1077
-140
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515

1616
# Get this from https://github.com/settings/tokens
1717
# Required scopes: repo, read:user
18-
GITHUB_TOKEN=""
18+
GITHUB_TOKEN=your_github_token_here
1919

2020
# Get this from https://platform.openai.com/api-keys
2121
OPENAI_API_KEY=""
2222

2323
# Get your Anthropic API key here: https://console.anthropic.com/
2424
ANTHROPIC_API_KEY=""
25+
26+
# Get this from your Supabase project settings
27+
DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres"
28+
SUPABASE_URL="https://[YOUR-PROJECT-REF].supabase.co"
29+
SUPABASE_ANON_KEY="your-anon-key"
30+
SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"

package-lock.json

Lines changed: 178 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
},
1818
"dependencies": {
1919
"@anthropic-ai/sdk": "^0.33.1",
20+
"@prisma/client": "^6.1.0",
21+
"@supabase/supabase-js": "^2.47.10",
2022
"@t3-oss/env-nextjs": "^0.10.1",
2123
"geist": "^1.3.0",
2224
"next": "^15.0.1",
2325
"openai": "^4.77.0",
26+
"prisma": "^6.1.0",
2427
"react": "^18.3.1",
2528
"react-dom": "^18.3.1",
2629
"react-markdown": "^9.0.1",

prisma/schema.prisma

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
5+
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
6+
7+
generator client {
8+
provider = "prisma-client-js"
9+
}
10+
11+
datasource db {
12+
provider = "postgresql"
13+
url = env("DATABASE_URL")
14+
}
15+
16+
model ActivitySession {
17+
id String @id
18+
username String
19+
startTime DateTime
20+
endTime DateTime
21+
summary String @db.Text
22+
commits Json? // Store commits as JSON array
23+
issues Json? // Store issues as JSON array
24+
pullRequests Json? // Store PRs as JSON array
25+
createdAt DateTime @default(now())
26+
updatedAt DateTime @updatedAt
27+
28+
@@index([username])
29+
@@index([startTime, endTime])
30+
}

src/app/api/activity/route.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { NextResponse } from "next/server";
2+
import { prisma } from "../../../lib/db";
3+
4+
export async function POST(request: Request) {
5+
try {
6+
const body = await request.json();
7+
const { id, username, startTime, endTime, summary, commits, issues, pullRequests } = body;
8+
9+
if (!id || !username || !startTime || !endTime) {
10+
return NextResponse.json(
11+
{ error: "Missing required fields" },
12+
{ status: 400 }
13+
);
14+
}
15+
16+
const activity = await prisma.activitySession.create({
17+
data: {
18+
id,
19+
username,
20+
startTime: new Date(startTime),
21+
endTime: new Date(endTime),
22+
summary: summary || "",
23+
commits: commits || null,
24+
issues: issues || null,
25+
pullRequests: pullRequests || null,
26+
},
27+
});
28+
29+
return NextResponse.json(activity);
30+
} catch (error: any) {
31+
console.error("Error saving activity:", error);
32+
return NextResponse.json(
33+
{ error: error.message || "Internal server error" },
34+
{ status: 500 }
35+
);
36+
}
37+
}
38+
39+
export async function GET(request: Request) {
40+
try {
41+
const { searchParams } = new URL(request.url);
42+
const username = searchParams.get("username");
43+
const id = searchParams.get("id");
44+
45+
if (id) {
46+
const activity = await prisma.activitySession.findUnique({
47+
where: { id }
48+
});
49+
return NextResponse.json(activity);
50+
}
51+
52+
if (username) {
53+
const activities = await prisma.activitySession.findMany({
54+
where: { username },
55+
orderBy: { startTime: 'desc' },
56+
take: 10
57+
});
58+
return NextResponse.json(activities);
59+
}
60+
61+
const activities = await prisma.activitySession.findMany({
62+
orderBy: { startTime: 'desc' },
63+
take: 10
64+
});
65+
return NextResponse.json(activities);
66+
} catch (error: any) {
67+
console.error("Error fetching activities:", error);
68+
return NextResponse.json(
69+
{ error: error.message || "Internal server error" },
70+
{ status: 500 }
71+
);
72+
}
73+
}

0 commit comments

Comments
 (0)