Skip to content

Commit c9210ae

Browse files
Merge pull request #36 from TeamLearningFlow/develop
Develop을 deploy로 merge 재시도
2 parents 510e6a8 + 89f8aa4 commit c9210ae

15 files changed

Lines changed: 285 additions & 184 deletions

File tree

build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ dependencies {
7070

7171

7272
//QueryDsl
73-
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
74-
implementation 'com.querydsl:querydsl-core'
73+
implementation 'com.querydsl:querydsl-jpa:5.1.0:jakarta'
7574
annotationProcessor "com.querydsl:querydsl-apt:5.1.0:jakarta"
7675
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
7776
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
@@ -97,11 +96,6 @@ tasks.withType(JavaCompile).configureEach {
9796
options.generatedSourceOutputDirectory = file(generated)
9897
}
9998

100-
// gradle clean 시에 QClass 디렉토리 삭제
101-
clean {
102-
delete file(generated)
103-
}
104-
10599
configurations {
106100
compileOnly {
107101
extendsFrom annotationProcessor

src/main/java/learningFlow/learningFlow_BE/config/security/SecurityConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public SecurityFilterChain filterChain(HttpSecurity http, JwtAuthenticationFilte
4545
"/find/**",
4646
"/reset-password",
4747
"/search/**",
48+
"/home/**",
4849
"/collections/{collectionId:[\\d]+}"
4950
).permitAll()
5051
.requestMatchers(
51-
"/register", "/register/complete", "/login", "/login/google", "/oauth2/**", "/logout/**",
52-
"/home/**").permitAll()
52+
"/register", "/register/complete", "/login", "/login/google", "/oauth2/**", "/logout/**").permitAll()
5353
.requestMatchers("/admin/**").hasRole("ADMIN")
5454
.requestMatchers("/user/**", "/resources/**", "/collections/{collectionId}/bookmark").authenticated()
5555
.anyRequest().permitAll()

src/main/java/learningFlow/learningFlow_BE/converter/CollectionConverter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
public class CollectionConverter {
1313

14+
public static List<CollectionResponseDTO.CollectionPreviewDTO> convertToHomeCollection(List<Collection> collections) {
15+
return collections.stream()
16+
.map(collection -> CollectionConverter.toCollectionPreviewDTO(collection, null))
17+
.toList();
18+
}
19+
1420
public static SearchRequestDTO.SearchConditionDTO toSearchConditionDTO(
1521
String keyword,
1622
InterestField interestFields,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package learningFlow.learningFlow_BE.converter;
2+
3+
import learningFlow.learningFlow_BE.domain.Collection;
4+
import learningFlow.learningFlow_BE.domain.User;
5+
import learningFlow.learningFlow_BE.web.dto.collection.CollectionResponseDTO;
6+
import learningFlow.learningFlow_BE.web.dto.home.HomeResponseDTO;
7+
8+
import java.util.List;
9+
10+
public class HomeConverter {
11+
12+
public static HomeResponseDTO.GuestHomeInfoDTO convertToGuestHomeInfoDTO(
13+
List<CollectionResponseDTO.CollectionPreviewDTO> collectionPreviewList
14+
) {
15+
return HomeResponseDTO.GuestHomeInfoDTO.builder()
16+
.recommendedCollections(collectionPreviewList)
17+
.build();
18+
}
19+
20+
public static HomeResponseDTO.UserHomeInfoDTO convertToUserHomeInfoDTO(
21+
HomeResponseDTO.RecentLearningDTO recentLearning,
22+
List<Collection> recommendedCollections,
23+
User user,
24+
int size
25+
) {
26+
List<CollectionResponseDTO.CollectionPreviewDTO> recommendedPreviewDTOs = recommendedCollections.stream()
27+
.distinct()
28+
.map(collection -> CollectionConverter.toCollectionPreviewDTO(collection, user))
29+
.limit(size)
30+
.toList();
31+
32+
return HomeResponseDTO.UserHomeInfoDTO.builder()
33+
.recentLearning(recentLearning)
34+
.recommendedCollections(recommendedPreviewDTOs)
35+
.build();
36+
}
37+
}

src/main/java/learningFlow/learningFlow_BE/converter/ResourceConverter.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,39 @@
33
import learningFlow.learningFlow_BE.domain.Collection;
44
import learningFlow.learningFlow_BE.domain.CollectionEpisode;
55
import learningFlow.learningFlow_BE.domain.UserCollection;
6+
import learningFlow.learningFlow_BE.web.dto.collection.CollectionResponseDTO;
7+
import learningFlow.learningFlow_BE.web.dto.home.HomeResponseDTO;
68
import learningFlow.learningFlow_BE.web.dto.resource.ResourceResponseDTO;
79

810
import java.util.List;
911

1012
public class ResourceConverter {
1113

14+
public static HomeResponseDTO.RecentLearningDTO toRecentLearningDTO(UserCollection userCollection) {
15+
Collection collection = userCollection.getCollection();
16+
int currentEpisode = userCollection.getUserCollectionStatus();
17+
18+
List<ResourceResponseDTO.SearchResultResourceDTO> resources = collection.getEpisodes().stream()
19+
.filter(episode -> episode.getEpisodeNumber() <= currentEpisode)
20+
.map(episode -> ResourceResponseDTO.SearchResultResourceDTO.builder()
21+
.resourceId(episode.getResource().getId())
22+
.episodeName(episode.getEpisodeName())
23+
.url(episode.getResource().getUrl())
24+
.resourceSource(extractResourceSource(episode.getResource().getUrl()))
25+
.episodeNumber(episode.getEpisodeNumber())
26+
.build())
27+
.toList();
28+
29+
CollectionResponseDTO.CompletedCollectionDTO completedCollectionDTO
30+
= CollectionConverter.convertToCompletedCollectionDTO(userCollection);
31+
32+
return HomeResponseDTO.RecentLearningDTO.builder()
33+
.collection(completedCollectionDTO)
34+
.resources(resources)
35+
.progressRatio(calculateProgressRatio(userCollection))
36+
.build();
37+
}
38+
1239
public static List<ResourceResponseDTO.SearchResultResourceDTO> getResourceDTOList(Collection collection) {
1340

1441
return collection.getEpisodes().stream()
@@ -22,6 +49,19 @@ public static List<ResourceResponseDTO.SearchResultResourceDTO> getResourceDTOLi
2249
.toList();
2350
}
2451

52+
public static ResourceResponseDTO.RecentlyWatchedEpisodeDTO convertToRecentlyWatchedEpisodeDTO(
53+
UserCollection userCollection
54+
) {
55+
return ResourceResponseDTO.RecentlyWatchedEpisodeDTO.builder()
56+
.resourceId(getResourceId(userCollection))
57+
.CollectionTitle(userCollection.getCollection().getTitle())
58+
.resourceSource(extractResourceSource(getResourceUrl(userCollection)))
59+
.episodeNumber(userCollection.getUserCollectionStatus())
60+
.episodeName(getEpisodeName(userCollection))
61+
.progressRatio(calculateProgressRatio(userCollection))
62+
.build();
63+
}
64+
2565
private static String extractResourceSource(String url) {
2666

2767
String lowerCaseUrl = url.toLowerCase();
@@ -39,19 +79,6 @@ private static String extractResourceSource(String url) {
3979
}
4080
}
4181

42-
public static ResourceResponseDTO.RecentlyWatchedEpisodeDTO convertToRecentlyWatchedEpisodeDTO(
43-
UserCollection userCollection
44-
) {
45-
return ResourceResponseDTO.RecentlyWatchedEpisodeDTO.builder()
46-
.resourceId(getResourceId(userCollection))
47-
.CollectionTitle(userCollection.getCollection().getTitle())
48-
.resourceSource(extractResourceSource(getResourceUrl(userCollection)))
49-
.episodeNumber(userCollection.getUserCollectionStatus())
50-
.episodeName(getEpisodeName(userCollection))
51-
.progressRatio(calculateProgressRatio(userCollection))
52-
.build();
53-
}
54-
5582
private static String getResourceUrl(UserCollection userCollection) {
5683
return userCollection.getCollection().getEpisodes().stream()
5784
.filter(episode -> episode.getEpisodeNumber().equals(userCollection.getUserCollectionStatus()))

src/main/java/learningFlow/learningFlow_BE/converter/UserConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import learningFlow.learningFlow_BE.web.dto.resource.ResourceResponseDTO;
77
import learningFlow.learningFlow_BE.web.dto.user.UserResponseDTO;
88
import learningFlow.learningFlow_BE.web.dto.user.UserResponseDTO.UserInfoDTO;
9-
import org.springframework.stereotype.Component;
109

1110
import java.util.List;
1211

13-
@Component
1412
public class UserConverter {
1513

1614
public static UserResponseDTO.UserLoginResponseDTO toUserLoginResponseDTO(User user) {

src/main/java/learningFlow/learningFlow_BE/domain/User.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class User extends BaseEntity {
4343
@Column(nullable = false)
4444
private Job job;
4545

46-
@ElementCollection(fetch = FetchType.LAZY)
46+
@ElementCollection(fetch = FetchType.EAGER)
4747
@CollectionTable(name = "user_interests")
4848
@Enumerated(EnumType.STRING)
4949
@Column(name = "interest_field", nullable = false)
@@ -68,7 +68,7 @@ public class User extends BaseEntity {
6868
@JoinColumn(name = "image_id")
6969
private Image image;
7070

71-
@ElementCollection(fetch = FetchType.LAZY)
71+
@ElementCollection(fetch = FetchType.EAGER)
7272
@CollectionTable(name = "user_bookmarks", joinColumns = @JoinColumn(name = "user_id"))
7373
@Column(name = "collection_id")
7474
private List<Long> bookmarkedCollectionIds = new ArrayList<>();

src/main/java/learningFlow/learningFlow_BE/repository/UserCollectionRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import org.springframework.data.jpa.repository.JpaRepository;
77

88
import java.util.List;
9+
import java.util.Optional;
910

1011
public interface UserCollectionRepository extends JpaRepository<UserCollection, Long> {
1112
List<UserCollection> findByUserAndStatusOrderByLastAccessedAtDesc(User user, UserCollectionStatus status);
12-
}
13+
14+
Optional<UserCollection> findFirstByUserAndStatusOrderByLastAccessedAtDesc(User user, UserCollectionStatus status);
15+
}

src/main/java/learningFlow/learningFlow_BE/repository/collection/CollectionRepositoryCustom.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package learningFlow.learningFlow_BE.repository.collection;
22

33
import learningFlow.learningFlow_BE.domain.Collection;
4+
import learningFlow.learningFlow_BE.domain.enums.MediaType;
5+
import learningFlow.learningFlow_BE.domain.enums.InterestField;
46
import learningFlow.learningFlow_BE.web.dto.search.SearchRequestDTO;
57
import org.springframework.data.domain.Pageable;
68

@@ -11,4 +13,10 @@ public interface CollectionRepositoryCustom {
1113
Integer getTotalCount(SearchRequestDTO.SearchConditionDTO condition);
1214
List<Collection> searchNextPage(SearchRequestDTO.SearchConditionDTO condition, Collection lastCollection, Pageable pageable);
1315
Integer getCountGreaterThanBookmark(Integer bookmarkCount, Long lastId, SearchRequestDTO.SearchConditionDTO condition);
16+
List<Collection> findTopBookmarkedCollections(int limit);
17+
List<Collection> findByInterestFieldAndPreferType(List<InterestField> interestFields,
18+
MediaType preferType,
19+
boolean matchInterest,
20+
boolean matchPreferType,
21+
int limit);
1422
}

src/main/java/learningFlow/learningFlow_BE/repository/collection/CollectionRepositoryImpl.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import learningFlow.learningFlow_BE.domain.QCollection;
1010
import learningFlow.learningFlow_BE.domain.QCollectionEpisode;
1111
import learningFlow.learningFlow_BE.domain.enums.InterestField;
12+
import learningFlow.learningFlow_BE.domain.enums.MediaType;
1213
import learningFlow.learningFlow_BE.web.dto.search.SearchRequestDTO;
1314
import lombok.RequiredArgsConstructor;
1415
import org.springframework.data.domain.Pageable;
@@ -112,6 +113,42 @@ public Integer getCountGreaterThanBookmark(Integer bookmarkCount, Long lastId, S
112113
return count != null ? count.intValue() : 0;
113114
}
114115

116+
@Override
117+
public List<Collection> findTopBookmarkedCollections(int limit) {
118+
return jpaQueryFactory
119+
.selectFrom(collection)
120+
.orderBy(collection.bookmarkCount.desc())
121+
.limit(limit)
122+
.fetch();
123+
}
124+
125+
@Override
126+
public List<Collection> findByInterestFieldAndPreferType(
127+
List<InterestField> interestFields,
128+
MediaType preferType,
129+
boolean matchInterest,
130+
boolean matchPreferType,
131+
int limit
132+
) {
133+
134+
BooleanExpression interestCondition = matchInterest ?
135+
collection.interestField.in(interestFields) : collection.interestField.notIn(interestFields);
136+
137+
BooleanExpression preferTypeCondition = null;
138+
if (preferType != MediaType.NO_PREFERENCE) {
139+
preferTypeCondition = preferType == MediaType.VIDEO ?
140+
(matchPreferType ? collection.resourceTypeRatio.goe(50) : collection.resourceTypeRatio.lt(50)) :
141+
(matchPreferType ? collection.resourceTypeRatio.lt(50) : collection.resourceTypeRatio.goe(50));
142+
}
143+
144+
return jpaQueryFactory
145+
.selectFrom(collection)
146+
.where(interestCondition, preferTypeCondition)
147+
.orderBy(collection.bookmarkCount.desc())
148+
.limit(limit)
149+
.fetch();
150+
}
151+
115152
private BooleanExpression createDynamicInterestFields(InterestField interestFields) {
116153
if (interestFields == null) {
117154
return null;

0 commit comments

Comments
 (0)