Initial commit of Dance School App

This commit is contained in:
kertenkerem
2026-01-08 00:51:13 +03:00
parent 902fb6e9bb
commit 260dea0713
48 changed files with 7923 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
.layout {
display: flex;
min-height: 100vh;
}
.sidebar {
width: 250px;
background-color: #1a1a1a;
color: white;
padding: 2rem;
display: flex;
flex-direction: column;
}
.brand {
font-size: 1.5rem;
font-weight: bold;
margin-bottom: 2rem;
color: #fff;
text-decoration: none;
}
.nav {
display: flex;
flex-direction: column;
gap: 1rem;
flex: 1;
}
.navLink {
color: #aaa;
text-decoration: none;
font-size: 1.1rem;
padding: 0.5rem 0;
transition: color 0.2s;
}
.navLink:hover {
color: white;
}
.active {
color: white;
font-weight: bold;
}
.main {
flex: 1;
background-color: #f9f9f9;
padding: 2rem;
overflow-y: auto;
}
.logoutBtn {
margin-top: auto;
background: none;
border: 1px solid #333;
color: #999;
padding: 0.5rem;
cursor: pointer;
border-radius: 4px;
}
.logoutBtn:hover {
color: white;
border-color: white;
}

View File

@@ -0,0 +1,35 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import styles from './branches.module.css';
export function AddBranchForm() {
const [name, setName] = useState('');
const [address, setAddress] = useState('');
const router = useRouter();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
await fetch('/api/branches', {
method: 'POST',
body: JSON.stringify({ name, address }),
});
setName('');
setAddress('');
router.refresh();
};
return (
<form onSubmit={handleSubmit} className={styles.form}>
<div className={styles.inputGroup}>
<label>Şube Adı</label>
<input value={name} onChange={e => setName(e.target.value)} className={styles.input} required />
</div>
<div className={styles.inputGroup}>
<label>Adres</label>
<input value={address} onChange={e => setAddress(e.target.value)} className={styles.input} />
</div>
<button type="submit" className={styles.btn}>Ekle</button>
</form>
);
}

View File

@@ -0,0 +1,27 @@
'use client';
import { useRouter } from 'next/navigation';
import styles from './branches.module.css';
export function BranchList({ branches }: { branches: any[] }) {
const router = useRouter();
const handleDelete = async (id: string) => {
if (!confirm('Silmek istediğinize emin misiniz?')) return;
await fetch(`/api/branches/${id}`, { method: 'DELETE' });
router.refresh();
};
return (
<div className={styles.list}>
{branches.map(b => (
<div key={b.id} className={styles.card}>
<div>
<h3>{b.name}</h3>
<p>{b.address}</p>
</div>
<button onClick={() => handleDelete(b.id)} className={`${styles.btn} ${styles.btnDelete}`}>Sil</button>
</div>
))}
</div>
);
}

View File

