feat: initial commit with Nuxt 3 student management system
- Add Nuxt 3 + Prisma + SQLite full-stack setup - Add student CRUD API with batch import/export - Add stats dashboard with gender/class distribution - Add target community settings feature - Add Docker deployment support (Dockerfile + docker-compose) - Add README with development and deployment instructions
This commit is contained in:
11
server/api/students/[id].delete.ts
Normal file
11
server/api/students/[id].delete.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = Number(event.context.params?.id)
|
||||
|
||||
await prisma.student.delete({
|
||||
where: { id }
|
||||
})
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
23
server/api/students/[id].put.ts
Normal file
23
server/api/students/[id].put.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = Number(event.context.params?.id)
|
||||
const body = await readBody(event)
|
||||
|
||||
const student = await prisma.student.update({
|
||||
where: { id },
|
||||
data: {
|
||||
className: body.className,
|
||||
name: body.name,
|
||||
gender: body.gender,
|
||||
birthday: body.birthday || null,
|
||||
address: body.address || null,
|
||||
fatherName: body.fatherName || null,
|
||||
fatherPhone: body.fatherPhone || null,
|
||||
motherName: body.motherName || null,
|
||||
motherPhone: body.motherPhone || null
|
||||
}
|
||||
})
|
||||
|
||||
return student
|
||||
})
|
||||
6
server/api/students/clear.post.ts
Normal file
6
server/api/students/clear.post.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await prisma.student.deleteMany()
|
||||
return { success: true }
|
||||
})
|
||||
28
server/api/students/import.post.ts
Normal file
28
server/api/students/import.post.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
|
||||
if (!Array.isArray(body.students)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: 'Invalid data format'
|
||||
})
|
||||
}
|
||||
|
||||
const result = await prisma.student.createMany({
|
||||
data: body.students.map((s: any) => ({
|
||||
className: s.className,
|
||||
name: s.name,
|
||||
gender: s.gender || '',
|
||||
birthday: s.birthday || null,
|
||||
address: s.address || null,
|
||||
fatherName: s.fatherName || null,
|
||||
fatherPhone: s.fatherPhone || null,
|
||||
motherName: s.motherName || null,
|
||||
motherPhone: s.motherPhone || null
|
||||
}))
|
||||
})
|
||||
|
||||
return { count: result.count }
|
||||
})
|
||||
8
server/api/students/index.get.ts
Normal file
8
server/api/students/index.get.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const students = await prisma.student.findMany({
|
||||
orderBy: { id: 'desc' }
|
||||
})
|
||||
return students
|
||||
})
|
||||
21
server/api/students/index.post.ts
Normal file
21
server/api/students/index.post.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
|
||||
const student = await prisma.student.create({
|
||||
data: {
|
||||
className: body.className,
|
||||
name: body.name,
|
||||
gender: body.gender,
|
||||
birthday: body.birthday || null,
|
||||
address: body.address || null,
|
||||
fatherName: body.fatherName || null,
|
||||
fatherPhone: body.fatherPhone || null,
|
||||
motherName: body.motherName || null,
|
||||
motherPhone: body.motherPhone || null
|
||||
}
|
||||
})
|
||||
|
||||
return student
|
||||
})
|
||||
Reference in New Issue
Block a user