-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: praytype을 없애고 모두 categorytype으로 통일
- Loading branch information
Showing
14 changed files
with
894 additions
and
964 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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.