@@ -0,0 +1,62 @@
.container {
padding: 1rem;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
}
.form {
background: white;
padding: 1.5rem;
border-radius: 8px;
margin-bottom: 2rem;
display: flex;
gap: 1rem;
align-items: flex-end;
flex-wrap: wrap;
}
.inputGroup {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.input {
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 4px;
min-width: 200px;
}
.btn {
padding: 0.6rem 1.2rem;
background: #333;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btnDelete {
background: #d32f2f;
}
.list {
display: grid;
gap: 1rem;
}
.card {
background: white;
padding: 1.5rem;
border-radius: 8px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

View File

@@ -0,0 +1,17 @@
import { prisma } from '@/infrastructure/db/prisma';
import { AddBranchForm } from './AddBranchForm';
import { BranchList } from './BranchList';
import styles from './branches.module.css';
export default async function Page() {
const branches = await prisma.branch.findMany({ orderBy: { createdAt: 'desc' } });
return (
<div className={styles.container}>
<div className={styles.header}>
<h1>Şubeler</h1>
</div>
<AddBranchForm />
<BranchList branches={branches} />
</div>
);
}

View File

@@ -0,0 +1,49 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import styles from '../branches/branches.module.css';
export function AddClassForm({ branches, instructors }: { branches: any[], instructors: any[] }) {
const [name, setName] = useState('');
const [branchId, setBranchId] = useState('');
const [instructorId, setInstructorId] = useState(''); // Optional
const router = useRouter();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!branchId) return alert('Şube seçiniz');
await fetch('/api/classes', {
method: 'POST',
body: JSON.stringify({ name, branchId, instructorId: instructorId || null }),
});
setName('');
setBranchId('');
setInstructorId('');
router.refresh();
};
return (
<form onSubmit={handleSubmit} className={styles.form}>
<div className={styles.inputGroup}>
<label>Sınıf Adı</label>
<input value={name} onChange={e => setName(e.target.value)} className={styles.input} required />
</div>
<div className={styles.inputGroup}>
<label>Şube</label>
<select value={branchId} onChange={e => setBranchId(e.target.value)} className={styles.input} required>
<option value="">Seçiniz</option>
{branches.map(b => <option key={b.id} value={b.id}>{b.name}</option>)}
</select>
</div>
<div className={styles.inputGroup}>
<label>Varsayılan Hoca (Opsiyonel)</label>
<select value={instructorId} onChange={e => setInstructorId(e.target.value)} className={styles.input}>
<option value="">Seçiniz</option>
{instructors.map(i => <option key={i.id} value={i.id}>{i.name}</option>)}
</select>
</div>
<button type="submit" className={styles.btn}>Ekle</button>
</form>
);
}

View File

@@ -0,0 +1,28 @@
'use client';
import { useRouter } from 'next/navigation';
import styles from '../branches/branches.module.css';
export function ClassList({ classes }: { classes: any[] }) {
const router = useRouter();
const handleDelete = async (id: string) => {
if (!confirm('Silmek istediğinize emin misiniz?')) return;
await fetch(`/api/classes/${id}`, { method: 'DELETE' });
router.refresh();
};
return (
<div className={styles.list}>
{classes.map(c => (
<div key={c.id} className={styles.card}>
<div>
<h3>{c.name}</h3>
<p>Şube: {c.branch?.name}</p>
{c.instructor && <p>Hoca: {c.instructor.name}</p>}
</div>
<button onClick={() => handleDelete(c.id)} className={`${styles.btn} ${styles.btnDelete}`}>Sil</button>
</div>
))}
</div>
);
}

View File

@@ -0,0 +1,20 @@
import { prisma } from '@/infrastructure/db/prisma';
import { AddClassForm } from './AddClassForm';
import { ClassList } from './ClassList';
import styles from '../branches/branches.module.css';
export default async function Page() {
const classes = await prisma.danceClass.findMany({ include: { branch: true, instructor: true }, orderBy: { createdAt: 'desc' } });
const branches = await prisma.branch.findMany();
const instructors = await prisma.instructor.findMany();
return (
<div className={styles.container}>
<div className={styles.header}>
<h1>Sınıflar</h1>
</div>
<AddClassForm branches={branches} instructors={instructors} />
<ClassList classes={classes} />
</div>
);
}

View File

@@ -0,0 +1,3 @@
.container {
padding: 2rem;
}

View File

@@ -0,0 +1,10 @@
import styles from './dashboard.module.css';
export default function Dashboard() {
return (
<div className={styles.container}>
<h1>Dashboard</h1>
<p>Welcome to the Admin Panel</p>
</div>
);
}

View File

