Skip to content

Commit

Permalink
refactor : 그룹 조회 시 isOwner -> role 수정 (#232)
Browse files Browse the repository at this point in the history
* feat : 그룹 조회 DTO isOwner -> role 수정

* test : 그룹 조회 DTO isOwner -> role 테스트 수정
  • Loading branch information
rladmstn authored Dec 8, 2024
1 parent fde5e36 commit 7367c85
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.LocalDate;

import com.gamzabat.algohub.feature.group.studygroup.etc.RoleOfGroupMember;

import lombok.Getter;

@Getter
Expand All @@ -12,18 +14,18 @@ public class GetGroupResponse {
private final LocalDate endDate;
private final String introduction;
private final String groupImage;
private final Boolean isOwner;
private final RoleOfGroupMember role;
private final String ownerNickname;

public GetGroupResponse(Long id, String name, LocalDate startDate, LocalDate endDate, String introduction,
String groupImage, Boolean isOwner, String ownerNickname) {
String groupImage, RoleOfGroupMember role, String ownerNickname) {
this.id = id;
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.introduction = introduction;
this.groupImage = groupImage;
this.isOwner = isOwner;
this.role = role;
this.ownerNickname = ownerNickname;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gamzabat.algohub.feature.group.studygroup.dto;

import com.gamzabat.algohub.common.DateFormatUtil;
import com.gamzabat.algohub.feature.group.studygroup.domain.GroupMember;
import com.gamzabat.algohub.feature.group.studygroup.domain.StudyGroup;
import com.gamzabat.algohub.feature.group.studygroup.etc.RoleOfGroupMember;
import com.gamzabat.algohub.feature.user.domain.User;

public record GetStudyGroupResponse(Long id,
Expand All @@ -11,10 +13,10 @@ public record GetStudyGroupResponse(Long id,
String endDate,
String introduction,
String ownerNickname,
boolean isOwner,
RoleOfGroupMember role,
boolean isBookmarked,
boolean isVisible) {
public static GetStudyGroupResponse toDTO(StudyGroup group, User user, boolean isBookmarked, User owner,
public static GetStudyGroupResponse toDTO(StudyGroup group, GroupMember member, boolean isBookmarked, User owner,
boolean isVisible) {
return new GetStudyGroupResponse(
group.getId(),
Expand All @@ -24,7 +26,7 @@ public static GetStudyGroupResponse toDTO(StudyGroup group, User user, boolean i
DateFormatUtil.formatDate(group.getEndDate()),
group.getIntroduction(),
owner.getNickname(),
owner.getId().equals(user.getId()),
member.getRole(),
isBookmarked,
isVisible
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public GetStudyGroupListsResponse getStudyGroupList(User user) {
private GetStudyGroupResponse getStudyGroupResponseDTO(User user, StudyGroup group) {
GroupMember member = groupMemberRepository.findByUserAndStudyGroup(user, group)
.orElseThrow(() -> new GroupMemberValidationException(HttpStatus.FORBIDDEN.value(), "참여하지 않은 스터디 그룹입니다."));
return GetStudyGroupResponse.toDTO(group, user, isBookmarked(user, group), getStudyGroupOwner(group),
return GetStudyGroupResponse.toDTO(group, member, isBookmarked(user, group), getStudyGroupOwner(group),
member.getIsVisible());
}

Expand Down Expand Up @@ -447,8 +447,9 @@ public GetGroupResponse getGroup(User user, Long groupId) {
() -> new GroupMemberValidationException(HttpStatus.BAD_REQUEST.value(), "참여하지 않은 그룹 입니다."));

GetGroupResponse response = new GetGroupResponse(group.getId(), group.getName(), group.getStartDate(),
group.getEndDate(), group.getIntroduction(), group.getGroupImage(), RoleOfGroupMember.isOwner(member),
group.getEndDate(), group.getIntroduction(), group.getGroupImage(), member.getRole(),
getStudyGroupOwner(group).getNickname());
log.info("success to get study group");
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,29 @@ void getStudyGroupList() throws Exception {
bookmarked.add(new GetStudyGroupResponse(
(long)i, "name" + i, "groupImage" + 1,
DateFormatUtil.formatDate(LocalDate.now()), DateFormatUtil.formatDate(LocalDate.now().plusDays(i)),
"introduction" + 1, "nickname", true, true, true
"introduction" + 1, "nickname", RoleOfGroupMember.OWNER, true, true
));
}

for (int i = 0; i < 10; i++) {
done.add(new GetStudyGroupResponse(
(long)i, "name" + i, "groupImage" + 1,
DateFormatUtil.formatDate(LocalDate.now()), DateFormatUtil.formatDate(LocalDate.now().plusDays(i)),
"introduction" + 1, "nickname", true, true, true
"introduction" + 1, "nickname", RoleOfGroupMember.ADMIN, true, true
));
}
for (int i = 0; i < 10; i++) {
inProgress.add(new GetStudyGroupResponse(
(long)i, "name" + i, "groupImage" + 1,
DateFormatUtil.formatDate(LocalDate.now()), DateFormatUtil.formatDate(LocalDate.now().plusDays(i)),
"introduction" + 1, "nickname", true, true, true
"introduction" + 1, "nickname", RoleOfGroupMember.PARTICIPANT, true, true
));
}
for (int i = 0; i < 10; i++) {
queued.add(new GetStudyGroupResponse(
(long)i, "name" + i, "groupImage" + 1,
DateFormatUtil.formatDate(LocalDate.now()), DateFormatUtil.formatDate(LocalDate.now().plusDays(i)),
"introduction" + 1, "nickname", true, true, true
"introduction" + 1, "nickname", RoleOfGroupMember.PARTICIPANT, true, true
));
}
GetStudyGroupListsResponse response = new GetStudyGroupListsResponse(bookmarked, done, inProgress, queued);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void getGroupList() {
assertThat(done.get(i).startDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().minusDays(i + 30)));
assertThat(done.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().minusDays(30)));
assertThat(done.get(i).isBookmarked()).isTrue();
assertThat(done.get(i).isOwner()).isTrue();
assertThat(done.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
for (int i = 0; i < 10; i++) {
assertThat(inProgress.get(i).name()).isEqualTo("name" + i);
Expand All @@ -427,15 +427,15 @@ void getGroupList() {
DateFormatUtil.formatDate(LocalDate.now().minusDays(i)));
assertThat(inProgress.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().plusDays(i)));
assertThat(inProgress.get(i).isBookmarked()).isFalse();
assertThat(inProgress.get(i).isOwner()).isTrue();
assertThat(inProgress.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
for (int i = 0; i < 10; i++) {
assertThat(queued.get(i).name()).isEqualTo("name" + i);
assertThat(queued.get(i).ownerNickname()).isEqualTo("nickname2");
assertThat(queued.get(i).startDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().plusDays(30)));
assertThat(queued.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().plusDays(i + 30)));
assertThat(queued.get(i).isBookmarked()).isFalse();
assertThat(queued.get(i).isOwner()).isFalse();
assertThat(queued.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
for (int i = 0; i < 10; i++) {
assertThat(bookmarked.get(i).name()).isEqualTo("name" + i);
Expand All @@ -444,7 +444,7 @@ void getGroupList() {
DateFormatUtil.formatDate(LocalDate.now().minusDays(i + 30)));
assertThat(bookmarked.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().minusDays(30)));
assertThat(bookmarked.get(i).isBookmarked()).isTrue();
assertThat(bookmarked.get(i).isOwner()).isTrue();
assertThat(bookmarked.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
}

Expand Down Expand Up @@ -842,7 +842,7 @@ void getOtherUserGroupList() {
assertThat(done.get(i).startDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().minusDays(i + 30)));
assertThat(done.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().minusDays(30)));
assertThat(done.get(i).isBookmarked()).isTrue();
assertThat(done.get(i).isOwner()).isTrue();
assertThat(done.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
for (int i = 0; i < 10; i++) {
assertThat(inProgress.get(i).name()).isEqualTo("name" + i);
Expand All @@ -851,15 +851,15 @@ void getOtherUserGroupList() {
DateFormatUtil.formatDate(LocalDate.now().minusDays(i)));
assertThat(inProgress.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().plusDays(i)));
assertThat(inProgress.get(i).isBookmarked()).isFalse();
assertThat(inProgress.get(i).isOwner()).isTrue();
assertThat(inProgress.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
for (int i = 0; i < 10; i++) {
assertThat(queued.get(i).name()).isEqualTo("name" + i);
assertThat(queued.get(i).ownerNickname()).isEqualTo("nickname2");
assertThat(queued.get(i).startDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().plusDays(30)));
assertThat(queued.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().plusDays(i + 30)));
assertThat(queued.get(i).isBookmarked()).isFalse();
assertThat(queued.get(i).isOwner()).isFalse();
assertThat(queued.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
for (int i = 0; i < 10; i++) {
assertThat(bookmarked.get(i).name()).isEqualTo("name" + i);
Expand All @@ -868,7 +868,7 @@ void getOtherUserGroupList() {
DateFormatUtil.formatDate(LocalDate.now().minusDays(i + 30)));
assertThat(bookmarked.get(i).endDate()).isEqualTo(DateFormatUtil.formatDate(LocalDate.now().minusDays(30)));
assertThat(bookmarked.get(i).isBookmarked()).isTrue();
assertThat(bookmarked.get(i).isOwner()).isTrue();
assertThat(bookmarked.get(i).role()).isEqualTo(RoleOfGroupMember.OWNER);
}
}

Expand Down

0 comments on commit 7367c85

Please sign in to comment.