feat: restructure into XFlow monorepo with Nuxt 4, Modular Onion Monolith, Android client, and Desktop CLI
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
import { prisma } from '../../../utils/prisma';
|
||||
import { IListRepository } from '../domain/IListRepository';
|
||||
import { NoteList } from '../domain/NoteList';
|
||||
import { ListItem } from '../domain/ListItem';
|
||||
|
||||
export class PrismaListRepository implements IListRepository {
|
||||
public async findListById(id: string): Promise<NoteList | null> {
|
||||
const record = await (prisma as any).noteList.findUnique({
|
||||
where: { id },
|
||||
include: { items: true }
|
||||
});
|
||||
|
||||
if (!record) return null;
|
||||
return this.mapToDomain(record);
|
||||
}
|
||||
|
||||
public async findListByTitleAndOwner(title: string, ownerId: string): Promise<NoteList | null> {
|
||||
const record = await (prisma as any).noteList.findFirst({
|
||||
where: {
|
||||
title: { equals: title, mode: 'insensitive' },
|
||||
ownerId
|
||||
},
|
||||
include: { items: true }
|
||||
});
|
||||
|
||||
if (!record) return null;
|
||||
return this.mapToDomain(record);
|
||||
}
|
||||
|
||||
public async findListsByOwner(ownerId: string, category?: string): Promise<NoteList[]> {
|
||||
const where: any = { ownerId };
|
||||
if (category) {
|
||||
where.category = category;
|
||||
}
|
||||
|
||||
const records = await (prisma as any).noteList.findMany({
|
||||
where,
|
||||
include: { items: { orderBy: { createdAt: 'desc' } } },
|
||||
orderBy: { updatedAt: 'desc' }
|
||||
});
|
||||
|
||||
return records.map((r: any) => this.mapToDomain(r));
|
||||
}
|
||||
|
||||
public async saveList(list: NoteList): Promise<void> {
|
||||
await (prisma as any).noteList.upsert({
|
||||
where: { id: list.id },
|
||||
create: {
|
||||
id: list.id,
|
||||
title: list.title,
|
||||
category: list.category,
|
||||
description: list.description,
|
||||
color: list.color,
|
||||
icon: list.icon,
|
||||
ownerId: list.ownerId,
|
||||
createdAt: list.createdAt,
|
||||
updatedAt: list.updatedAt
|
||||
},
|
||||
update: {
|
||||
title: list.title,
|
||||
category: list.category,
|
||||
description: list.description,
|
||||
color: list.color,
|
||||
icon: list.icon,
|
||||
updatedAt: new Date()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async deleteList(id: string, ownerId: string): Promise<boolean> {
|
||||
const res = await (prisma as any).noteList.deleteMany({
|
||||
where: { id, ownerId }
|
||||
});
|
||||
return res.count > 0;
|
||||
}
|
||||
|
||||
public async findItemById(id: string): Promise<ListItem | null> {
|
||||
const record = await (prisma as any).listItem.findUnique({
|
||||
where: { id }
|
||||
});
|
||||
|
||||
if (!record) return null;
|
||||
return new ListItem({
|
||||
id: record.id,
|
||||
listId: record.listId,
|
||||
title: record.title,
|
||||
description: record.description,
|
||||
isCompleted: record.isCompleted,
|
||||
status: record.status,
|
||||
priority: record.priority,
|
||||
metadata: record.metadata as any,
|
||||
dueDate: record.dueDate,
|
||||
createdAt: record.createdAt,
|
||||
updatedAt: record.updatedAt
|
||||
});
|
||||
}
|
||||
|
||||
public async saveItem(item: ListItem): Promise<void> {
|
||||
await (prisma as any).listItem.upsert({
|
||||
where: { id: item.id },
|
||||
create: {
|
||||
id: item.id,
|
||||
listId: item.listId,
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
isCompleted: item.isCompleted,
|
||||
status: item.status,
|
||||
priority: item.priority,
|
||||
metadata: item.metadata || {},
|
||||
dueDate: item.dueDate,
|
||||
createdAt: item.createdAt,
|
||||
updatedAt: item.updatedAt
|
||||
},
|
||||
update: {
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
isCompleted: item.isCompleted,
|
||||
status: item.status,
|
||||
priority: item.priority,
|
||||
metadata: item.metadata || {},
|
||||
dueDate: item.dueDate,
|
||||
updatedAt: new Date()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async deleteItem(id: string): Promise<boolean> {
|
||||
const res = await (prisma as any).listItem.delete({
|
||||
where: { id }
|
||||
});
|
||||
return !!res;
|
||||
}
|
||||
|
||||
private mapToDomain(record: any): NoteList {
|
||||
const items = (record.items || []).map((i: any) => new ListItem({
|
||||
id: i.id,
|
||||
listId: i.listId,
|
||||
title: i.title,
|
||||
description: i.description,
|
||||
isCompleted: i.isCompleted,
|
||||
status: i.status,
|
||||
priority: i.priority,
|
||||
metadata: i.metadata,
|
||||
dueDate: i.dueDate,
|
||||
createdAt: i.createdAt,
|
||||
updatedAt: i.updatedAt
|
||||
}));
|
||||
|
||||
return new NoteList({
|
||||
id: record.id,
|
||||
title: record.title,
|
||||
category: record.category,
|
||||
description: record.description,
|
||||
color: record.color,
|
||||
icon: record.icon,
|
||||
ownerId: record.ownerId,
|
||||
createdAt: record.createdAt,
|
||||
updatedAt: record.updatedAt,
|
||||
items
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user