Skip to content

Commit fbfe425

Browse files
committed
add:many
1 parent cc73fab commit fbfe425

File tree

10 files changed

+2170
-106
lines changed

10 files changed

+2170
-106
lines changed

schema.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// src/lib/db/schema.ts
2+
import {
3+
pgTable,
4+
serial,
5+
text,
6+
boolean,
7+
integer,
8+
timestamp,
9+
uniqueIndex,
10+
varchar,
11+
real,
12+
primaryKey,
13+
} from "drizzle-orm/pg-core";
14+
15+
// --- User ---
16+
export const users = pgTable("User", {
17+
id: serial("id").primaryKey(),
18+
Firstname: text("Firstname").notNull(),
19+
Lastname: text("Lastname").notNull(),
20+
username: text("username").notNull(),
21+
email: text("email").notNull(),
22+
hashedpass: text("hashedpass").notNull(),
23+
description: text("description"),
24+
isbanned: boolean("isbanned").notNull().default(false),
25+
},
26+
(table) => ({
27+
usernameIndex: uniqueIndex("username_idx").on(table.username),
28+
emailIndex: uniqueIndex("email_idx").on(table.email),
29+
}));
30+
31+
// --- Category ---
32+
export const categories = pgTable("Category", {
33+
id: serial("id").primaryKey(),
34+
name: text("name").notNull(),
35+
description: text("description"),
36+
app_read: boolean("app_read").notNull().default(false),
37+
app_write: boolean("app_write").notNull().default(false),
38+
creationdate: timestamp("creationdate").defaultNow().notNull(),
39+
isdisable: boolean("isdisable").notNull().default(false),
40+
ishidden: boolean("ishidden").notNull().default(false),
41+
totaltopics: integer("totaltopics").notNull().default(0),
42+
createby: integer("createby").notNull(),
43+
}, (table) => ({
44+
nameIndex: uniqueIndex("name_idx").on(table.name),
45+
}));
46+
47+
// --- Post ---
48+
export const posts = pgTable("Post", {
49+
id: serial("id").primaryKey(),
50+
name: text("name").notNull(),
51+
description: text("description"),
52+
createby: integer("createby").notNull(),
53+
creation_date: timestamp("creation_date").defaultNow().notNull(),
54+
last_edited: timestamp("last_edited").notNull(),
55+
app_read: boolean("app_read").notNull().default(false),
56+
app_write: boolean("app_write").notNull().default(false),
57+
isdisable: boolean("isdisable").notNull().default(false),
58+
ishidden: boolean("ishidden").notNull().default(false),
59+
maplocation: text("maplocation"),
60+
categoryId: integer("categoryId").notNull(),
61+
});
62+
63+
// --- Review ---
64+
export const reviews = pgTable("Review", {
65+
id: serial("id").primaryKey(),
66+
userid: integer("userid").notNull(),
67+
topicid: integer("topicid").notNull(),
68+
title: text("title").notNull(),
69+
description: text("description").notNull(),
70+
});
71+
72+
// --- Log ---
73+
export const logs = pgTable("Log", {
74+
id: serial("id").primaryKey(),
75+
action: text("action").notNull(),
76+
who: integer("who").notNull(),
77+
ondate: timestamp("ondate").defaultNow().notNull(),
78+
});
79+
80+
// --- Session ---
81+
export const sessions = pgTable("Session", {
82+
id: varchar("id", { length: 255 }).primaryKey(),
83+
userId: integer("userId").notNull(),
84+
expiresAt: timestamp("expiresAt").notNull(),
85+
});
86+
87+
// --- Key ---
88+
export const keys = pgTable("Key", {
89+
id: varchar("id", { length: 255 }).primaryKey(),
90+
userId: integer("userId").notNull(),
91+
hashedPassword: text("hashedPassword"),
92+
});
93+
94+
// --- Stargazing ---
95+
export const stargazing = pgTable("Stargazing", {
96+
id: serial("id").primaryKey(),
97+
title: text("title").notNull(),
98+
description: text("description"),
99+
lat: real("lat").notNull(),
100+
long: real("long").notNull(),
101+
});

