Skip to content

Commit 4e23577

Browse files
Fix: [FN-221] 내가 생성한 그룹 전체 조회
Fix: [FN-221] 내가 생성한 그룹 전체 조회
2 parents 3d37120 + c16d5b3 commit 4e23577

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

src/main/java/project/flipnote/group/controller/GroupController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,15 @@ public ResponseEntity<CursorPagingResponse<GroupInfo>> findMyGroup(
106106

107107
return ResponseEntity.ok(res);
108108
}
109+
110+
//내가 생성한 그룹 전체 조회
111+
@GetMapping("/created")
112+
public ResponseEntity<CursorPagingResponse<GroupInfo>> findCreatedGroup(
113+
@AuthenticationPrincipal AuthPrinciple authPrinciple,
114+
@Valid @ModelAttribute GroupListRequest req
115+
) {
116+
CursorPagingResponse<GroupInfo> res = groupService.findCreatedGroup(authPrinciple, req);
117+
118+
return ResponseEntity.ok(res);
119+
}
109120
}

src/main/java/project/flipnote/group/repository/GroupRepositoryCustom.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface GroupRepositoryCustom {
99
List<GroupInfo> findAllByCursor(Long lastId, Category category, int pageSize);
1010

1111
List<GroupInfo> findAllByCursorAndUserId(Long lastId, Category category, int pageSize, Long userId);
12+
13+
List<GroupInfo> findAllByCursorAndCreatedUserId(Long cursorId, Category category, int size, Long id);
1214
}

src/main/java/project/flipnote/group/repository/GroupRepositoryImpl.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import lombok.RequiredArgsConstructor;
1111
import project.flipnote.group.entity.Category;
12+
import project.flipnote.group.entity.GroupMemberRole;
1213
import project.flipnote.group.entity.QGroup;
1314
import project.flipnote.group.entity.QGroupMember;
1415
import project.flipnote.group.model.GroupInfo;
@@ -90,4 +91,41 @@ public List<GroupInfo> findAllByCursorAndUserId(Long lastId, Category category,
9091
.fetch();
9192
}
9293

94+
/**
95+
* 그룹 테이블에 생성한 유저 추가?
96+
* @param lastId
97+
* @param category
98+
* @param pageSize
99+
* @param userId
100+
* @return
101+
*/
102+
@Override
103+
public List<GroupInfo> findAllByCursorAndCreatedUserId(Long lastId, Category category, int pageSize, Long userId) {
104+
return queryFactory
105+
.select(Projections.constructor(
106+
GroupInfo.class,
107+
group.id,
108+
group.name,
109+
group.description,
110+
group.category,
111+
group.imageUrl,
112+
imageRef.id
113+
))
114+
.from(group)
115+
.join(groupMember).on(groupMember.group.eq(group))
116+
.where(
117+
group.deletedAt.isNull(),
118+
groupMember.user.id.eq(userId),
119+
groupMember.role.eq(GroupMemberRole.OWNER),
120+
lastId != null ? group.id.lt(lastId) : null,
121+
category != null ? group.category.eq(category) : null
122+
)
123+
.leftJoin(imageRef)
124+
.on(imageRef.referenceType.eq(ReferenceType.GROUP)
125+
.and(imageRef.referenceId.eq(group.id)))
126+
.orderBy(group.id.desc())
127+
.limit(pageSize + 1)
128+
.fetch();
129+
}
130+
93131
}

src/main/java/project/flipnote/group/service/GroupService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,19 @@ private CursorPagingResponse<GroupInfo> createGroupInfoCursorPagingResponse(Grou
472472

473473
return CursorPagingResponse.of(groups, hasNext, nextCursor);
474474
}
475+
476+
//리팩토링
477+
public CursorPagingResponse<GroupInfo> findCreatedGroup(AuthPrinciple authPrinciple, GroupListRequest req) {
478+
//1. 유저 가져오기
479+
UserProfile user = getUser(authPrinciple);
480+
481+
//2. 카테고리 변환
482+
Category category = convertCategory(req.getCategory());
483+
484+
List<GroupInfo> groups = groupRepository.findAllByCursorAndCreatedUserId(req.getCursorId(), category, req.getSize(),
485+
user.getId());
486+
487+
488+
return createGroupInfoCursorPagingResponse(req, groups);
489+
}
475490
}

0 commit comments

Comments
 (0)