5 changed files with 229 additions and 75 deletions
@ -1,10 +0,0 @@
|
||||
import 'package:problem_check_system/app/features/problem/domain/repositories/problem_repository.dart'; |
||||
|
||||
class DeleteProblem { |
||||
final ProblemRepository problemRepository; |
||||
|
||||
DeleteProblem({required this.problemRepository}); |
||||
Future<void> call(String id) async { |
||||
await problemRepository.deleteProblem(id); |
||||
} |
||||
} |
||||
@ -0,0 +1,29 @@
|
||||
import 'package:problem_check_system/app/core/domain/entities/sync_status.dart'; |
||||
import 'package:problem_check_system/app/core/repositories/auth_repository.dart'; |
||||
import 'package:problem_check_system/app/features/problem/domain/entities/problem_entity.dart'; |
||||
import 'package:problem_check_system/app/features/problem/domain/repositories/problem_repository.dart'; |
||||
|
||||
class DeleteProblemUsecase { |
||||
final ProblemRepository problemRepository; |
||||
final AuthRepository authRepository; |
||||
|
||||
DeleteProblemUsecase({ |
||||
required this.problemRepository, |
||||
required this.authRepository, |
||||
}); |
||||
Future<void> call(ProblemEntity problemEntity) async { |
||||
final nowUtc = DateTime.now().toUtc(); |
||||
final userId = authRepository.getUserId(); |
||||
|
||||
if (problemEntity.syncStatus == SyncStatus.pendingCreate) { |
||||
await problemRepository.deleteProblem(problemEntity.id); |
||||
} else { |
||||
final newProblem = problemEntity.copyWith( |
||||
lastModifiedTime: nowUtc, |
||||
lastModifierId: userId, |
||||
syncStatus: SyncStatus.pendingDelete, |
||||
); |
||||
await problemRepository.updateProblem(newProblem); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue