@@ -10,6 +10,26 @@ import Domain
1010final class RoutineRepository : RoutineRepositoryProtocol {
1111 private let networkService = NetworkService . shared
1212
13+ func createRoutine( routineSummary: RoutineSummaryEntity , subRoutineSummaries: [ SubRoutineSummaryEntity ] ) async throws {
14+ let subRoutineNames = subRoutineSummaries. compactMap { $0. subRoutineName }
15+
16+ let routineCreationDTO = RoutineCreationDTO (
17+ routineName: routineSummary. routineName,
18+ repeatDay: routineSummary. repeatDay. map { $0. rawValue } ,
19+ executionTime: routineSummary. executionTime,
20+ subRoutineName: subRoutineNames)
21+ let endpoint = RoutineEndpoint . createRoutine ( routine: routineCreationDTO)
22+
23+ _ = try await networkService. request ( endpoint: endpoint, type: EmptyResponseDTO . self)
24+ }
25+
26+ func fetchRoutine( routineId: String ) async throws -> RoutineEntity ? {
27+ let endpoint = RoutineEndpoint . fetchRoutine ( routineId: routineId)
28+ guard let response = try await networkService. request ( endpoint: endpoint, type: RoutineResponseDTO . self) else { return nil }
29+
30+ return response. toRoutineEntity ( )
31+ }
32+
1333 func fetchRoutines( from startDate: String , to endDate: String ) async throws -> [ String : [ RoutineEntity ] ] {
1434 let endpoint = RoutineEndpoint . fetchRoutines ( startDate: startDate, endDate: endDate)
1535 guard let response = try await networkService. request ( endpoint: endpoint, type: RoutineDictionaryDTO . self)
@@ -21,4 +41,25 @@ final class RoutineRepository: RoutineRepositoryProtocol {
2141 }
2242 return result
2343 }
44+
45+ func updateRoutine( routineSummary: RoutineSummaryEntity , subRoutineSummaries: [ SubRoutineSummaryEntity ] ) async throws {
46+ guard let routineId = routineSummary. routineId else { return }
47+
48+ let subRoutineDTO = subRoutineSummaries. map {
49+ SubRoutineUpdateDTO (
50+ subRoutineId: $0. subRoutineId,
51+ subRoutineName: $0. subRoutineName,
52+ sortOrder: $0. sortOrder)
53+ }
54+
55+ let routineUpdateDTO = RoutineUpdateDTO (
56+ routineId: routineId,
57+ routineName: routineSummary. routineName,
58+ repeatDay: routineSummary. repeatDay. map { $0. rawValue } ,
59+ executionTime: routineSummary. executionTime,
60+ subRoutineInfos: subRoutineDTO)
61+ let endpoint = RoutineEndpoint . updateRoutine ( routine: routineUpdateDTO)
62+
63+ _ = try await networkService. request ( endpoint: endpoint, type: EmptyResponseDTO . self)
64+ }
2465}
0 commit comments