-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRecommendedRoutineDTO.swift
More file actions
57 lines (49 loc) · 1.61 KB
/
RecommendedRoutineDTO.swift
File metadata and controls
57 lines (49 loc) · 1.61 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
//
// RecommendedRoutineDTO.swift
// DataSource
//
// Created by 최정인 on 7/27/25.
//
import Domain
struct RecommendedRoutineDTO: Decodable {
let id: Int
let routineName: String
let routineDescription: String
let routineLevel: String?
let subRoutines: [SubRoutineDTO]
enum CodingKeys: String, CodingKey {
case id = "recommendedRoutineId"
case routineName = "recommendedRoutineName"
case routineDescription = "recommendedRoutineDescription"
case routineLevel = "recommendedRoutineLevel"
case subRoutines = "recommendedSubRoutineSearchResult"
}
func toRecommendedRoutineEntity(category: String? = nil) -> RecommendedRoutineEntity {
var routineCategory: RoutineCategoryType?
if let category {
routineCategory = RoutineCategoryType(rawValue: category)
}
var level: RoutineLevelType?
if let routineLevel {
level = RoutineLevelType(rawValue: routineLevel)
}
return RecommendedRoutineEntity(
id: id,
title: routineName,
description: routineDescription,
category: routineCategory,
level: level,
subRoutines: subRoutines.compactMap({ $0.toSubRoutineEntity() }))
}
}
struct SubRoutineDTO: Decodable {
let id: Int
let routineName: String
enum CodingKeys: String, CodingKey {
case id = "recommendedSubRoutineId"
case routineName = "recommendedSubRoutineName"
}
func toSubRoutineEntity() -> SubRoutineEntity {
return SubRoutineEntity(id: id, title: routineName)
}
}