rename to core
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Application Use Case: SubmitProtestDefenseUseCase
|
||||
*
|
||||
* Allows the accused driver to submit their defense statement for a protest.
|
||||
*/
|
||||
|
||||
import type { IProtestRepository } from '../../domain/repositories/IProtestRepository';
|
||||
|
||||
export interface SubmitProtestDefenseCommand {
|
||||
protestId: string;
|
||||
driverId: string;
|
||||
statement: string;
|
||||
videoUrl?: string;
|
||||
}
|
||||
|
||||
export interface SubmitProtestDefenseResult {
|
||||
success: boolean;
|
||||
protestId: string;
|
||||
}
|
||||
|
||||
export class SubmitProtestDefenseUseCase {
|
||||
constructor(
|
||||
private readonly protestRepository: IProtestRepository,
|
||||
) {}
|
||||
|
||||
async execute(command: SubmitProtestDefenseCommand): Promise<SubmitProtestDefenseResult> {
|
||||
// Get the protest
|
||||
const protest = await this.protestRepository.findById(command.protestId);
|
||||
if (!protest) {
|
||||
throw new Error('Protest not found');
|
||||
}
|
||||
|
||||
// Verify the submitter is the accused driver
|
||||
if (protest.accusedDriverId !== command.driverId) {
|
||||
throw new Error('Only the accused driver can submit a defense');
|
||||
}
|
||||
|
||||
// Check if defense can be submitted
|
||||
if (!protest.canSubmitDefense()) {
|
||||
throw new Error('Defense cannot be submitted for this protest');
|
||||
}
|
||||
|
||||
// Submit defense
|
||||
const updatedProtest = protest.submitDefense(command.statement, command.videoUrl);
|
||||
await this.protestRepository.update(updatedProtest);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
protestId: protest.id,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user