@@ -61,6 +61,13 @@ final class HomeViewModel: ObservableObject {
6161 return totalItemCount == 0
6262 }
6363
64+ var currentSeasons : Set < Season > {
65+ let temp = Int ( weatherData? . currentTemp ?? 20 )
66+ if temp >= 30 { return [ . summer] }
67+ else if temp >= 10 { return [ . spring, . fall] }
68+ else { return [ . winter] }
69+ }
70+
6471 // MARK: - Initializer
6572
6673 init (
@@ -92,12 +99,12 @@ extension HomeViewModel {
9299 loadToday ( )
93100 loadActiveCategories ( )
94101 }
95-
102+
96103 func loadToday( ) {
97104 let entity = dateUseCase. getToday ( )
98105 self . todayString = entity. formattedDate
99106 }
100-
107+
101108 func loadActiveCategories( ) {
102109 let allCategories = categoryUseCase. loadCategories ( )
103110 self . activeCategories = allCategories. filter { $0. itemCount > 0 }
@@ -109,6 +116,10 @@ extension HomeViewModel {
109116 self . weatherData = weather
110117
111118 let temperature = weather. currentTemp
119+
120+ let targetSeasons = determineSeasons ( from: temperature)
121+ await loadRecommendCategoryClothList ( seasons: targetSeasons)
122+
112123 let request = PostTodayTemperatureAPIRequestDTO (
113124 temperature: Double ( temperature)
114125 )
@@ -118,10 +129,20 @@ extension HomeViewModel {
118129 print ( " Weather load or post failed: " , error)
119130 }
120131 }
132+
133+ internal func determineSeasons( from temperature: Int ) -> Set < Season > {
134+ if temperature >= 30 {
135+ return [ . summer]
136+ } else if temperature >= 10 {
137+ return [ . spring, . fall]
138+ } else {
139+ return [ . winter]
140+ }
141+ }
121142}
122143
123144extension HomeViewModel {
124- func loadRecommendCategoryClothList( ) async {
145+ func loadRecommendCategoryClothList( seasons : Set < Season > ) async {
125146 self . activeCategories = [ ]
126147 self . clothItemsByCategory = [ : ]
127148
@@ -138,7 +159,7 @@ extension HomeViewModel {
138159 lastClothId: nil ,
139160 size: 10 ,
140161 categoryId: Int64 ( category. id) ,
141- season: [ . spring ]
162+ season: seasons // 전달받은 seasons 사용
142163 )
143164 resultMap [ category. id] = result. content
144165 } catch {
@@ -149,14 +170,14 @@ extension HomeViewModel {
149170
150171 self . clothItemsByCategory = resultMap
151172 }
152-
173+
153174 func moveCategory( from source: IndexSet , to destination: Int ) {
154175 activeCategories. move ( fromOffsets: source, toOffset: destination)
155176
156177 // 순서 변경을 로컬에 저장하려면 categoryUseCase를 통해 저장
157178 // categoryUseCase.saveCategoryOrder(activeCategories)
158179 }
159-
180+
160181 func updateSelectedIndex( for categoryId: Int , index: Int ) {
161182 selectedIndicesByCategory [ categoryId] = index
162183 }
@@ -353,12 +374,12 @@ extension HomeViewModel {
353374 )
354375 }
355376 }
356-
377+
357378 func handlePopupClose( ) {
358379 showCompletePopUp = false
359380 completedCodiImageURL = nil
360381 }
361-
382+
362383 private func captureCompletedCodiImage( ) -> UIImage {
363384 let view = CodiCompositeView ( clothes: selectedCodiClothes)
364385 . frame ( width: 260 , height: 260 )
0 commit comments