-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat : 스터디 그룹 공개 여부 설정 API 추가 #144
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
341624b
feat : 스터디 그룹 공개 여부 수정 API 추가
rladmstn c92d9f4
test : 스터디 그룹 공개 여부 수정 테스트 작성
rladmstn a2a8bc4
test : 스터디 그룹 공개 여부 수정 Controller 테스트 작성
rladmstn 75e97f4
feat : 스터디 그룹 목록 조회 시, 공개 여부 필드 추가
rladmstn 543a314
test : 스터디 그룹 목록 조회 시, 공개 여부 필드 테스트 수정
rladmstn 960f3d1
Merge branch 'develop' into feat/#143
rladmstn fc51227
refactor : 공개 여부 필드 네이밍 수정
rladmstn b047a7a
refactor : 로깅에 유저 고유 아이디 정보 추가
rladmstn 6204add
refactor : isVisible 타입 수정
rladmstn 2965398
fix : isVisible 타입 수정에 따른 오류 해결
rladmstn 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
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
7 changes: 7 additions & 0 deletions
7
...in/java/com/gamzabat/algohub/feature/group/studygroup/dto/EditGroupVisibilityRequest.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,7 @@ | ||
package com.gamzabat.algohub.feature.group.studygroup.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record EditGroupVisibilityRequest(@NotNull(message = "그룹 아이디는 필수 입력입니다.") Long groupId, | ||
boolean isPublic) { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import com.gamzabat.algohub.feature.group.studygroup.dto.CheckSolvedProblemResponse; | ||
import com.gamzabat.algohub.feature.group.studygroup.dto.CreateGroupRequest; | ||
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupRequest; | ||
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupVisibilityRequest; | ||
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupMemberResponse; | ||
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupResponse; | ||
import com.gamzabat.algohub.feature.group.studygroup.dto.GetStudyGroupListsResponse; | ||
|
@@ -185,30 +186,26 @@ public GetStudyGroupListsResponse getStudyGroupList(User user) { | |
List<StudyGroup> groups = groupRepository.findAllByUser(user); | ||
|
||
List<GetStudyGroupResponse> bookmarked = bookmarkedStudyGroupRepository.findAllByUser(user).stream() | ||
.map(bookmark -> GetStudyGroupResponse.toDTO(bookmark.getStudyGroup(), user, true, | ||
getStudyGroupOwner(bookmark.getStudyGroup()))) | ||
.map(bookmark -> getStudyGroupResponseDTO(user, bookmark.getStudyGroup())) | ||
.toList(); | ||
|
||
LocalDate today = LocalDate.now(); | ||
|
||
List<GetStudyGroupResponse> done = groups.stream() | ||
.filter(group -> group.getEndDate() != null && group.getEndDate().isBefore(today)) | ||
.map( | ||
group -> GetStudyGroupResponse.toDTO(group, user, isBookmarked(user, group), getStudyGroupOwner(group))) | ||
.map(group -> getStudyGroupResponseDTO(user, group)) | ||
.toList(); | ||
|
||
List<GetStudyGroupResponse> inProgress = groups.stream() | ||
.filter( | ||
group -> !(group.getStartDate() == null || group.getStartDate().isAfter(today)) | ||
&& !(group.getEndDate() == null || group.getEndDate().isBefore(today))) | ||
.map( | ||
group -> GetStudyGroupResponse.toDTO(group, user, isBookmarked(user, group), getStudyGroupOwner(group))) | ||
.map(group -> getStudyGroupResponseDTO(user, group)) | ||
.toList(); | ||
|
||
List<GetStudyGroupResponse> queued = groups.stream() | ||
.filter(group -> group.getStartDate() != null && group.getStartDate().isAfter(today)) | ||
.map( | ||
group -> GetStudyGroupResponse.toDTO(group, user, isBookmarked(user, group), getStudyGroupOwner(group))) | ||
.map(group -> getStudyGroupResponseDTO(user, group)) | ||
.toList(); | ||
|
||
GetStudyGroupListsResponse response = new GetStudyGroupListsResponse(bookmarked, done, inProgress, queued); | ||
|
@@ -217,6 +214,13 @@ public GetStudyGroupListsResponse getStudyGroupList(User user) { | |
return response; | ||
} | ||
|
||
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), | ||
member.isPublic()); | ||
} | ||
|
||
private User getStudyGroupOwner(StudyGroup group) { | ||
return groupMemberRepository.findByStudyGroupAndRole(group, RoleOfGroupMember.OWNER).getUser(); | ||
} | ||
|
@@ -416,4 +420,16 @@ public String getRoleInGroup(User user, Long groupId) { | |
|
||
return member.getRole().getValue(); | ||
} | ||
|
||
@Transactional | ||
public void editStudyGroupVisibility(User user, EditGroupVisibilityRequest request) { | ||
StudyGroup group = groupRepository.findById(request.groupId()) | ||
.orElseThrow(() -> new CannotFoundGroupException("존재하지 않는 그룹입니다.")); | ||
|
||
GroupMember member = groupMemberRepository.findByUserAndStudyGroup(user, group) | ||
.orElseThrow(() -> new GroupMemberValidationException(HttpStatus.FORBIDDEN.value(), "참여하지 않은 그룹입니다.")); | ||
|
||
member.updateVisibility(request.isPublic()); | ||
log.info("success to update group visibility"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] 로깅에 식별자정도 남기면 좋을 것 같아요~ |
||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean +
@NotNull
겁시다~그리고 필드 이름이랑, 엔드포인트 이름이랑 어느정도 통합하게
isVisible
정도 어때요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오
isVisible
좋네요! 수정해야겠어요 의견 감삼다There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
갑자기 생각난건데요 왜 엔티티에는 primitive type으로 안쓰나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
primitive 타입은 null을 소화할수 없어서 그렇습니다
ex) int age 했는데 db에 널 들어있는 경우
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null이 불가능하단건 알고있었는데, reference type + NotNull을 하게 되면 결국 primitive type과 같아지는게 아닌건가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 맞긴합니다~
그냥 표현의 차이긴 합니다. primitive 쓴다고 문제가 생기진 않아서, 작업할때 원하는 방향 가도 되는 부분입니다
다만 notnull은 꼭 걸어줘야겠네용