@@ -0,0 +1,35 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import styles from '../branches/branches.module.css'; // Reuse styles
export function AddInstructorForm() {
const [name, setName] = useState('');
const [bio, setBio] = useState('');
const router = useRouter();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
await fetch('/api/instructors', {
method: 'POST',
body: JSON.stringify({ name, bio }),
});
setName('');
setBio('');
router.refresh();
};
return (
<form onSubmit={handleSubmit} className={styles.form}>
<div className={styles.inputGroup}>
<label>Hoca Adı</label>
<input value={name} onChange={e => setName(e.target.value)} className={styles.input} required />
</div>
<div className={styles.inputGroup}>
<label>Biyografi / Uzmanlık</label>
<input value={bio} onChange={e => setBio(e.target.value)} className={styles.input} />
</div>
<button type="submit" className={styles.btn}>Ekle</button>
</form>
);
}

View File

@@ -0,0 +1,27 @@
'use client';
import { useRouter } from 'next/navigation';
import styles from '../branches/branches.module.css';
export function InstructorList({ instructors }: { instructors: any[] }) {
const router = useRouter();
const handleDelete = async (id: string) => {
if (!confirm('Silmek istediğinize emin misiniz?')) return;
await fetch(`/api/instructors/${id}`, { method: 'DELETE' });
router.refresh();
};
return (
<div className={styles.list}>
{instructors.map(i => (
<div key={i.id} className={styles.card}>
<div>
<h3>{i.name}</h3>
<p>{i.bio}</p>
</div>
<button onClick={() => handleDelete(i.id)} className={`${styles.btn} ${styles.btnDelete}`}>Sil</button>
</div>
))}
</div>
);
}

View File

@@ -0,0 +1,17 @@
import { prisma } from '@/infrastructure/db/prisma';
import { AddInstructorForm } from './AddInstructorForm';
import { InstructorList } from './InstructorList';
import styles from '../branches/branches.module.css';
export default async function Page() {
const instructors = await prisma.instructor.findMany({ orderBy: { createdAt: 'desc' } });
return (
<div className={styles.container}>
<div className={styles.header}>
<h1>Hocalar</h1>
</div>
<AddInstructorForm />
<InstructorList instructors={instructors} />
</div>
);
}

15
src/app/admin/layout.tsx Normal file
View File

@@ -0,0 +1,15 @@
import { Sidebar } from '@/presentation/components/Sidebar';
import styles from './admin.module.css';
export default function AdminLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<div className={styles.layout}>
<Sidebar />
<main className={styles.main}>{children}</main>
</div>
);
}

View File

@@ -0,0 +1,32 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/infrastructure/db/prisma';
export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
try {
await prisma.branch.delete({
where: { id: params.id },
});
return NextResponse.json({ success: true });
} catch (error) {
return NextResponse.json({ error: 'Failed' }, { status: 500 });
}
}
export async function PUT(
request: Request,
{ params }: { params: { id: string } }
) {
try {
const json = await request.json();
const branch = await prisma.branch.update({
where: { id: params.id },
data: json,
});
return NextResponse.json(branch);
} catch (error) {
return NextResponse.json({ error: 'Failed' }, { status: 500 });
}
}

View File

@@ -0,0 +1,26 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/infrastructure/db/prisma';
export async function GET() {
const branches = await prisma.branch.findMany({
orderBy: { createdAt: 'desc' }
});
return NextResponse.json(branches);
}
export async function POST(request: Request) {
try {
const json = await request.json();
// Validate?
const branch = await prisma.branch.create({
data: {
name: json.name,
address: json.address,
phone: json.phone
}
});
return NextResponse.json(branch);
} catch (error) {
return NextResponse.json({ error: 'Failed to create branch' }, { status: 500 });
}
}

View File

@@ -0,0 +1,16 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/infrastructure/db/prisma';
export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
try {
await prisma.danceClass.delete({
where: { id: params.id },
});
return NextResponse.json({ success: true });
} catch (error) {
return NextResponse.json({ error: 'Failed' }, { status: 500 });
}
}

View File

