-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoutineUseCase.swift
More file actions
69 lines (56 loc) · 2.48 KB
/
Copy pathRoutineUseCase.swift
File metadata and controls
69 lines (56 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// RoutineUseCase.swift
// Domain
//
// Created by 최정인 on 7/30/25.
//
import Foundation
import Shared
public final class RoutineUseCase: RoutineUseCaseProtocol {
private let routineRepository: RoutineRepositoryProtocol
public init(routineRepository: RoutineRepositoryProtocol) {
self.routineRepository = routineRepository
}
public func fetchRoutine(routineId: String) async throws -> RoutineEntity? {
let routineEnity = try await routineRepository.fetchRoutine(routineId: routineId)
return routineEnity
}
public func fetchRoutines(startDate: Date, endDate: Date) async throws -> [String: (routines: [RoutineEntity], allCompleted: Bool)] {
let start = startDate.convertToString(dateType: .yearMonthDate)
let end = endDate.convertToString(dateType: .yearMonthDate)
let routineEntities = try await routineRepository.fetchRoutines(from: start, to: end)
return routineEntities
}
public func saveRoutine(routine: RoutineCreationEntity) async throws {
let routine = RoutineCreationEntity(
id: routine.id,
name: routine.name,
repeatDay: routine.repeatDay,
startDate: routine.startDate,
endDate: routine.endDate,
executionTime: routine.executionTime,
subroutines: routine.subroutines.filter { !$0.isEmpty },
recommendedRoutineType: routine.recommendedRoutineType,
applyDateType: routine.applyDateType)
if routine.id == nil { // 루틴 아이디가 있으면 수정, 없으면 생성
try await createRoutine(routine: routine)
} else {
try await updateRoutine(routine: routine)
}
}
private func createRoutine(routine: RoutineCreationEntity) async throws {
try await routineRepository.createRoutine(routine: routine)
}
private func updateRoutine(routine: RoutineCreationEntity) async throws {
try await routineRepository.updateRoutine(routine: routine)
}
public func deleteAllRoutine(routineId: String) async throws {
try await routineRepository.deleteAllRoutine(routineId: routineId)
}
public func deleteDailyRoutine(routineId: String) async throws {
try await routineRepository.deleteDailyRoutine(routineId: routineId)
}
public func updateRoutineCompletions(routines: [RoutineCompletionEntity]) async throws {
try await routineRepository.updateRoutineCompletions(routines: routines)
}
}