24 lines
839 B
TypeScript
24 lines
839 B
TypeScript
import { IUseCase } from '../../core/application/IUseCase';
|
|
import { Result } from '../../core/domain/Result';
|
|
import { DomainError, ValidationError } from '../../core/domain/DomainError';
|
|
import { IListRepository } from '../domain/IListRepository';
|
|
import { NoteList } from '../domain/NoteList';
|
|
|
|
export interface GetListsRequest {
|
|
ownerId: string;
|
|
category?: string;
|
|
}
|
|
|
|
export class GetListsUseCase implements IUseCase<GetListsRequest, NoteList[]> {
|
|
constructor(private readonly listRepository: IListRepository) {}
|
|
|
|
public async execute(req: GetListsRequest): Promise<Result<NoteList[], DomainError>> {
|
|
if (!req.ownerId) {
|
|
return Result.fail(new ValidationError('Owner ID is required'));
|
|
}
|
|
|
|
const lists = await this.listRepository.findListsByOwner(req.ownerId, req.category);
|
|
return Result.ok(lists);
|
|
}
|
|
}
|