Spaces:
Sleeping
Sleeping
Commit ·
fa66bf2
1
Parent(s): 4f889a3
apply changes
Browse files
src/app/api/contributor/tracked-repos/route.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Tracked Repositories Route
|
| 3 |
+
*
|
| 4 |
+
* GET /api/contributor/tracked-repos - Get repositories the user has explicitly tracked
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 8 |
+
import { getCurrentUser } from "@/lib/auth";
|
| 9 |
+
import { db } from "@/db";
|
| 10 |
+
import { repositories } from "@/db/schema";
|
| 11 |
+
import { eq, and } from "drizzle-orm";
|
| 12 |
+
|
| 13 |
+
export async function GET(request: NextRequest) {
|
| 14 |
+
try {
|
| 15 |
+
const user = await getCurrentUser(request);
|
| 16 |
+
if (!user) {
|
| 17 |
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
// Fetch repositories that the user has explicitly added
|
| 21 |
+
const trackedRepos = await db
|
| 22 |
+
.select({
|
| 23 |
+
id: repositories.id,
|
| 24 |
+
name: repositories.name,
|
| 25 |
+
owner: repositories.owner,
|
| 26 |
+
createdAt: repositories.createdAt,
|
| 27 |
+
})
|
| 28 |
+
.from(repositories)
|
| 29 |
+
.where(
|
| 30 |
+
and(
|
| 31 |
+
eq(repositories.userId, user.id),
|
| 32 |
+
eq(repositories.addedByUser, true)
|
| 33 |
+
)
|
| 34 |
+
)
|
| 35 |
+
.orderBy(repositories.createdAt);
|
| 36 |
+
|
| 37 |
+
// Return just the repository names for easy consumption
|
| 38 |
+
const repoNames = trackedRepos.map(repo => repo.name);
|
| 39 |
+
|
| 40 |
+
return NextResponse.json({
|
| 41 |
+
repositories: repoNames,
|
| 42 |
+
count: repoNames.length,
|
| 43 |
+
details: trackedRepos, // Include full details for potential future use
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
} catch (error) {
|
| 47 |
+
console.error("GET /api/contributor/tracked-repos error:", error);
|
| 48 |
+
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
| 49 |
+
}
|
| 50 |
+
}
|