@@ -0,0 +1,27 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/infrastructure/db/prisma';
export async function GET() {
const classes = await prisma.danceClass.findMany({
include: { branch: true, instructor: true },
orderBy: { createdAt: 'desc' }
});
return NextResponse.json(classes);
}
export async function POST(request: Request) {
try {
const json = await request.json();
const cls = await prisma.danceClass.create({
data: {
name: json.name,
branchId: json.branchId, // required
instructorId: json.instructorId || undefined, // optional?
},
});
return NextResponse.json(cls);
} catch (error) {
console.error(error);
return NextResponse.json({ error: 'Failed' }, { status: 500 });
}
}

View File

@@ -0,0 +1,16 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/infrastructure/db/prisma';
export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
try {
await prisma.instructor.delete({
where: { id: params.id },
});
return NextResponse.json({ success: true });
} catch (error) {
return NextResponse.json({ error: 'Failed' }, { status: 500 });
}
}

View File

@@ -0,0 +1,22 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/infrastructure/db/prisma';
export async function GET() {
const instructors = await prisma.instructor.findMany({ orderBy: { createdAt: 'desc' } });
return NextResponse.json(instructors);
}
export async function POST(request: Request) {
try {
const json = await request.json();
const instructor = await prisma.instructor.create({
data: {
name: json.name,
bio: json.bio,
},
});
return NextResponse.json(instructor);
} catch (error) {
return NextResponse.json({ error: 'Failed' }, { status: 500 });
}
}

View File

@@ -0,0 +1,44 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/infrastructure/db/prisma';
import { comparePassword, encrypt } from '@/lib/auth';
import { cookies } from 'next/headers';
export async function POST(request: Request) {
try {
const body = await request.json();
const { username, password } = body;
if (!username || !password) {
return NextResponse.json({ error: 'Missing fields' }, { status: 400 });
}
const user = await prisma.user.findUnique({ where: { username } });
if (!user) {
return NextResponse.json({ error: 'Invalid credentials' }, { status: 401 });
}
const isValid = await comparePassword(password, user.password);
if (!isValid) {
return NextResponse.json({ error: 'Invalid credentials' }, { status: 401 });
}
const expires = new Date(Date.now() + 24 * 60 * 60 * 1000); // 1 day
const token = await encrypt({ userId: user.id, username: user.username, expires });
// Set cookie
const cookieStore = await cookies();
cookieStore.set('admin_session', token, {
expires,
httpOnly: true,
path: '/',
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax'
});
return NextResponse.json({ success: true });
} catch (error) {
console.error('Login error:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
}
}

BIN
src/app/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

16
src/app/globals.css Normal file
View File

@@ -0,0 +1,16 @@
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: #f5f5f5;
color: #333;
}
a {
text-decoration: none;
color: inherit;
}
* {
box-sizing: border-box;
}

32
src/app/layout.tsx Normal file
View File

@@ -0,0 +1,32 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`${geistSans.variable} ${geistMono.variable}`}>
{children}
</body>
</html>
);
}

View File

@@ -0,0 +1,63 @@
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f5f5;
}
.card {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
.title {
text-align: center;
margin-bottom: 2rem;
color: #333;
}
.formGroup {
margin-bottom: 1.5rem;
}
.label {
display: block;
margin-bottom: 0.5rem;
color: #555;
font-weight: 500;
}
.input {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 1rem;
}
.button {
width: 100%;
padding: 0.75rem;
background-color: #0070f3;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
cursor: pointer;
transition: background 0.2s;
}
.button:hover {
background-color: #005bb5;
}
.error {
color: red;
margin-bottom: 1rem;
text-align: center;
}

57
src/app/login/page.tsx Normal file
View File

@@ -0,0 +1,57 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import styles from './login.module.css';
export default function LoginPage() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const router = useRouter();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError('');
const res = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});
if (res.ok) {
router.push('/admin/dashboard');
} else {
const data = await res.json();
setError(data.error || 'Login failed');
}
};
return (
<div className={styles.container}>
<form onSubmit={handleSubmit} className={styles.card}>
<h1 className={styles.title}>Admin Login</h1>
{error && <div className={styles.error}>{error}</div>}
<div className={styles.formGroup}>
<label className={styles.label}>Username</label>
<input
className={styles.input}
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
</div>
<div className={styles.formGroup}>
<label className={styles.label}>Password</label>
<input
className={styles.input}
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
<button type="submit" className={styles.button}>Login</button>
</form>
</div>
);
}

