@@ -141,8 +141,8 @@ public CollectionResponseDTO.CollectionLearningInfo getLearningInfo(
141141 .learningStatus ("BEFORE" )
142142 .progressRate (null )
143143 .resourceDTOList (isDetailView ?
144- getAllResources (collection , null ) : // 상세 조회면 전체 리소스
145- getFilteredResources (collection , null , 0 )) // 아니면 필터링된 리소스
144+ getAllResourcesWithProgress (collection , null , 0 ) :
145+ getFilteredResources (collection , null , 0 ))
146146 .build ();
147147 }
148148
@@ -153,8 +153,8 @@ public CollectionResponseDTO.CollectionLearningInfo getLearningInfo(
153153 .learningStatus ("BEFORE" )
154154 .progressRate (null )
155155 .resourceDTOList (isDetailView ?
156- getAllResources (collection , user ) : // 상세 조회면 전체 리소스
157- getFilteredResources (collection , null , 0 )) // 아니면 필터링된 리소스
156+ getAllResourcesWithProgress (collection , null , 0 ) :
157+ getFilteredResources (collection , null , 0 ))
158158 .build ();
159159 }
160160
@@ -166,8 +166,8 @@ public CollectionResponseDTO.CollectionLearningInfo getLearningInfo(
166166 .startDate (realUserCollection .getCreatedAt ().toLocalDate ())
167167 .completedDate (realUserCollection .getCompletedTime ())
168168 .resourceDTOList (isDetailView ?
169- getAllResources (collection ) : // 상세 조회면 전체 리소스
170- new ArrayList <>()) // 아니면 빈 리스트
169+ getAllResourcesWithProgress (collection , user , realUserCollection . getUserCollectionStatus ()) :
170+ new ArrayList <>())
171171 .build ();
172172 }
173173
@@ -178,11 +178,34 @@ public CollectionResponseDTO.CollectionLearningInfo getLearningInfo(
178178 .startDate (realUserCollection .getCreatedAt ().toLocalDate ())
179179 .currentEpisode (realUserCollection .getUserCollectionStatus ())
180180 .resourceDTOList (isDetailView ?
181- getAllResources (collection , user ) :
181+ getAllResourcesWithProgress (collection , user , realUserCollection . getUserCollectionStatus () ) :
182182 getFilteredResources (collection , user , realUserCollection .getUserCollectionStatus ()))
183183 .build ();
184184 }
185185
186+ private List <ResourceResponseDTO .SearchResultResourceDTO > getAllResourcesWithProgress (
187+ Collection collection ,
188+ User user ,
189+ int currentEpisodeNumber
190+ ) {
191+ return collection .getEpisodes ().stream ()
192+ .sorted (Comparator .comparing (CollectionEpisode ::getEpisodeNumber ))
193+ .map (episode -> {
194+ UserEpisodeProgress progress = null ;
195+ if (user != null ) {
196+ progress = userEpisodeProgressRepository .findById (
197+ new UserEpisodeProgressId (episode .getId (), user .getLoginId ())
198+ ).orElse (null );
199+ }
200+ return ResourceConverter .convertToResourceDTO (
201+ episode ,
202+ progress ,
203+ currentEpisodeNumber
204+ );
205+ })
206+ .toList ();
207+ }
208+
186209 private int calculateProgressRate (UserCollection userCollection ) {
187210 return (int ) Math .round ((double ) userCollection .getUserCollectionStatus () /
188211 userCollection .getCollection ().getEpisodes ().size () * 100 );
@@ -216,9 +239,23 @@ private List<ResourceResponseDTO.SearchResultResourceDTO> getFilteredResources(
216239 .limit (4 )
217240 .toList ();
218241 }
219-
220- return filteredEpisodes .stream ()
242+ /* return filteredEpisodes.stream()
221243 .map(ResourceConverter::convertToResourceDTO)
244+ .toList();*/
245+ return filteredEpisodes .stream ()
246+ .map (episode -> {
247+ UserEpisodeProgress progress = null ;
248+ if (user != null ) {
249+ progress = userEpisodeProgressRepository .findById (
250+ new UserEpisodeProgressId (episode .getId (), user .getLoginId ())
251+ ).orElse (null );
252+ }
253+ return ResourceConverter .convertToResourceDTO (
254+ episode ,
255+ progress ,
256+ currentEpisode
257+ );
258+ })
222259 .toList ();
223260 }
224261
0 commit comments