@@ -42,10 +42,10 @@ protocol HomeAPIServiceProtocol {
4242}
4343
4444final 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
351296private 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:
0 commit comments