Skip to content

Commit e5d47ae

Browse files
committed
set up actual pages
1 parent bcd7d09 commit e5d47ae

File tree

30 files changed

+233
-83
lines changed

30 files changed

+233
-83
lines changed

bun.lock

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"workspaces": {
44
"": {
55
"name": "syllabus",
6+
"dependencies": {
7+
"@elysiajs/eden": "^1.3.2",
8+
"elysia": "^1.3.6",
9+
},
610
"devDependencies": {
711
"@biomejs/biome": "^2.1.1",
812
"concurrently": "^9.2.0",
@@ -51,19 +55,14 @@
5155
"@packages/models": "workspace:*",
5256
"@sinclair/typebox": "^0.34.38",
5357
},
54-
"devDependencies": {
55-
"@types/bun": "^1.2.19",
56-
},
57-
"peerDependencies": {
58-
"typescript": "^5",
59-
},
6058
},
6159
"packages/web": {
6260
"name": "@packages/web",
6361
"version": "0.1.0",
6462
"dependencies": {
6563
"@elysiajs/eden": "^1.3.2",
6664
"@headlessui/react": "^2.2.4",
65+
"@packages/models": "workspace:models",
6766
"@packages/server": "workspace:*",
6867
"@sinclair/typebox": "^0.34.38",
6968
"@tanstack/react-query": "^5.83.0",
@@ -629,7 +628,7 @@
629628

630629
"electron-to-chromium": ["[email protected]", "", {}, "sha512-k4McmnB2091YIsdCgkS0fMVMPOJgxl93ltFzaryXqwip1AaxeDqKCGLxkXODDA5Ab/D+tV5EL5+aTx76RvLRxw=="],
631630

632-
"elysia": ["[email protected].5", "", { "dependencies": { "cookie": "^1.0.2", "exact-mirror": "0.1.2", "fast-decode-uri-component": "^1.0.1" }, "optionalDependencies": { "@sinclair/typebox": "^0.34.33", "openapi-types": "^12.1.3" }, "peerDependencies": { "file-type": ">= 20.0.0", "typescript": ">= 5.0.0" } }, "sha512-XVIKXlKFwUT7Sta8GY+wO5reD9I0rqAEtaz1Z71UgJb61csYt8Q3W9al8rtL5RgumuRR8e3DNdzlUN9GkC4KDw=="],
631+
"elysia": ["[email protected].6", "", { "dependencies": { "cookie": "^1.0.2", "exact-mirror": "0.1.2", "fast-decode-uri-component": "^1.0.1" }, "optionalDependencies": { "@sinclair/typebox": "^0.34.33", "openapi-types": "^12.1.3" }, "peerDependencies": { "file-type": ">= 20.0.0", "typescript": ">= 5.0.0" } }, "sha512-NPjbt42KlLzf98JN/3Uvzg3oVFCzEle9gJnRtwUxYGQd61Bm7sE1h8FMqQVdXRCoxmz1T+jhhoB+p1YjDdwEzQ=="],
633632

634633
"emoji-regex": ["[email protected]", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
635634

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@
1717
"devDependencies": {
1818
"@biomejs/biome": "^2.1.1",
1919
"concurrently": "^9.2.0"
20+
},
21+
"dependencies": {
22+
"@elysiajs/eden": "^1.3.2",
23+
"elysia": "^1.3.6"
2024
}
2125
}

packages/server/app.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { cors } from "@elysiajs/cors";
22
import { Elysia } from "elysia";
3-
import { betterAuth } from "./lib/auth.ts";
3+
import { betterAuth } from "@/lib/auth.ts";
44
import coursesRouter from "./router/courses.ts";
5+
import usersRouter from "./router/users.ts";
56

67
export const app = new Elysia({
78
prefix: "/api",
89
})
9-
.use(betterAuth)
1010
.use(cors())
11-
.group("/courses", (route) => route.use(coursesRouter));
11+
.use(betterAuth)
12+
.use(coursesRouter)
13+
.use(usersRouter);
1214

1315
export type App = typeof app;

packages/server/db/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { drizzle } from "drizzle-orm/libsql";
22
import { env } from "../lib/env.ts";
3+
import * as schema from "./schema.ts";
34

45
export const db = drizzle({
56
connection: { url: env.DATABASE_URL },
7+
schema,
68
});

packages/server/db/schema.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { relations } from "drizzle-orm";
12
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
23

3-
// auth
44
export const user = sqliteTable("users", {
55
id: text("id").primaryKey(),
66
name: text("name").notNull(),
@@ -16,7 +16,34 @@ export const user = sqliteTable("users", {
1616
.$defaultFn(() => /* @__PURE__ */ new Date())
1717
.notNull(),
1818
});
19+
export const userData = sqliteTable("user_data", {
20+
id: text("id").primaryKey(),
21+
userId: text("user_id")
22+
.notNull()
23+
.references(() => user.id, { onDelete: "cascade" }),
24+
stream: text("stream"),
25+
grade: integer("grade"),
26+
classNumber: integer("class_number"),
27+
});
28+
export const userCourse = sqliteTable("user_courses", {
29+
id: text("id").primaryKey(),
30+
userId: text("user_id")
31+
.notNull()
32+
.references(() => user.id, { onDelete: "cascade" }),
33+
code: text("code").notNull(),
34+
});
35+
export const userRelations = relations(user, ({ one }) => ({
36+
courses: one(userCourse, {
37+
fields: [user.id],
38+
references: [userCourse.userId],
39+
}),
40+
data: one(userData, {
41+
fields: [user.id],
42+
references: [userData.userId],
43+
}),
44+
}));
1945

46+
// auth-related tables
2047
export const session = sqliteTable("sessions", {
2148
id: text("id").primaryKey(),
2249
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),

packages/server/lib/auth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export const auth = betterAuth({
1717
},
1818
},
1919
trustedOrigins: [env.PUBLIC_WEB_URL],
20+
advanced: {
21+
cookiePrefix: "x_utcode_syllabus_",
22+
},
2023
});
2124

2225
const betterAuthMacro = new Elysia({ name: "better-auth" })

packages/server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "module",
55
"private": true,
66
"exports": {
7-
".": "./app.ts"
7+
".": "./app.ts",
8+
"./types": "./types.ts"
89
},
910
"scripts": {
1011
"dev": "bun --env-file=../../.env run --watch ./serve.ts"

packages/server/router/courses.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const semesterCoursesMap = new Map<string, CourseList>([
88
["2024A", Value.Parse(CourseList, courses2024A)],
99
]);
1010

11-
const router = new Elysia().get(
11+
const router = new Elysia({
12+
prefix: "/courses",
13+
}).get(
1214
"/",
1315
({ query, set }) => {
1416
const courses = semesterCoursesMap.get(query.name);

packages/server/router/users.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { eq } from "drizzle-orm";
2+
import Elysia from "elysia";
3+
import { db } from "@/db/client";
4+
import { betterAuth } from "@/lib/auth.ts";
5+
6+
const router = new Elysia({
7+
prefix: "/users",
8+
})
9+
.use(betterAuth)
10+
.get(
11+
"/me",
12+
async ({ user: { id: currentUserId } }) => {
13+
const fullUser = await db.query.user.findFirst({
14+
where: (user) => eq(user.id, currentUserId),
15+
with: {
16+
data: true,
17+
courses: true,
18+
},
19+
});
20+
return fullUser;
21+
},
22+
{
23+
auth: true,
24+
},
25+
);
26+
27+
export default router;

packages/server/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"moduleResolution": "bundler",
1313
"allowImportingTsExtensions": true,
1414
"verbatimModuleSyntax": true,
15-
"noEmit": true
15+
"noEmit": true,
16+
"baseUrl": ".",
17+
"paths": {
18+
"@/*": ["./*"]
19+
}
1620
}
1721
}

0 commit comments

Comments
 (0)