65 lines
1.7 KiB
Dart
65 lines
1.7 KiB
Dart
import '../models/instruction_log.dart';
|
||
import 'interface/IRepository.dart';
|
||
|
||
class InstructionLogRepository implements Repository<InstructionLog> {
|
||
final List<InstructionLog> _logs = [
|
||
InstructionLog(
|
||
id: '1',
|
||
workerId: '1',
|
||
instructionId: '1',
|
||
status: InstructionStatus.completed,
|
||
notes: 'Работа выполнена качественно'
|
||
),
|
||
InstructionLog(
|
||
id: '2',
|
||
workerId: '2',
|
||
instructionId: '2',
|
||
status: InstructionStatus.assigned,
|
||
notes: 'В процессе выполнения'
|
||
),
|
||
InstructionLog(
|
||
id: '3',
|
||
workerId: '1',
|
||
instructionId: '3',
|
||
status: InstructionStatus.assigned,
|
||
notes: 'Ожидает начала работ'
|
||
)
|
||
];
|
||
|
||
@override
|
||
Future<List<InstructionLog>> load() async {
|
||
return List.of(_logs);
|
||
}
|
||
|
||
@override
|
||
Future<InstructionLog> add(InstructionLog log) async {
|
||
_logs.add(log);
|
||
return log;
|
||
}
|
||
|
||
@override
|
||
Future<void> update(InstructionLog log) async {
|
||
final index = _logs.indexWhere((l) => l.id == log.id);
|
||
if (index == -1) {
|
||
throw Exception('Запись журнала не найдена');
|
||
}
|
||
_logs[index] = log;
|
||
}
|
||
|
||
@override
|
||
Future<void> delete(String? id) async {
|
||
_logs.removeWhere((log) => log.id == id);
|
||
}
|
||
|
||
Future<List<InstructionLog>> getByWorkerId(String workerId) async {
|
||
return _logs.where((log) => log.workerId == workerId).toList();
|
||
}
|
||
|
||
Future<List<InstructionLog>> getByInstructionId(String instructionId) async {
|
||
return _logs.where((log) => log.instructionId == instructionId).toList();
|
||
}
|
||
|
||
Future<List<InstructionLog>> getByStatus(InstructionStatus status) async {
|
||
return _logs.where((log) => log.status == status).toList();
|
||
}
|
||
} |