Skip to content

Commit a1eb14d

Browse files
committed
[#60] 코드 정리
#60
1 parent 3b3b2eb commit a1eb14d

4 files changed

Lines changed: 35 additions & 151 deletions

File tree

Codive/Features/Home/Data/Services/HomeAPIService.swift

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ protocol HomeAPIServiceProtocol {
4242
}
4343

4444
final class HomeAPIService: HomeAPIServiceProtocol {
45-
45+
4646
private let client: Client
4747
private let jsonDecoder: JSONDecoder
48-
48+
4949
init(tokenProvider: TokenProvider = KeychainTokenProvider()) {
5050
self.client = CodiveAPIProvider.createClient(
5151
middlewares: [CodiveAuthMiddleware(provider: tokenProvider)]
@@ -58,8 +58,8 @@ extension HomeAPIService {
5858

5959
func fetchRecommendCategoryCloth(lastClothId: Int64?, size: Int32, categoryId: Int64, season: [Season]) async throws -> HomeCategoryResponseDTO {
6060
guard let firstSeason = season.first else {
61-
throw HomeAPIError.invalidResponse
62-
}
61+
throw HomeAPIError.invalidResponse
62+
}
6363
let seasonPayload = mapSeasonToQueryParam(firstSeason)
6464

6565
let input = Operations.Cloth_recommendCategoryClothes.Input(
@@ -71,7 +71,7 @@ extension HomeAPIService {
7171
switch response {
7272
case .ok(let okResponse):
7373
let data = try await Data(collecting: okResponse.body.any, upTo: .max)
74-
74+
7575
let decoded = try jsonDecoder.decode(Components.Schemas.BaseResponseSliceResponseClothRecommendListResponse.self, from: data)
7676

7777
let content: [HomeCategoryResponseItem] = decoded.result?.content?.map { item -> HomeCategoryResponseItem in
@@ -119,11 +119,11 @@ extension HomeAPIService {
119119
switch response {
120120
case .ok(let okResponse):
121121
let data = try await Data(collecting: okResponse.body.any, upTo: .max)
122-
122+
123123
let decoded = try jsonDecoder.decode(Components.Schemas.BaseResponseListCoordinateDetailsListResponse.self, from: data)
124124

125125
let items = decoded.result ?? []
126-
126+
127127
return items.map { item in
128128
FetchTodayCoordinateDetailsResponseDTO(
129129
coordinateClothId: item.coordinateClothId ?? 0,
@@ -181,10 +181,10 @@ extension HomeAPIService {
181181
let requestBody = Components.Schemas.TemperatureNotificationRequest(
182182
temperature: request.temperature
183183
)
184-
184+
185185
let input = Operations.sendTemperatureNotification.Input(body: .json(requestBody))
186186
let response = try await client.sendTemperatureNotification(input)
187-
187+
188188
switch response {
189189
case .ok:
190190
return
@@ -211,20 +211,20 @@ extension HomeAPIService {
211211
)
212212
let input = Operations.Coordinate_createDailyCoordinate.Input(body: .json(requestBody))
213213
let response = try await client.Coordinate_createDailyCoordinate(input)
214-
214+
215215
switch response {
216216
case .ok(let okResponse):
217217
let data = try await Data(collecting: okResponse.body.any, upTo: .max)
218218
let decoded = try jsonDecoder.decode(
219219
Components.Schemas.BaseResponseCoordinateCreateResponse.self,
220220
from: data
221221
)
222-
222+
223223
guard let coordinateId = decoded.result?.coordinateId else {
224224
throw HomeAPIError.invalidResponse
225225
}
226226
return CreateTodayCoordinateResponseDTO(coordinateId: coordinateId)
227-
227+
228228
case .undocumented(statusCode: let code, _):
229229
throw HomeAPIError.serverError(statusCode: code, message: "오늘의 코디 생성 실패")
230230
}
@@ -261,40 +261,7 @@ extension HomeAPIService {
261261
}
262262
}
263263

264-
// func patchUpdateCoordinates(coordinateId: Int64, request: EditCoordinateRequestDTO) async throws {
265-
// let requestBody = Components.Schemas.CoordinateUpdateRequest(
266-
// coordinateImageUrl: request.coordinateImageUrl,
267-
// name: request.name,
268-
// memo: request.memo,
269-
// payloads: request.payloads?.map {
270-
// Components.Schemas.CoordinateUpdateRequestPayload(
271-
// clothId: $0.clothId,
272-
// locationX: $0.locationX,
273-
// locationY: $0.locationY,
274-
// ratio: $0.ratio,
275-
// degree: $0.degree,
276-
// order: Int32($0.order)
277-
// )
278-
// }
279-
// )
280-
//
281-
// let input = Operations.Coordinate_updateCoordinate.Input(
282-
// path: .init(coordinateId: coordinateId),
283-
// body: .json(requestBody)
284-
// )
285-
// let response = try await client.Coordinate_updateCoordinate(input)
286-
//
287-
// switch response {
288-
// case .ok:
289-
// return
290-
// case .undocumented(statusCode: let code, _):
291-
// throw LookBookAPIError.serverError(statusCode: code, message: "코디 수정 실패")
292-
// }
293-
// }
294264
func patchUpdateCoordinates(coordinateId: Int64, request: EditCoordinateRequestDTO) async throws {
295-
print("--------------------------------------------------")
296-
print("🚀 [API Request] PATCH Coordinate - ID: \(coordinateId)")
297-
298265
let requestBody = Components.Schemas.CoordinateUpdateRequest(
299266
coordinateImageUrl: request.coordinateImageUrl,
300267
name: request.name,
@@ -310,46 +277,24 @@ extension HomeAPIService {
310277
)
311278
}
312279
)
313-
280+
314281
let input = Operations.Coordinate_updateCoordinate.Input(
315282
path: .init(coordinateId: coordinateId),
316283
body: .json(requestBody)
317284
)
318-
319285
let response = try await client.Coordinate_updateCoordinate(input)
320286

321287
switch response {
322288
case .ok:
323-
print("✅ [API Success] 코디 수정 성공")
324289
return
325-
326-
case .undocumented(statusCode: let code, let payload):
327-
print("❌ [API Error] Status Code: \(code)")
328-
329-
// HTTPBody에서 데이터를 추출하여 문자열로 변환하는 로직
330-
var errorBody: String = "No body content"
331-
if let body = payload.body {
332-
do {
333-
// body를 Data로 변환한 뒤 String으로 변환
334-
let data = try await Data(collecting: body, upTo: 1024 * 1024) // 최대 1MB
335-
if let decodedString = String(data: data, encoding: .utf8) {
336-
errorBody = decodedString
337-
}
338-
} catch {
339-
errorBody = "Failed to decode error body: \(error.localizedDescription)"
340-
}
341-
}
342-
343-
print("⚠️ Server Error Message: \(errorBody)")
344-
print("--------------------------------------------------")
345-
346-
throw LookBookAPIError.serverError(statusCode: code, message: "코디 수정 실패: \(errorBody)")
290+
case .undocumented(statusCode: let code, _):
291+
throw LookBookAPIError.serverError(statusCode: code, message: "코디 수정 실패")
347292
}
348293
}
349294
}
350295

351296
private extension HomeAPIService {
352-
297+
353298
func mapSeasonToQueryParam(
354299
_ season: Season
355300
) -> Operations.Cloth_recommendCategoryClothes.Input.Query.seasonPayload {
@@ -385,7 +330,7 @@ enum HomeAPIError: LocalizedError {
385330
case s3UploadFailed(statusCode: Int)
386331
case noClothIdsReturned
387332
case serverError(statusCode: Int, message: String)
388-
333+
389334
var errorDescription: String? {
390335
switch self {
391336
case .presignedUrlMismatch:

Codive/Features/Home/Presentation/View/HomeNoCodiView.swift

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct HomeNoCodiView: View {
1212
// MARK: - Properties
1313
@ObservedObject var viewModel: HomeViewModel
1414
@State private var draggingItem: CategoryEntity?
15-
15+
1616
// MARK: - Body
1717
var body: some View {
1818
VStack(spacing: 0) {
@@ -27,15 +27,11 @@ struct HomeNoCodiView: View {
2727
}
2828
.onAppear {
2929
viewModel.onAppear()
30-
// Task {
31-
// await viewModel.loadRecommendCategoryClothList()
32-
// }
3330
Task {
34-
// 이미 카테고리 아이템이 있다면(수정 모드 진입 등) 새로 로드하지 않음
35-
if viewModel.clothItemsByCategory.isEmpty {
36-
await viewModel.loadRecommendCategoryClothList()
37-
}
38-
}
31+
if viewModel.clothItemsByCategory.isEmpty {
32+
await viewModel.loadRecommendCategoryClothList()
33+
}
34+
}
3935
}
4036
}
4137
}
@@ -68,41 +64,22 @@ private extension HomeNoCodiView {
6864
.padding(.bottom, 16)
6965
}
7066

71-
// var codiClothList: some View {
72-
// ScrollView(.vertical, showsIndicators: false) {
73-
// VStack(spacing: 16) {
74-
// ForEach(viewModel.activeCategories) { category in
75-
// let clothItems = viewModel.clothItemsByCategory[category.id] ?? []
76-
//
77-
// CodiClothView(
78-
// title: category.title,
79-
// items: clothItems,
80-
// isEmptyState: clothItems.isEmpty
81-
// ) { newIndex in
82-
// viewModel.updateSelectedIndex(for: category.id, index: newIndex)
83-
// }
84-
// .id("\(category.id)_\(clothItems.count)")
85-
// .background(Color.white)
86-
// .cornerRadius(15)
8767
var codiClothList: some View {
8868
ScrollView(.vertical, showsIndicators: false) {
8969
VStack(spacing: 16) {
9070
ForEach(viewModel.activeCategories, id: \.id) { category in
91-
// 1. 필요한 데이터를 안전하게 추출 (타입 명시)
9271
let items: [HomeClothEntity] = viewModel.clothItemsByCategory[category.id] ?? []
9372
let selectedIdx: Int = viewModel.selectedIndicesByCategory[category.id] ?? 0
9473

95-
// 2. 뷰를 생성할 때 고유 ID는 category.id만 사용 (스크롤 안정성 핵심)
9674
CodiClothView(
9775
title: category.title,
9876
items: items,
9977
selectedIndex: selectedIdx,
100-
isEmptyState: items.isEmpty,
101-
onIndexChanged: { newIndex in
102-
viewModel.updateSelectedIndex(for: category.id, index: newIndex)
103-
}
104-
)
105-
.id(category.id) // 여기에 selectedIdx를 포함하면 스크롤 시 뷰가 튀게 됩니다.
78+
isEmptyState: items.isEmpty
79+
) { newIndex in
80+
viewModel.updateSelectedIndex(for: category.id, index: newIndex)
81+
}
82+
.id(category.id)
10683
.background(Color.white)
10784
.cornerRadius(15)
10885
.onDrag {
@@ -177,14 +154,14 @@ struct CategoryDropDelegate: DropDelegate {
177154
}
178155
}
179156
}
180-
157+
181158
func performDrop(info: DropInfo) -> Bool {
182159
withAnimation(.easeInOut) {
183160
draggingItem = nil
184161
}
185162
return true
186163
}
187-
164+
188165
func dropUpdated(info: DropInfo) -> DropProposal? {
189166
return DropProposal(operation: .move)
190167
}

Codive/Features/Home/Presentation/ViewModel/CodiBoardViewModel.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,11 @@ final class CodiBoardViewModel: ObservableObject {
5757
}
5858

5959
// MARK: - Navigation
60-
61-
/// 이전 화면으로 이동
62-
// func handleBackTap() {
63-
// if homeViewModel?.todayCodiPreview != nil {
64-
// homeViewModel?.hasCodi = true
65-
// }
66-
// navigationRouter.navigateBack()
67-
// }
6860
func handleBackTap() {
69-
// 수정 중이었거나 기존 데이터가 있다면 화면 상태를 HasCodi로 복구
7061
if let homeVM = homeViewModel {
7162
if homeVM.todayCodiPreview != nil {
7263
homeVM.hasCodi = true
7364
}
74-
// 수정 모드 플래그 해제 (다음에 새로 들어올 때를 위해)
7565
homeVM.isEditingExistingCodi = false
7666
}
7767
navigationRouter.navigateBack()

0 commit comments

Comments
 (0)