src/components/navbar.svelte

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
<script lang="ts">
2+
import { redirect } from "@sveltejs/kit";
3+
4+
let isMobileMenuOpen = $state(false);
5+
6+
function toggleMobileMenu() {
7+
isMobileMenuOpen = !isMobileMenuOpen;
8+
}
9+
10+
let { data } = $props();
11+
12+
function handleLoginClick() {
13+
// Add login functionality here
14+
console.log('Login clicked');
15+
throw redirect(303,'/login ');
16+
17+
}
18+
19+
async function handleLogout() {
20+
try {
21+
const res = await fetch('/api/auth/logout', {
22+
method: 'POST'
23+
});
24+
25+
// Redirect to login page after successful logout
26+
throw redirect(303,'/');
27+
28+
} catch (e) {
29+
console.error('Logout failed:', e);
30+
}
31+
}
32+
33+
</script>
34+
35+
<header class="header">
36+
<div class="logo">
37+
<div class="logo-icon"></div>
38+
<span>ไลก์</span>
39+
</div>
40+
41+
<nav>
42+
<ul class="nav-menu">
43+
<li><a href="#" >หน้าหลัก</a></li>
44+
<li><a href="#" >บทความ</a></li>
45+
<li><a href="#" >ข้อมูลดวงดาว</a></li>
46+
<li><a href="#" >กิจกรรม</a></li>
47+
</ul>
48+
</nav>
49+
{#if data.user}
50+
<button class="login-btn" onclick={handleLogout}>
51+
<h2>Welcome, {data.user.username}!</h2>
52+
<p>Your email: {data.user.email}</p>
53+
</button>
54+
{:else}
55+
<a class="login-btn" href="/login">
56+
ล็อคอิน/สมัครสมาชิก
57+
</a>
58+
{/if}
59+
</header>
60+
61+
<style>
62+
.header {
63+
background-color: #1a1a1a;
64+
padding: 1rem;
65+
display: flex;
66+
justify-content: space-between;
67+
align-items: center;
68+
border-bottom: 1px solid #333;
69+
position: sticky;
70+
top: 0;
71+
z-index: 1000;
72+
flex-wrap: wrap;
73+
}
74+
75+
.logo {
76+
display: flex;
77+
align-items: center;
78+
gap: 0.5rem;
79+
font-weight: 500;
80+
font-size: 1.1rem;
81+
color: white;
82+
}
83+
84+
.logo-icon {
85+
width: 24px;
86+
height: 24px;
87+
background-color: white;
88+
border-radius: 50%;
89+
}
90+
91+
.nav-menu {
92+
display: flex;
93+
gap: 1rem;
94+
list-style: none;
95+
flex-wrap: wrap;
96+
margin: 0;
97+
padding: 0;
98+
}
99+
100+
.nav-menu a {
101+
color: white;
102+
text-decoration: none;
103+
padding: 0.5rem 0.8rem;
104+
border-radius: 4px;
105+
transition: background-color 0.3s;
106+
font-size: 14px;
107+
white-space: nowrap;
108+
cursor: pointer;
109+
}
110+
111+
.nav-menu a:hover {
112+
background-color: rgba(255, 255, 255, 0.1);
113+
}
114+
115+
.login-btn {
116+
background-color: #4a90e2;
117+
color: white;
118+
padding: 0.6rem 1rem;
119+
border: none;
120+
border-radius: 6px;
121+
cursor: pointer;
122+
font-size: 14px;
123+
transition: background-color 0.3s;
124+
white-space: nowrap;
125+
font-family: inherit;
126+
}
127+
128+
.login-btn:hover {
129+
background-color: #357abd;
130+
}
131+
132+
@media (max-width: 768px) {
133+
.header {
134+
padding: 0.8rem;
135+
flex-direction: column;
136+
gap: 1rem;
137+
}
138+
139+
.nav-menu {
140+
order: 3;
141+
width: 100%;
142+
justify-content: center;
143+
gap: 0.5rem;
144+
}
145+
146+
.nav-menu a {
147+
padding: 0.4rem 0.6rem;
148+
font-size: 12px;
149+
}
150+
151+
.login-btn {
152+
order: 2;
153+
padding: 0.5rem 1rem;
154+
font-size: 12px;
155+
}
156+
}
157+
158+
@media (max-width: 480px) {
159+
.header {
160+
padding: 0.6rem;
161+
}
162+
163+
.logo {
164+
font-size: 1rem;
165+
}
166+
167+
.nav-menu {
168+
gap: 0.3rem;
169+
}
170+
171+
.nav-menu a {
172+
padding: 0.3rem 0.5rem;
173+
font-size: 11px;
174+
}
175+
176+
.login-btn {
177+
padding: 0.4rem 0.8rem;
178+
font-size: 11px;
179+
}
180+
}
181+
</style>

src/db/schema.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// src/lib/db/schema.ts
2+
import {
3+
pgTable,
4+
serial,
5+
text,
6+
boolean,
7+
integer,
8+
timestamp,
9+
uniqueIndex,
10+
varchar,
11+
real,
12+
primaryKey,
13+
} from "drizzle-orm/pg-core";
14+
15+
// --- User ---
16+
export const users = pgTable("User", {
17+
id: serial("id").primaryKey(),
18+
Firstname: text("Firstname").notNull(),
19+
Lastname: text("Lastname").notNull(),
20+
username: text("username").notNull(),
21+
email: text("email").notNull(),
22+
hashedpass: text("hashedpass").notNull(),
23+
description: text("description"),
24+
isbanned: boolean("isbanned").notNull().default(false),
25+
},
26+
(table) => ({
27+
usernameIndex: uniqueIndex("username_idx").on(table.username),
28+
emailIndex: uniqueIndex("email_idx").on(table.email),
29+
}));
30+
31+
// --- Category ---
32+
export const categories = pgTable("Category", {
33+
id: serial("id").primaryKey(),
34+
name: text("name").notNull(),
35+
description: text("description"),
36+
app_read: boolean("app_read").notNull().default(false),
37+
app_write: boolean("app_write").notNull().default(false),
38+
creationdate: timestamp("creationdate").defaultNow().notNull(),
39+
isdisable: boolean("isdisable").notNull().default(false),
40+
ishidden: boolean("ishidden").notNull().default(false),
41+
totaltopics: integer("totaltopics").notNull().default(0),
42+
createby: integer("createby").notNull(),
43+
}, (table) => ({
44+
nameIndex: uniqueIndex("name_idx").on(table.name),
45+
}));
46+
47+
// --- Post ---
48+
export const posts = pgTable("Post", {
49+
id: serial("id").primaryKey(),
50+
name: text("name").notNull(),
51+
description: text("description"),
52+
createby: integer("createby").notNull(),
53+
creation_date: timestamp("creation_date").defaultNow().notNull(),
54+
last_edited: timestamp("last_edited").notNull(),
55+
app_read: boolean("app_read").notNull().default(false),
56+
app_write: boolean("app_write").notNull().default(false),
57+
isdisable: boolean("isdisable").notNull().default(false),
58+
ishidden: boolean("ishidden").notNull().default(false),
59+
maplocation: text("maplocation"),
60+
categoryId: integer("categoryId").notNull(),
61+
});
62+
63+
// --- Review ---
64+
export const reviews = pgTable("Review", {
65+
id: serial("id").primaryKey(),
66+
userid: integer("userid").notNull(),
67+
topicid: integer("topicid").notNull(),
68+
title: text("title").notNull(),
69+
description: text("description").notNull(),
70+
});
71+
72+
// --- Log ---
73+
export const logs = pgTable("Log", {
74+
id: serial("id").primaryKey(),
75+
action: text("action").notNull(),
76+
who: integer("who").notNull(),
77+
ondate: timestamp("ondate").defaultNow().notNull(),
78+
});
79+
80+
// --- Session ---
81+
export const sessions = pgTable("Session", {
82+
id: varchar("id", { length: 255 }).primaryKey(),
83+
userId: integer("userId").notNull(),
84+
expiresAt: timestamp("expiresAt").notNull(),
85+
});
86+
87+
// --- Key ---
88+
export const keys = pgTable("Key", {
89+
id: varchar("id", { length: 255 }).primaryKey(),
90+
userId: integer("userId").notNull(),
91+
hashedPassword: text("hashedPassword"),
92+
});
93+
94+
// --- Stargazing ---
95+
export const stargazing = pgTable("Stargazing", {
96+
id: serial("id").primaryKey(),
97+
title: text("title").notNull(),
98+
description: text("description"),
99+
lat: real("lat").notNull(),
100+
long: real("long").notNull(),
101+
});

0 commit comments

Comments
 (0)