Skip to content

Commit 18c3313

Browse files
authored
Merge pull request #128 from TEAM-Cherrish/feat/#125-flowstate
Feat/#125 Flowstate, 시술 일정 추가 API 연결
2 parents a529710 + d8546f4 commit 18c3313

18 files changed

Lines changed: 357 additions & 47 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// UserProcedureItemRequestDTO.swift
3+
// Cherrish-iOS
4+
//
5+
// Created by 어재선 on 1/21/26.
6+
//
7+
8+
import Foundation
9+
10+
struct UserProcedureItemRequestDTO: Encodable {
11+
let procedureId: Int
12+
let downtimeDays: Int
13+
}
14+
15+
struct CreateUserProcedureRequestDTO: Encodable {
16+
let scheduledAt: String
17+
let recoveryTargetDate: String
18+
let procedures: [UserProcedureItemRequestDTO]
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// CreateUserProcedureResponseDTO.swift
3+
// Cherrish-iOS
4+
//
5+
// Created by 어재선 on 1/21/26.
6+
//
7+
8+
import Foundation
9+
10+
11+
struct CreateUserProcedureResponseDTO: Decodable {
12+
let userProcedureId: Int
13+
let procedureId: Int
14+
let procedureName: String
15+
let scheduledAt: String
16+
let downtimeDays: Int
17+
let recoveryTargetDate: String
18+
}
19+
20+
struct CreateUserProceduresResponseDTO: Decodable {
21+
let procedures: [CreateUserProcedureResponseDTO]
22+
}

Cherrish-iOS/Cherrish-iOS/Data/Network/EndPoint/TreatmentAPI.swift

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import Alamofire
1111
enum TreatmentAPI: EndPoint {
1212
case fetchCategories(userId: Int)
1313
case fetchProcedures(userId: Int, id: Int? = nil, text: String? = nil)
14+
case createUserProcedure(userId: Int, request: CreateUserProcedureRequestDTO)
1415

1516
var basePath: String {
1617
switch self {
1718
case .fetchCategories:
1819
return "/api"
19-
2020
case .fetchProcedures:
2121
return "/api"
22+
case .createUserProcedure:
23+
return "/api"
2224
}
2325
}
2426

@@ -28,6 +30,8 @@ enum TreatmentAPI: EndPoint {
2830
return "/worries"
2931
case .fetchProcedures:
3032
return "/procedures"
33+
case .createUserProcedure:
34+
return "/user-procedures"
3135
}
3236
}
3337

@@ -37,6 +41,8 @@ enum TreatmentAPI: EndPoint {
3741
return .get
3842
case .fetchProcedures:
3943
return .get
44+
case .createUserProcedure:
45+
return .post
4046
}
4147
}
4248

@@ -46,6 +52,9 @@ enum TreatmentAPI: EndPoint {
4652
return .withAuth(userID: userId)
4753
case .fetchProcedures(let userId, _, _):
4854
return .withAuth(userID: userId)
55+
case .createUserProcedure(let userId, _):
56+
return .withAuth(userID: userId)
57+
4958
}
5059
}
5160

@@ -56,6 +65,8 @@ enum TreatmentAPI: EndPoint {
5665
return URLEncoding.default
5766
case .fetchProcedures:
5867
return URLEncoding.default
68+
case .createUserProcedure:
69+
return JSONEncoding.default
5970
}
6071
}
6172

@@ -65,22 +76,36 @@ enum TreatmentAPI: EndPoint {
6576
return nil
6677
case .fetchProcedures(_, let id, let text):
6778
var params: [String: Any] = [:]
68-
if let id = id {
69-
params["worryId"] = id
70-
}
71-
if let text = text {
72-
params["keyword"] = "\(text)"
73-
}
74-
return params
79+
if let id = id {
80+
params["worryId"] = id
81+
}
82+
if let text = text {
83+
params["keyword"] = "\(text)"
84+
}
85+
return params
86+
case .createUserProcedure:
87+
return nil
7588
}
7689
}
7790

