-
Notifications
You must be signed in to change notification settings - Fork 5
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
[BE] issue122: 스터디 참여 기능 #132
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
8de6562
refactor: 네이밍 변경
tco0427 40a88b4
feat: StudyService 구현 및 테스트
tco0427 593a4d3
Merge branch 'develop' of https://github.com/woowacourse-teams/2022-m…
tco0427 b0dc328
feat: Participants 검증 로직 및 참여자 추가 로직 구현
tco0427 0f79069
feat: Details `CLOSE` 확인 로직 추가
tco0427 bbc410a
feat: Period 모집 기간 확인 로직 추가
tco0427 9f0a622
feat: Study 참여 로직 추가
tco0427 3df6cba
feat: StudyService 회원 참여 기능 구현 및 생성 테스트 로직 추가
tco0427 5b6a5c5
feat: StudyController 구현 및 테스트
tco0427 40a7434
fix: 스터디 생성 테스트 오류 수정
tco0427 47b49dd
fix: EnrollmentEndDate 는 null 일수 있으므로 이를 고려하여 검증 로직 수정
tco0427 63a4378
feat: 인수 테스트 작성
tco0427 9291dd0
fix: ParticipantsTest 수정
tco0427 0634073
fix: owner는 participants 가 아니므로 제거
tco0427 72274e1
fix: isInvalidMemberSize `스터디 최대 인원수` 가 없는 경우도 반영하도록 수정
tco0427 b1ec72f
refactor: 마감일자 검증 로직 가독성 있게 변경
tco0427 90e9ec5
refactor: assertThatThrownBy().isInstnaceOf() 로 예외 타입 체크
tco0427 e482a95
refactor: `isAlreadyParticipation` 메소드 내부 로직 메소드 분리
tco0427 f7f8bd3
refactor: 의미가 분명한 네이밍으로 변경
tco0427 5822471
fix: 참여자에서 방장은 제외하도록 수정
tco0427 78aafb4
fix: 참여자수를 확인하는 테스트 코드 수정
tco0427 574b6ad
refactor: checkParticipating 캡슐화
tco0427 6d34aee
refactor: 스터디 참여 검증 로직 개선
tco0427 8786486
test: 스터디장은 스터디에 참여할 수 없다.
tco0427 d9c0b25
refactor: Study 추상화 및 예외 네이밍 변경
tco0427 eed9d4e
refactor: Boolean 네이밍 변경
tco0427 4875818
refactor: 메소드명 동사로 변경
tco0427 7b78036
refactor: participate 메소드 수정
tco0427 4dce039
fix: 깨지는 테스트 수정
tco0427 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
25 changes: 17 additions & 8 deletions
25
backend/src/main/java/com/woowacourse/moamoa/study/controller/StudyController.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,31 +1,40 @@ | ||
package com.woowacourse.moamoa.study.controller; | ||
|
||
import com.woowacourse.moamoa.auth.config.AuthenticationPrincipal; | ||
import com.woowacourse.moamoa.study.service.request.CreateStudyRequest; | ||
import com.woowacourse.moamoa.study.domain.Study; | ||
import com.woowacourse.moamoa.study.service.CreateStudyService; | ||
import com.woowacourse.moamoa.study.service.StudyService; | ||
import com.woowacourse.moamoa.study.service.request.CreatingStudyRequest; | ||
import java.net.URI; | ||
import javax.validation.Valid; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Getter | ||
@RequestMapping("/api/studies") | ||
public class StudyController { | ||
|
||
private final CreateStudyService createStudyService; | ||
private final StudyService studyService; | ||
|
||
@PostMapping("/api/studies") | ||
@PostMapping | ||
public ResponseEntity<Void> createStudy( | ||
@AuthenticationPrincipal final Long githubId, | ||
@Valid @RequestBody(required = false) final CreateStudyRequest createStudyRequest | ||
@Valid @RequestBody(required = false) final CreatingStudyRequest creatingStudyRequest | ||
) { | ||
final Study study = createStudyService.createStudy(githubId, createStudyRequest); | ||
final Study study = studyService.createStudy(githubId, creatingStudyRequest); | ||
return ResponseEntity.created(URI.create("/api/studies/" + study.getId())).build(); | ||
} | ||
|
||
@PostMapping("/{study-id}") | ||
public ResponseEntity<Void> participateStudy(@AuthenticationPrincipal final Long githubId, | ||
@PathVariable("study-id") final Long studyId | ||
) { | ||
studyService.participateStudy(githubId, studyId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
package com.woowacourse.moamoa.study.domain; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import javax.persistence.CollectionTable; | ||
import javax.persistence.Column; | ||
import javax.persistence.ElementCollection; | ||
import javax.persistence.Embeddable; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Embeddable | ||
@ToString | ||
@NoArgsConstructor(access = PROTECTED) | ||
public class Participants { | ||
|
||
@Column(name = "current_member_count") | ||
|
@@ -26,13 +31,10 @@ public class Participants { | |
|
||
@ElementCollection | ||
@CollectionTable(name = "study_member", joinColumns = @JoinColumn(name = "study_id")) | ||
private List<Participant> participants = new ArrayList<>(); | ||
|
||
protected Participants() { | ||
} | ||
private Set<Participant> participants = new HashSet<>(); | ||
|
||
public Participants(final Integer size, final Integer max, | ||
final List<Participant> participants, Long ownerId) { | ||
final Set<Participant> participants, Long ownerId) { | ||
this.size = size; | ||
this.max = max; | ||
this.participants = participants; | ||
|
@@ -43,8 +45,38 @@ public List<Participant> getParticipants() { | |
return new ArrayList<>(participants); | ||
} | ||
|
||
public static Participants createByMaxSizeAndOwnerId(final Integer maxSize, Long id) { | ||
return new Participants(1, maxSize, new ArrayList<>(), id); | ||
public static Participants createByMaxSizeAndOwnerId(final Integer maxSize, Long ownerId) { | ||
return new Participants(1, maxSize, new HashSet<>(), ownerId); | ||
} | ||
|
||
public int getCurrentMemberSize() { | ||
return size; | ||
} | ||
|
||
void participate(final Participant participant) { | ||
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. 👍 |
||
participants.add(participant); | ||
size = size + 1; | ||
} | ||
|
||
boolean isImpossibleParticipation(Long memberId) { | ||
return isInvalidMemberSize() || isAlreadyParticipation(memberId); | ||
} | ||
|
||
private boolean isInvalidMemberSize() { | ||
return max != null && max <= size; | ||
} | ||
|
||
private boolean isAlreadyParticipation(final Long memberId) { | ||
final Participant participant = new Participant(memberId); | ||
return isOwner(memberId) || isParticipated(participant); | ||
} | ||
|
||
private boolean isOwner(final Long memberId) { | ||
return Objects.equals(memberId, ownerId); | ||
} | ||
|
||
private boolean isParticipated(final Participant participant) { | ||
return participants.contains(participant); | ||
} | ||
|
||
@Override | ||
|
@@ -61,7 +93,7 @@ public boolean equals(final Object o) { | |
} | ||
|
||
@Override | ||
public int hashCode() { | ||
public int hashCode() { | ||
return Objects.hash(size, max, ownerId, participants); | ||
} | ||
} |
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.
중복된 값 X 👍 명확해서 좋아요!