-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/190 pray #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor/190 pray #191
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
300cfe7
refactor: prayController indent 수정 및 pathvariable 누락 해결
soonga00 c8b39f7
refactor: update pray 기능 분리
soonga00 d32061e
refactor: convertPrayToHistory 분리하여 중복 코드 삭제
soonga00 f628526
refactor: prayFacade 복잡도 낮추기
soonga00 fbc78e7
fix: origin pray id가 null일 때 분기처리
200516bb 762d9ed
fix: return 값 수정
200516bb 5249192
fix: @EnabledScheduling 추가
200516bb f9fb295
fix: getCountById 삭제
200516bb 5a82e23
fix: getSharedCountByIdAndOriginPrayId 수정
200516bb 253e4f2
refactor: prayController indent 수정 및 pathvariable 누락 해결
soonga00 9e583dc
refactor: update pray 기능 분리
soonga00 9cd2986
refactor: convertPrayToHistory 분리하여 중복 코드 삭제
soonga00 53e34e0
refactor: prayFacade 복잡도 낮추기
soonga00 38102c3
fix: praytype을 없애고 모두 categorytype으로 통일
soonga00 b3830f3
Merge branch 'refactor/190-pray' into fix/192-pray-to-history
200516bb e9ab752
Fix/192 pray to history (#193)
200516bb e32c3a7
♻️ Refactor: 기능 분리
soonga00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 41 additions & 91 deletions
132
...in/java/com/uspray/uspray/domain/category/repository/querydsl/CategoryRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,111 +1,61 @@ | ||
| package com.uspray.uspray.domain.category.repository.querydsl; | ||
|
|
||
| import static com.uspray.uspray.domain.category.model.QCategory.category; | ||
| import static com.uspray.uspray.domain.member.model.QMember.member; | ||
| import static com.uspray.uspray.domain.pray.model.QPray.pray; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import com.uspray.uspray.domain.category.model.Category; | ||
| import com.uspray.uspray.domain.member.model.Member; | ||
| import com.uspray.uspray.domain.pray.dto.pray.PrayListResponseDto; | ||
| import com.uspray.uspray.domain.pray.dto.pray.response.PrayResponseDto; | ||
| import com.uspray.uspray.domain.pray.dto.pray.response.QPrayResponseDto; | ||
| import com.uspray.uspray.domain.pray.model.Pray; | ||
| import com.uspray.uspray.global.enums.PrayType; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class CategoryRepositoryImpl implements CategoryRepositoryCustom { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| @Override | ||
| public List<PrayListResponseDto> findAllWithOrderAndType(String username, String prayType) { | ||
| // 카테고리 목록 가져오기 | ||
| List<Category> categories = queryFactory | ||
| .selectFrom(category) | ||
| .where(category.member.userId.eq(username)) | ||
| .where(category.categoryType.stringValue().likeIgnoreCase(prayType)) | ||
| .orderBy(category.order.asc()) | ||
| .fetch(); | ||
|
|
||
| if (categories.isEmpty()) { | ||
| return new ArrayList<>(); | ||
| } | ||
|
|
||
| // 각 카테고리 별로 PrayResponseDto 목록 가져오기 | ||
| List<PrayListResponseDto> prayListResponseDtos = new ArrayList<>(); | ||
| for (Category cat : categories) { | ||
| List<Pray> prays = queryFactory | ||
| .selectFrom(pray) | ||
| .where(pray.category.id.eq(cat.getId()) | ||
| .and(pray.member.userId.eq(username)) | ||
| .and(pray.prayType.stringValue().likeIgnoreCase(prayType))) | ||
| .orderBy(pray.createdAt.asc()) | ||
| .fetch(); | ||
|
|
||
| List<PrayResponseDto> prayResponseDtos = prays.stream() | ||
| .map(pray_iter -> { | ||
| if (pray_iter.getPrayType().equals(PrayType.SHARED)) { | ||
| Member originMember = queryFactory | ||
| .selectFrom(member) | ||
| .where(member.id.eq(pray_iter.getOriginMemberId())) | ||
| .fetchOne(); | ||
| return PrayResponseDto.shared(pray_iter, originMember); | ||
| } else { | ||
| return PrayResponseDto.of(pray_iter); | ||
| } | ||
| }) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| prayListResponseDtos.add( | ||
| new PrayListResponseDto(cat.getId(), cat.getName(), cat.getColor(), | ||
| prayResponseDtos)); | ||
| } | ||
| return prayListResponseDtos; | ||
| } | ||
|
|
||
| @Override | ||
| public List<PrayListResponseDto> findAllWithOrderAndType(String username, String prayType, | ||
| List<Long> prayIds) { | ||
| List<Category> categories = queryFactory | ||
| .selectFrom(category) | ||
| .where(category.member.userId.eq(username)) | ||
| .where(category.categoryType.stringValue().likeIgnoreCase(prayType)) | ||
| .orderBy(category.order.asc()) | ||
| .fetch(); | ||
|
|
||
| // 각 카테고리 별로 PrayResponseDto 목록 가져오기 | ||
| List<PrayListResponseDto> prayListResponseDtos = new ArrayList<>(); | ||
| for (Category cat : categories) { | ||
| List<PrayResponseDto> prayResponseDtos = queryFactory | ||
| .select(new QPrayResponseDto( | ||
| pray.id, | ||
| pray.content, | ||
| pray.member.name, | ||
| pray.deadline, | ||
| pray.category.id, | ||
| pray.category.name, | ||
| pray.lastPrayedAt, | ||
| pray.isShared | ||
| )) | ||
| .from(pray) | ||
| .where(pray.category.id.eq(cat.getId()) | ||
| .and(pray.member.userId.eq(username)) | ||
| .and(pray.prayType.stringValue().likeIgnoreCase(prayType))) | ||
| .fetch(); | ||
| prayResponseDtos.removeIf(p -> !prayIds.contains(p.getPrayId())); | ||
| prayResponseDtos.forEach(p -> p.setInGroup(true)); | ||
|
|
||
| prayListResponseDtos.add( | ||
| new PrayListResponseDto(cat.getId(), cat.getName(), cat.getColor(), | ||
| prayResponseDtos)); | ||
| } | ||
| return prayListResponseDtos; | ||
| } | ||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
|
|
||
| @Override | ||
| public List<PrayListResponseDto> findAllWithOrderAndType(String username, String prayType, | ||
| List<Long> prayIds) { | ||
| List<Category> categories = queryFactory | ||
| .selectFrom(category) | ||
| .where(category.member.userId.eq(username)) | ||
| .where(category.categoryType.stringValue().likeIgnoreCase(prayType)) | ||
| .orderBy(category.order.asc()) | ||
| .fetch(); | ||
|
|
||
| // 각 카테고리 별로 PrayResponseDto 목록 가져오기 | ||
| List<PrayListResponseDto> prayListResponseDtos = new ArrayList<>(); | ||
| for (Category cat : categories) { | ||
| List<PrayResponseDto> prayResponseDtos = queryFactory | ||
| .select(new QPrayResponseDto( | ||
| pray.id, | ||
| pray.content, | ||
| pray.member.name, | ||
| pray.deadline, | ||
| pray.category.id, | ||
| pray.category.name, | ||
| pray.lastPrayedAt, | ||
| pray.isShared | ||
| )) | ||
| .from(pray) | ||
| .where(pray.category.id.eq(cat.getId()) | ||
| .and(pray.member.userId.eq(username)) | ||
| .and(pray.categoryType.stringValue().likeIgnoreCase(prayType))) | ||
| .fetch(); | ||
| prayResponseDtos.removeIf(p -> !prayIds.contains(p.getPrayId())); | ||
| prayResponseDtos.forEach(p -> p.setInGroup(true)); | ||
|
|
||
| prayListResponseDtos.add( | ||
| new PrayListResponseDto(cat.getId(), cat.getName(), cat.getColor(), | ||
| prayResponseDtos)); | ||
| } | ||
| return prayListResponseDtos; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.