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

43
.gitignore vendored Normal file
View File

@@ -0,0 +1,43 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
/src/generated/prisma

View File

@@ -1,2 +1,36 @@
# dance_school
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

BIN
dev.db Normal file

Binary file not shown.

18
eslint.config.mjs Normal file
View File

@@ -0,0 +1,18 @@
import { defineConfig, globalIgnores } from "eslint/config";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";
const eslintConfig = defineConfig([
...nextVitals,
...nextTs,
// Override default ignores of eslint-config-next.
globalIgnores([
// Default ignores of eslint-config-next:
".next/**",
"out/**",
"build/**",
"next-env.d.ts",
]),
]);
export default eslintConfig;

7
next.config.ts Normal file
View File

@@ -0,0 +1,7 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
};
export default nextConfig;

6558
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

31
package.json Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "temp_app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint"
},
"dependencies": {
"@prisma/client": "^5.22.0",
"bcryptjs": "^3.0.3",
"jose": "^6.1.3",
"next": "16.1.1",
"prisma": "^5.22.0",
"react": "19.2.3",
"react-dom": "19.2.3"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"dotenv": "^17.2.3",
"eslint": "^9",
"eslint-config-next": "16.1.1",
"tsx": "^4.21.0",
"typescript": "^5"
}
}

BIN
prisma/dev.db Normal file

Binary file not shown.

81
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,81 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
username String @unique
password String
createdAt DateTime @default(now())
}
model Branch {
id String @id @default(uuid())
name String
address String?
phone String?
instructors Instructor[] // Implicit many-to-many
classes DanceClass[]
lessons Lesson[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Instructor {
id String @id @default(uuid())
name String
bio String?
phone String?
branches Branch[] // Implicit many-to-many
classes DanceClass[]
lessons Lesson[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model DanceClass {
id String @id @default(uuid())
name String
description String?
branchId String
branch Branch @relation(fields: [branchId], references: [id])
instructorId String?
instructor Instructor? @relation(fields: [instructorId], references: [id])
lessons Lesson[]
fees Fee[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Lesson {
id String @id @default(uuid())
name String? // Optional name e.g. "Special Workshop"
startTime DateTime
endTime DateTime
type String // GROUP, PRIVATE
branchId String
branch Branch @relation(fields: [branchId], references: [id])
instructorId String
instructor Instructor @relation(fields: [instructorId], references: [id])
classId String?
class DanceClass? @relation(fields: [classId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Fee {
id String @id @default(uuid())
name String
amount Float
currency String @default("TRY")
type String // MONTHLY, PER_LESSON, PACKAGE
classId String?
class DanceClass? @relation(fields: [classId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

1
public/file.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

1
public/globe.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

1
public/next.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

1
public/vercel.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 128 B

1
public/window.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

29
scripts/seed.ts Normal file
View File

@@ -0,0 +1,29 @@
import 'dotenv/config';
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
// Manually read .env if needed, but dotenv/config should handle it
const prisma = new PrismaClient();
async function main() {
const password = await bcrypt.hash('admin123', 10);
const user = await prisma.user.upsert({
where: { username: 'admin' },
update: {},
create: {
username: 'admin',
password,
},
});
console.log('Admin user created:', user);
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});

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>
);
}

View File

@@ -0,0 +1,9 @@
import { PrismaClient } from '@prisma/client';
const globalForPrisma = global as unknown as { prisma: PrismaClient };
export const prisma =
globalForPrisma.prisma ||
new PrismaClient();
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;

32
src/lib/auth.ts Normal file
View File

@@ -0,0 +1,32 @@
import { SignJWT, jwtVerify } from 'jose';
import bcrypt from 'bcryptjs';
const secretKey = process.env.JWT_SECRET || 'super-secret-key-dance-school';
const key = new TextEncoder().encode(secretKey);
export async function encrypt(payload: any) {
return await new SignJWT(payload)
.setProtectedHeader({ alg: 'HS256' })
.setIssuedAt()
.setExpirationTime('24h')
.sign(key);
}
export async function decrypt(input: string): Promise<any> {
try {
const { payload } = await jwtVerify(input, key, {
algorithms: ['HS256'],
});
return payload;
} catch (error) {
return null;
}
}
export async function hashPassword(password: string) {
return await bcrypt.hash(password, 10);
}
export async function comparePassword(plain: string, hashed: string) {
return await bcrypt.compare(plain, hashed);
}

29
src/middleware.ts Normal file
View File

@@ -0,0 +1,29 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { decrypt } from '@/lib/auth';
export async function middleware(request: NextRequest) {
const path = request.nextUrl.pathname;
// Check for session cookie
const cookie = request.cookies.get('admin_session')?.value;
const session = cookie ? await decrypt(cookie) : null;
// Protect /admin routes
if (path.startsWith('/admin')) {
if (!session) {
return NextResponse.redirect(new URL('/login', request.nextUrl));
}
}
// Redirect already logged in users from /login to /admin/dashboard
if (path === '/login' && session) {
return NextResponse.redirect(new URL('/admin/dashboard', request.nextUrl));
}
return NextResponse.next();
}
export const config = {
matcher: ['/admin/:path*', '/login'],
};

View File

@@ -0,0 +1,42 @@
'use client';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import styles from '@/app/admin/admin.module.css';
export function Sidebar() {
const pathname = usePathname();
const router = useRouter();
const navItems = [
{ name: 'Dashboard', href: '/admin/dashboard' },
{ name: 'Şubeler', href: '/admin/branches' },
{ name: 'Hocalar', href: '/admin/instructors' },
{ name: 'Sınıflar', href: '/admin/classes' },
{ name: 'Ders Programı', href: '/admin/lessons' },
{ name: 'Ücretler', href: '/admin/fees' },
];
const handleLogout = () => {
document.cookie = 'admin_session=; Max-Age=0; path=/;';
router.push('/login');
router.refresh();
};
return (
<aside className={styles.sidebar}>
<div className={styles.brand}>Dance School</div>
<nav className={styles.nav}>
{navItems.map((item) => (
<Link
key={item.href}
href={item.href}
className={`${styles.navLink} ${pathname.startsWith(item.href) ? styles.active : ''}`}
>
{item.name}
</Link>
))}
</nav>
<button onClick={handleLogout} className={styles.logoutBtn}>Çıkış Yap</button>
</aside>
);
}

34
tsconfig.json Normal file
View File

@@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts"
],
"exclude": ["node_modules"]
}