Skip to content

Commit d4cfc99

Browse files
committed
[#61] 옷 저장 시 카테고리 정보 처리 개선
1 parent 004b9b1 commit d4cfc99

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

Codive/Features/Closet/Data/DTOs/ClothDTO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ClothResponseDTO: Decodable {
4141

4242
enum CodingKeys: String, CodingKey {
4343
case id
44-
case imageUrl = "ImageUrl"
44+
case imageUrl = "imageUrl"
4545
case name
4646
case brand
4747
case purchaseUrl = "purchase_url"

Codive/Features/Closet/Data/DataSources/ClothDataSource.swift

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,43 @@ final class DefaultClothDataSource: ClothDataSource {
116116
}
117117

118118
let clothIds = try await apiService.createClothes(requests: createRequests)
119-
120-
// 결과 변환: clothIds + inputs → Cloth 엔티티
121-
return zip(clothIds, zip(inputs, presignedInfos)).map { clothId, pair in
122-
let (input, presignedInfo) = pair
123-
return Cloth(
124-
id: Int(clothId),
125-
imageUrl: presignedInfo.finalUrl,
126-
name: input.name.isEmpty ? nil : input.name,
127-
brand: input.brand.isEmpty ? nil : input.brand,
128-
purchaseUrl: input.purchaseUrl.isEmpty ? nil : input.purchaseUrl,
129-
mainCategory: nil,
130-
subCategory: nil,
131-
seasons: input.seasons
132-
)
119+
120+
// Step 4: 생성된 옷의 상세 정보를 조회해서 정확한 카테고리 정보 포함
121+
var clothes: [Cloth] = []
122+
for (index, clothId) in clothIds.enumerated() {
123+
do {
124+
// 상세 정보 조회
125+
let detail = try await apiService.fetchClothDetails(clothId: clothId)
126+
127+
// ClothDetailResult → Cloth 변환
128+
clothes.append(Cloth(
129+
id: Int(clothId),
130+
imageUrl: detail.clothImageUrl,
131+
name: detail.name,
132+
brand: detail.brand,
133+
purchaseUrl: detail.clothUrl,
134+
mainCategory: detail.parentCategory,
135+
subCategory: detail.category,
136+
seasons: Set(detail.seasons)
137+
))
138+
} catch {
139+
// 상세 정보 조회 실패 시, 입력 데이터로 fallback
140+
let input = inputs[index]
141+
let presignedInfo = presignedInfos[index]
142+
clothes.append(Cloth(
143+
id: Int(clothId),
144+
imageUrl: presignedInfo.finalUrl,
145+
name: input.name.isEmpty ? nil : input.name,
146+
brand: input.brand.isEmpty ? nil : input.brand,
147+
purchaseUrl: input.purchaseUrl.isEmpty ? nil : input.purchaseUrl,
148+
mainCategory: nil,
149+
subCategory: nil,
150+
seasons: input.seasons
151+
))
152+
}
133153
}
154+
155+
return clothes
134156
}
135157

136158
func fetchMyClosetClothItems(

0 commit comments

Comments
 (0)