-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
185 additions
and
71 deletions.
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
...rc/main/java/site/timecapsulearchive/core/domain/group/data/dto/GroupOwnerSummaryDto.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package site.timecapsulearchive.core.domain.group.data.dto; | ||
|
||
public record GroupOwnerSummaryDto( | ||
String nickname, | ||
Boolean isOwner, | ||
String groupProfileUrl | ||
) { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
.../site/timecapsulearchive/core/domain/group/exception/GroupOwnerAuthenticateException.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package site.timecapsulearchive.core.domain.group.exception; | ||
|
||
import site.timecapsulearchive.core.global.error.ErrorCode; | ||
import site.timecapsulearchive.core.global.error.exception.BusinessException; | ||
|
||
public class GroupOwnerAuthenticateException extends BusinessException { | ||
|
||
public GroupOwnerAuthenticateException() { | ||
super(ErrorCode.GROUP_OWNER_AUTHENTICATE_ERROR); | ||
} | ||
} |
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
91 changes: 91 additions & 0 deletions
91
...n/java/site/timecapsulearchive/core/domain/group/repository/GroupQueryRepositoryImpl.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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package site.timecapsulearchive.core.domain.group.repository; | ||
|
||
import static com.querydsl.core.group.GroupBy.groupBy; | ||
import static com.querydsl.core.group.GroupBy.list; | ||
import static site.timecapsulearchive.core.domain.group.entity.QGroup.group; | ||
import static site.timecapsulearchive.core.domain.group.entity.QMemberGroup.memberGroup; | ||
import static site.timecapsulearchive.core.domain.member.entity.QMember.member; | ||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.domain.SliceImpl; | ||
import org.springframework.stereotype.Repository; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberDto; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class GroupQueryRepositoryImpl implements GroupQueryRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public Slice<GroupSummaryDto> findGroupsSlice( | ||
final Long memberId, | ||
final int size, | ||
final ZonedDateTime createdAt | ||
) { | ||
final List<GroupSummaryDto> groups = jpaQueryFactory | ||
.select( | ||
Projections.constructor( | ||
GroupSummaryDto.class, | ||
group.id, | ||
group.groupName, | ||
group.groupDescription, | ||
group.groupProfileUrl, | ||
group.createdAt, | ||
memberGroup.isOwner | ||
) | ||
) | ||
.from(memberGroup) | ||
.join(memberGroup.group, group) | ||
.where(memberGroup.member.id.eq(memberId).and(memberGroup.createdAt.lt(createdAt))) | ||
.limit(size + 1) | ||
.fetch(); | ||
|
||
final boolean hasNext = groups.size() > size; | ||
if (hasNext) { | ||
groups.remove(size); | ||
} | ||
|
||
return new SliceImpl<>(groups, Pageable.ofSize(size), groups.size() > size); | ||
} | ||
|
||
public Optional<GroupDetailDto> findGroupDetailByGroupId(final Long groupId) { | ||
return Optional.ofNullable( | ||
jpaQueryFactory | ||
.selectFrom(group) | ||
.join(memberGroup).on(memberGroup.group.id.eq(group.id)) | ||
.join(member).on(member.id.eq(memberGroup.member.id)) | ||
.where(group.id.eq(groupId)) | ||
.transform( | ||
groupBy(group.id).as( | ||
Projections.constructor( | ||
GroupDetailDto.class, | ||
group.groupName, | ||
group.groupDescription, | ||
group.groupProfileUrl, | ||
group.createdAt, | ||
list( | ||
Projections.constructor( | ||
GroupMemberDto.class, | ||
member.id, | ||
member.profileUrl, | ||
member.nickname, | ||
member.tag, | ||
memberGroup.isOwner | ||
) | ||
) | ||
) | ||
) | ||
) | ||
.get(groupId) | ||
); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...java/site/timecapsulearchive/core/domain/group/repository/MemberGroupQueryRepository.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package site.timecapsulearchive.core.domain.group.repository; | ||
|
||
import java.util.Optional; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupOwnerSummaryDto; | ||
|
||
public interface MemberGroupQueryRepository { | ||
|
||
Optional<GroupOwnerSummaryDto> findOwnerInMemberGroup(Long groupId, Long memberId); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
.../site/timecapsulearchive/core/domain/group/repository/MemberGroupQueryRepositoryImpl.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package site.timecapsulearchive.core.domain.group.repository; | ||
|
||
import static site.timecapsulearchive.core.domain.group.entity.QGroup.group; | ||
import static site.timecapsulearchive.core.domain.group.entity.QMemberGroup.memberGroup; | ||
import static site.timecapsulearchive.core.domain.member.entity.QMember.member; | ||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import site.timecapsulearchive.core.domain.group.data.dto.GroupOwnerSummaryDto; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class MemberGroupQueryRepositoryImpl implements MemberGroupQueryRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Optional<GroupOwnerSummaryDto> findOwnerInMemberGroup(final Long groupId, | ||
final Long memberId) { | ||
return Optional.ofNullable(jpaQueryFactory | ||
.select( | ||
Projections.constructor( | ||
GroupOwnerSummaryDto.class, | ||
member.nickname, | ||
memberGroup.isOwner, | ||
group.groupProfileUrl | ||
) | ||
) | ||
.from(memberGroup) | ||
.join(memberGroup.member, member) | ||
.join(memberGroup.group, group) | ||
.where(memberGroup.group.id.eq(groupId) | ||
.and(memberGroup.member.id.eq(memberId))) | ||
.fetchFirst() | ||
); | ||
} | ||
} |
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
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
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
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
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