91+
7892
var bodyParameters: Alamofire.Parameters? {
7993
switch self {
8094
case .fetchCategories:
8195
return .none
8296
case .fetchProcedures:
8397
return .none
98+
case .createUserProcedure(_, let request):
99+
return [
100+
"scheduledAt": request.scheduledAt,
101+
"recoveryTargetDate": request.recoveryTargetDate,
102+
"procedures": request.procedures.map {
103+
[
104+
"procedureId": $0.procedureId,
105+
"downtimeDays": $0.downtimeDays
106+
]
107+
}
108+
]
84109
}
85-
}
110+
}
86111
}

Cherrish-iOS/Cherrish-iOS/Data/Repository/TreatmentRepository.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import Foundation
99

1010
struct DefaultTreatmentRepository: TreatmentInterface {
11+
12+
1113
private let networkService: NetworkService
1214
private let userDefaultService: UserDefaultService
1315

@@ -29,12 +31,40 @@ struct DefaultTreatmentRepository: TreatmentInterface {
2931

3032
func fetchTreatment(id: Int?, keyword: String?) async throws -> [TreatmentEntity] {
3133
let userId: Int = userDefaultService.load(key: .userID) ?? 1
32-
let response = try await networkService.request(TreatmentAPI.fetchProcedures(userId: userId,id: id, text: keyword), decodingType: ProceduresResponseDTO.self)
34+
let response = try await networkService.request(
35+
TreatmentAPI.fetchProcedures(
36+
userId: userId,
37+
id: id,
38+
text: keyword
39+
),
40+
decodingType: ProceduresResponseDTO.self
41+
)
3342
return response.procedures.map { $0.toEntity() }
3443
}
44+
45+
func createUserProcedure(scheduledDate: String, recoveryDate: String, treatments: [TreatmentEntity]) async throws {
46+
let userId: Int = userDefaultService.load(key: .userID) ?? 1
47+
let request = CreateUserProcedureRequestDTO(
48+
scheduledAt: scheduledDate,
49+
recoveryTargetDate: recoveryDate,
50+
procedures: treatments.compactMap { $0.toRequestDTO() }
51+
)
52+
let _ = try await networkService.request(
53+
TreatmentAPI.createUserProcedure(
54+
userId: userId,
55+
request: request
56+
),
57+
decodingType: CreateProfileResponseDTO.self
58+
)
59+
}
3560
}
3661

3762
struct MockTreatmentRepository: TreatmentInterface {
63+
64+
func createUserProcedure(scheduledDate: String, recoveryDate: String, treatments: [TreatmentEntity]) {
65+
66+
}
67+
3868
func fetchTreatment(id: Int?, keyword: String?) async throws -> [TreatmentEntity] {
3969
return []
4070
}

Cherrish-iOS/Cherrish-iOS/Domain/DomainDependencyAssembler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ final class DomainDependencyAssembler: DependencyAssembler {
2525
return
2626
}
2727

28-
guard let treatmentCategoryRepository = DIContainer.shared.resolve(type: TreatmentInterface.self) else {
29-
return
30-
}
31-
3228
DIContainer.shared.register(type: FetchProcedureCountOfMonth.self) {
3329
return DefaultFetchProcedureCountOfMonth(repository: calendarRepository)
3430
}
@@ -76,5 +72,9 @@ final class DomainDependencyAssembler: DependencyAssembler {
7672
DIContainer.shared.register(type: FetchUserInfoUseCase.self) {
7773
return DefaultFetchUserInfoUserCase(repository: myPageRepository)
7874
}
75+
76+
DIContainer.shared .register(type: CreateUserProcedureUseCase.self) {
77+
return DefaultCreateUserProcedureUseCase(repository: treatmentRepository)
78+
}
7979
}
8080
}

Cherrish-iOS/Cherrish-iOS/Domain/Interface/TreatmentInterface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ import Foundation
1010
protocol TreatmentInterface {
1111
func fetchCategories() async throws -> [TreatmentCategoryEntity]
1212
func fetchTreatment(id: Int?, keyword: String?) async throws -> [TreatmentEntity]
13+
func createUserProcedure(scheduledDate: String, recoveryDate: String, treatments: [TreatmentEntity]) async throws
1314
}

Cherrish-iOS/Cherrish-iOS/Domain/Model/TreatmentEntity.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,13 @@ struct TreatmentEntity: Identifiable, Equatable, Hashable {
2020
}
2121
}
2222

