Connect app to MySQL database at 192.168.4.20

This commit is contained in:
2025-12-01 18:45:48 +00:00
commit 0cfcd05921
16 changed files with 6302 additions and 0 deletions

63
lib/actions.ts Normal file
View File

@@ -0,0 +1,63 @@
'use server'
import { prisma } from './db'
import { revalidatePath } from 'next/cache'
export async function getLists() {
return await prisma.list.findMany({
include: {
items: true,
},
orderBy: {
updatedAt: 'desc',
},
})
}
export async function createList(title: string, color: string = '#3B82F6') {
const list = await prisma.list.create({
data: {
title,
color,
},
})
revalidatePath('/')
return list
}
export async function getListWithItems(listId: string) {
return await prisma.list.findUnique({
where: { id: listId },
include: {
items: {
orderBy: {
createdAt: 'desc',
},
},
},
})
}
export async function createItem(listId: string, title: string, description?: string) {
const item = await prisma.item.create({
data: {
title,
description,
listId,
},
})
revalidatePath(`/list/${listId}`)
return item
}
export async function toggleItem(itemId: string) {
const item = await prisma.item.findUnique({ where: { id: itemId } })
if (!item) return null
const updated = await prisma.item.update({
where: { id: itemId },
data: { completed: !item.completed },
})
revalidatePath(`/list/${item.listId}`)
return updated
}