141
src/app/page.module.css Normal file
View File

@@ -0,0 +1,141 @@
.page {
--background: #fafafa;
--foreground: #fff;
--text-primary: #000;
--text-secondary: #666;
--button-primary-hover: #383838;
--button-secondary-hover: #f2f2f2;
--button-secondary-border: #ebebeb;
display: flex;
min-height: 100vh;
align-items: center;
justify-content: center;
font-family: var(--font-geist-sans);
background-color: var(--background);
}
.main {
display: flex;
min-height: 100vh;
width: 100%;
max-width: 800px;
flex-direction: column;
align-items: flex-start;
justify-content: space-between;
background-color: var(--foreground);
padding: 120px 60px;
}
.intro {
display: flex;
flex-direction: column;
align-items: flex-start;
text-align: left;
gap: 24px;
}
.intro h1 {
max-width: 320px;
font-size: 40px;
font-weight: 600;
line-height: 48px;
letter-spacing: -2.4px;
text-wrap: balance;
color: var(--text-primary);
}
.intro p {
max-width: 440px;
font-size: 18px;
line-height: 32px;
text-wrap: balance;
color: var(--text-secondary);
}
.intro a {
font-weight: 500;
color: var(--text-primary);
}
.ctas {
display: flex;
flex-direction: row;
width: 100%;
max-width: 440px;
gap: 16px;
font-size: 14px;
}
.ctas a {
display: flex;
justify-content: center;
align-items: center;
height: 40px;
padding: 0 16px;
border-radius: 128px;
border: 1px solid transparent;
transition: 0.2s;
cursor: pointer;
width: fit-content;
font-weight: 500;
}
a.primary {
background: var(--text-primary);
color: var(--background);
gap: 8px;
}
a.secondary {
border-color: var(--button-secondary-border);
}
/* Enable hover only on non-touch devices */
@media (hover: hover) and (pointer: fine) {
a.primary:hover {
background: var(--button-primary-hover);
border-color: transparent;
}
a.secondary:hover {
background: var(--button-secondary-hover);
border-color: transparent;
}
}
@media (max-width: 600px) {
.main {
padding: 48px 24px;
}
.intro {
gap: 16px;
}
.intro h1 {
font-size: 32px;
line-height: 40px;
letter-spacing: -1.92px;
}
}
@media (prefers-color-scheme: dark) {
.logo {
filter: invert();
}
.page {
--background: #000;
--foreground: #000;
--text-primary: #ededed;
--text-secondary: #999;
--button-primary-hover: #ccc;
--button-secondary-hover: #1a1a1a;
--button-secondary-border: #1a1a1a;
}
}

66
src/app/page.tsx Normal file
View File

@@ -0,0 +1,66 @@
import Image from "next/image";
import styles from "./page.module.css";
export default function Home() {
return (
<div className={styles.page}>
<main className={styles.main}>
<Image
className={styles.logo}
src="/next.svg"
alt="Next.js logo"
width={100}
height={20}
priority
/>
<div className={styles.intro}>
<h1>To get started, edit the page.tsx file.</h1>
<p>
Looking for a starting point or more instructions? Head over to{" "}
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Templates
</a>{" "}
or the{" "}
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Learning
</a>{" "}
center.
</p>
</div>
<div className={styles.ctas}>
<a
className={styles.primary}
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className={styles.logo}
src="/vercel.svg"
alt="Vercel logomark"
width={16}
height={16}
/>
Deploy Now
</a>
<a
className={styles.secondary}
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</main>
</div>
);
}