Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public SearchedNovelsResponse searchNovels(User user, String query, int page, in

//TODO: 추후 novelRating 제거
@Transactional(readOnly = true)
public FilteredNovelsResponse getFilteredNovels(List<String> genreNames, List<Integer> keywordIds, Boolean isCompleted, Float novelRating, Float novelRatingStart, Float novelRatingEnd, int page, int size) {
public FilteredNovelsResponse getFilteredNovels(List<String> genreNames, List<Integer> keywordIds, Boolean isCompleted, Float novelRating, Float novelRatingStart, Float novelRatingEnd, List<String> platformNames, int page, int size) {
PageRequest pageRequest = PageRequest.of(page, size);

List<Genre> genres = genreService.getGenresOrException(genreNames);
Expand All @@ -110,9 +110,9 @@ public FilteredNovelsResponse getFilteredNovels(List<String> genreNames, List<In
Page<Novel> novels;

if (novelRating == null) {
novels = novelService.findFilteredNovels(pageRequest, genres, keywords, isCompleted, novelRatingStart, novelRatingEnd);
novels = novelService.findFilteredNovels(pageRequest, genres, keywords, isCompleted, novelRatingStart, novelRatingEnd, platformNames);
} else {
novels = novelService.findFilteredNovels(pageRequest, genres, keywords, isCompleted, novelRating, novelRatingEnd);
novels = novelService.findFilteredNovels(pageRequest, genres, keywords, isCompleted, novelRating, novelRatingEnd, platformNames);
}

List<NovelSummaryResponse> novelGetResponsePreviews = novels.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public ResponseEntity<FilteredNovelsResponse> getFilteredNovels(
@RequestParam(required = false, defaultValue = "0.0") Float novelRatingStart,
@RequestParam(required = false, defaultValue = "5.0") Float novelRatingEnd,
@RequestParam(required = false) List<Integer> keywordIds,
@RequestParam(required = false) List<String> platformNames,
@RequestParam int page,
@RequestParam int size) {
return ResponseEntity
.status(OK)
.body(searchNovelApplication.getFilteredNovels(genres, keywordIds, isCompleted, novelRating,
novelRatingStart, novelRatingEnd, page, size));
novelRatingStart, novelRatingEnd, platformNames, page, size));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass platformNames through the application layer

This added argument does not match SearchNovelApplication#getFilteredNovels, which still accepts only the previous eight parameters, so the project no longer compiles. The same application method also still calls NovelServiceImpl#findFilteredNovels without the newly required platformNames argument, so the filtered novels endpoint cannot be built until the application-layer signature and calls are updated together.

Useful? React with 👍 / 👎.

}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/websoso/WSSServer/novel/domain/Novel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class Novel {
@OneToMany(mappedBy = "novel", fetch = FetchType.LAZY)
private List<NovelGenre> novelGenres = new ArrayList<>();

@OneToMany(mappedBy = "novel", fetch = FetchType.LAZY)
private List<NovelPlatform> novelPlatforms = new ArrayList<>();

public String getFirstGenreName(){
return novelGenres.stream()
.findFirst()
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/websoso/WSSServer/novel/domain/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import static jakarta.persistence.GenerationType.IDENTITY;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -25,4 +25,7 @@ public class Platform {
@Column(columnDefinition = "text", nullable = false)
private String platformImage;

@OneToMany(mappedBy = "platform", fetch = FetchType.LAZY)
private List<NovelPlatform> novelPlatforms = new ArrayList<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface NovelCustomRepository {

Page<Novel> findSearchedNovels(Pageable pageable, String query);

Page<Novel> findFilteredNovels(Pageable pageable, List<Genre> genres, Boolean isCompleted, Float novelRatingStart, Float novelRatingEnd, List<Keyword> keywords);
Page<Novel> findFilteredNovels(Pageable pageable, List<Genre> genres, Boolean isCompleted, Float novelRatingStart, Float novelRatingEnd, List<Keyword> keywords, List<String> platformNames);

List<Novel> findAutocompleteNovels(String searchQuery, int limitSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static org.websoso.WSSServer.library.domain.QUserNovel.userNovel;
import static org.websoso.WSSServer.novel.domain.QNovel.novel;
import static org.websoso.WSSServer.novel.domain.QNovelGenre.novelGenre;
import static org.websoso.WSSServer.novel.domain.QNovelPlatform.novelPlatform;
import static org.websoso.WSSServer.novel.domain.QPlatform.platform;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
Expand Down Expand Up @@ -75,7 +77,7 @@ private StringTemplate getCleanedString(StringPath stringPath) {

@Override
public Page<Novel> findFilteredNovels(Pageable pageable, List<Genre> genres, Boolean isCompleted, Float novelRatingStart,
Float novelRatingEnd, List<Keyword> keywords) {
Float novelRatingEnd, List<Keyword> keywords, List<String> platformNames) {

NumberTemplate<Long> popularity = Expressions.numberTemplate(Long.class,
"(SELECT COUNT(un) FROM UserNovel un WHERE un.novel = {0} AND (un.isInterest = true OR un.status <> 'QUIT'))",
Expand All @@ -85,6 +87,8 @@ public Page<Novel> findFilteredNovels(Pageable pageable, List<Genre> genres, Boo
.selectFrom(novel)
.distinct()
.join(novel.novelGenres, novelGenre)
.leftJoin(novel.novelPlatforms, novelPlatform)
.leftJoin(novelPlatform.platform, platform)
.where(
genres.isEmpty()
? null
Expand All @@ -95,7 +99,11 @@ public Page<Novel> findFilteredNovels(Pageable pageable, List<Genre> genres, Boo
getAverageRatingCondition(novel, novelRatingStart, novelRatingEnd),
keywords.isEmpty()
? null
: getKeywordCount(novel, keywords).eq(keywords.size())
: getKeywordCount(novel, keywords).eq(keywords.size()),
platformNames == null || platformNames.isEmpty()
? null
: platform.platformName.in(platformNames)

)
.orderBy(popularity.desc());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public List<Novel> getAutocompleteNovels(String searchQuery, int getSize) {
}

public Page<Novel> findFilteredNovels(PageRequest pageRequest, List<Genre> genres, List<Keyword> keywords,
Boolean isCompleted, Float novelRatingStart, Float novelRatingEnd) {
return novelRepository.findFilteredNovels(pageRequest, genres, isCompleted, novelRatingStart, novelRatingEnd, keywords);
Boolean isCompleted, Float novelRatingStart, Float novelRatingEnd, List<String> platformNames) {
return novelRepository.findFilteredNovels(pageRequest, genres, isCompleted, novelRatingStart, novelRatingEnd, keywords, platformNames);
}

public List<NovelGenre> getGenresByNovel(Novel novel) {
Expand Down
Loading