23-
23+
extension TreatmentEntity {
24+
func toRequestDTO() -> UserProcedureItemRequestDTO? {
25+
guard let downtime = setDowntime else { return nil }
26+
return UserProcedureItemRequestDTO(
27+
procedureId: id,
28+
downtimeDays: downtime
29+
)
30+
}
31+
}
2432

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// CreateUserProcedureUseCase.swift
3+
// Cherrish-iOS
4+
//
5+
// Created by 어재선 on 1/21/26.
6+
//
7+
8+
import Foundation
9+
10+
protocol CreateUserProcedureUseCase {
11+
func execute(scheduledDate: String, recoveryDate: String, treatments: [TreatmentEntity]) async throws
12+
}
13+
14+
struct DefaultCreateUserProcedureUseCase: CreateUserProcedureUseCase {
15+
16+
private let repository: TreatmentInterface
17+
18+
init(repository: TreatmentInterface) {
19+
self.repository = repository
20+
}
21+
22+
func execute(
23+
scheduledDate: String,
24+
recoveryDate: String,
25+
treatments: [TreatmentEntity]
26+
) async throws {
27+
return try await repository
28+
.createUserProcedure(
29+
scheduledDate: scheduledDate,
30+
recoveryDate: recoveryDate,
31+
treatments: treatments
32+
)
33+
}
34+
}

Cherrish-iOS/Cherrish-iOS/Presentation/Feature/Calendar/CalendarMain/CalendarView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ extension CalendarView {
167167
.foregroundStyle(.gray600)
168168
.frame(width: 24.adjustedW, height: 24.adjustedH)
169169
.onTapGesture {
170+
viewModel.sendDateToTreatmentView()
170171
calendarCoordinator.push(.selectTreatment)
171172
}
172173
case .selectedProcedure:
@@ -269,9 +270,11 @@ extension CalendarView {
269270
leadingIcon: Image(.plus),
270271
trailingIcon: nil,
271272
action: {
273+
viewModel.sendDateToTreatmentView()
272274
calendarCoordinator.push(
273275
.selectTreatment
274276
)
277+
275278
}
276279
)
277280
.padding(.horizontal, 24.adjustedW)

Cherrish-iOS/Cherrish-iOS/Presentation/Feature/Calendar/CalendarMain/CalendarViewModel.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ final class CalendarViewModel: ObservableObject {
2626
private let fetchProcedureCountOfMonthUseCase: FetchProcedureCountOfMonth
2727
private let fetchTodayProcedureListUseCase: FetchTodayProcedureListUseCase
2828
private let fetchProcedureDowntimeUseCase: FetchProcedureDowntimeUseCase
29+
private let calendarTreatmentFlowState: CalendarTreatmentFlowState
2930

3031
init(
3132
fetchProcedureCountOfMonthUseCase: FetchProcedureCountOfMonth,
3233
fetchTodayProcedureListUseCase: FetchTodayProcedureListUseCase,
33-
fetchProcedureDowntimeUseCase: FetchProcedureDowntimeUseCase
34+
fetchProcedureDowntimeUseCase: FetchProcedureDowntimeUseCase,
35+
calendarTreatmentFlowState: CalendarTreatmentFlowState
3436
) {
3537
self.fetchProcedureCountOfMonthUseCase = fetchProcedureCountOfMonthUseCase
3638
self.fetchTodayProcedureListUseCase = fetchTodayProcedureListUseCase
39+
self.calendarTreatmentFlowState = calendarTreatmentFlowState
3740
self.fetchProcedureDowntimeUseCase = fetchProcedureDowntimeUseCase
3841
}
3942

@@ -94,6 +97,10 @@ final class CalendarViewModel: ObservableObject {
9497
return procedureList.isEmpty
9598
}
9699

100+
func sendDateToTreatmentView() {
101+
calendarTreatmentFlowState.selectedDate = selectedDate
102+
}
103+
97104
@MainActor
98105
func fetchProcedureCountsOfMonth() async throws {
99106
let calendar = Calendar.current

0 commit comments

Comments
 (0)