Skip to content

Commit 6905f63

Browse files
Merge pull request #273 from prgrms-web-devcourse-final-project/refactor/EA3-195-study
[EA3-195] refactor: 스터디 로직 리팩터링
2 parents fc03c82 + 8709d0a commit 6905f63

33 files changed

+248
-239
lines changed

src/main/java/grep/neogulcoder/domain/alram/service/AlarmService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import grep.neogulcoder.domain.study.repository.StudyMemberQueryRepository;
1919
import grep.neogulcoder.domain.study.repository.StudyMemberRepository;
2020
import grep.neogulcoder.domain.study.repository.StudyRepository;
21+
import grep.neogulcoder.domain.study.service.StudyManagementServiceFacade;
2122
import grep.neogulcoder.domain.studyapplication.StudyApplication;
2223
import grep.neogulcoder.domain.studyapplication.event.ApplicationEvent;
2324
import grep.neogulcoder.domain.studyapplication.event.ApplicationStatusChangedEvent;
@@ -57,6 +58,7 @@ public class AlarmService {
5758
private final StudyMemberRepository studyMemberRepository;
5859
private final RecruitmentPostRepository recruitmentPostRepository;
5960
private final ApplicationRepository applicationRepository;
61+
private final StudyManagementServiceFacade studyManagementServiceFacade;
6062

6163
@Transactional
6264
public void saveAlarm(Long receiverId, AlarmType alarmType, DomainType domainType,
@@ -124,6 +126,7 @@ public void acceptInvite(Long targetUserId, Long alarmId) {
124126
Long studyId = alarm.getDomainId();
125127
Study study = findValidStudy(studyId);
126128
studyMemberRepository.save(StudyMember.createMember(study, targetUserId));
129+
studyManagementServiceFacade.increaseMemberCount(study, targetUserId);
127130
alarm.checkAlarm();
128131
}
129132

src/main/java/grep/neogulcoder/domain/recruitment/post/repository/RecruitmentPostRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public interface RecruitmentPostRepository extends JpaRepository<RecruitmentPost
1818
void deactivateByStudyId(@Param("studyId") Long studyId);
1919

2020
Page<RecruitmentPost> findBySubjectContainingIgnoreCase(String subject, Pageable pageable);
21+
22+
Optional<RecruitmentPost> findByStudyIdAndActivatedTrue(Long studyId);
2123
}

src/main/java/grep/neogulcoder/domain/study/Study.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void update(String name, Category category, int capacity, StudyType study
8484
this.imageUrl = imageUrl;
8585
}
8686

87-
public boolean isStarted() {
88-
return this.startDate.isBefore(LocalDateTime.now());
87+
public boolean isStarted(LocalDateTime currentDateTime) {
88+
return this.startDate.isBefore(currentDateTime);
8989
}
9090

9191
public void delete() {

src/main/java/grep/neogulcoder/domain/study/StudyMember.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ public void changeRoleMember() {
7272
this.role = StudyMemberRole.MEMBER;
7373
}
7474

75-
public boolean isParticipated() {
76-
return this.participated;
77-
}
78-
7975
public void participate() {
8076
this.participated = true;
8177
}

src/main/java/grep/neogulcoder/domain/study/controller/StudyController.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.data.domain.Pageable;
1212
import org.springframework.data.web.PageableDefault;
1313
import org.springframework.http.MediaType;
14+
import org.springframework.http.ResponseEntity;
1415
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1516
import org.springframework.web.bind.annotation.*;
1617
import org.springframework.web.multipart.MultipartFile;
@@ -26,70 +27,70 @@ public class StudyController implements StudySpecification {
2627
private final StudyService studyService;
2728

2829
@GetMapping
29-
public ApiResponse<StudyItemPagingResponse> getMyStudies(@PageableDefault(size = 12) Pageable pageable,
30-
@RequestParam(required = false) Boolean finished,
31-
@AuthenticationPrincipal Principal userDetails) {
30+
public ResponseEntity<ApiResponse<StudyItemPagingResponse>> getMyStudies(@PageableDefault(size = 12) Pageable pageable,
31+
@RequestParam(required = false) Boolean finished,
32+
@AuthenticationPrincipal Principal userDetails) {
3233
StudyItemPagingResponse myStudies = studyService.getMyStudiesPaging(pageable, userDetails.getUserId(), finished);
33-
return ApiResponse.success(myStudies);
34+
return ResponseEntity.ok(ApiResponse.success(myStudies));
3435
}
3536

3637
@GetMapping("/main")
37-
public ApiResponse<List<StudyItemResponse>> getMyUnfinishedStudies(@AuthenticationPrincipal Principal userDetails) {
38+
public ResponseEntity<ApiResponse<List<StudyItemResponse>>> getMyUnfinishedStudies(@AuthenticationPrincipal Principal userDetails) {
3839
List<StudyItemResponse> unfinishedStudies = studyService.getMyUnfinishedStudies(userDetails.getUserId());
39-
return ApiResponse.success(unfinishedStudies);
40+
return ResponseEntity.ok(ApiResponse.success(unfinishedStudies));
4041
}
4142

4243
@GetMapping("/{studyId}/header")
43-
public ApiResponse<StudyHeaderResponse> getStudyHeader(@PathVariable("studyId") Long studyId) {
44-
return ApiResponse.success(studyService.getStudyHeader(studyId));
44+
public ResponseEntity<ApiResponse<StudyHeaderResponse>> getStudyHeader(@PathVariable("studyId") Long studyId) {
45+
return ResponseEntity.ok(ApiResponse.success(studyService.getStudyHeader(studyId)));
4546
}
4647

4748
@GetMapping("/{studyId}")
48-
public ApiResponse<StudyResponse> getStudy(@PathVariable("studyId") Long studyId) {
49-
return ApiResponse.success(studyService.getStudy(studyId));
49+
public ResponseEntity<ApiResponse<StudyResponse>> getStudy(@PathVariable("studyId") Long studyId) {
50+
return ResponseEntity.ok(ApiResponse.success(studyService.getStudy(studyId)));
5051
}
5152

5253
@GetMapping("/me/images")
53-
public ApiResponse<List<StudyImageResponse>> getStudyImages(@AuthenticationPrincipal Principal userDetails) {
54+
public ResponseEntity<ApiResponse<List<StudyImageResponse>>> getStudyImages(@AuthenticationPrincipal Principal userDetails) {
5455
Long userId = userDetails.getUserId();
55-
return ApiResponse.success(studyService.getStudyImages(userId));
56+
return ResponseEntity.ok(ApiResponse.success(studyService.getStudyImages(userId)));
5657
}
5758

5859
@GetMapping("/{studyId}/info")
59-
public ApiResponse<StudyInfoResponse> getStudyInfo(@PathVariable("studyId") Long studyId,
60+
public ResponseEntity<ApiResponse<StudyInfoResponse>> getStudyInfo(@PathVariable("studyId") Long studyId,
6061
@AuthenticationPrincipal Principal userDetails) {
6162
Long userId = userDetails.getUserId();
62-
return ApiResponse.success(studyService.getMyStudyContent(studyId, userId));
63+
return ResponseEntity.ok(ApiResponse.success(studyService.getMyStudyContent(studyId, userId)));
6364
}
6465

6566
@GetMapping("/{studyId}/me")
66-
public ApiResponse<StudyMemberInfoResponse> getMyStudyMemberInfo(@PathVariable("studyId") Long studyId,
67+
public ResponseEntity<ApiResponse<StudyMemberInfoResponse>> getMyStudyMemberInfo(@PathVariable("studyId") Long studyId,
6768
@AuthenticationPrincipal Principal userDetails) {
6869
Long userId = userDetails.getUserId();
69-
return ApiResponse.success(studyService.getMyStudyMemberInfo(studyId, userId));
70+
return ResponseEntity.ok(ApiResponse.success(studyService.getMyStudyMemberInfo(studyId, userId)));
7071
}
7172

7273
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
73-
public ApiResponse<Long> createStudy(@RequestPart("request") @Valid StudyCreateRequest request,
74+
public ResponseEntity<ApiResponse<Long>> createStudy(@RequestPart("request") @Valid StudyCreateRequest request,
7475
@RequestPart(value = "image", required = false) MultipartFile image,
7576
@AuthenticationPrincipal Principal userDetails) throws IOException {
7677
Long id = studyService.createStudy(request, userDetails.getUserId(), image);
77-
return ApiResponse.success(id);
78+
return ResponseEntity.ok(ApiResponse.success(id));
7879
}
7980

8081
@PutMapping(value = "/{studyId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
81-
public ApiResponse<Void> updateStudy(@PathVariable("studyId") Long studyId,
82+
public ResponseEntity<ApiResponse<Void>> updateStudy(@PathVariable("studyId") Long studyId,
8283
@RequestPart @Valid StudyUpdateRequest request,
8384
@RequestPart(value = "image", required = false) MultipartFile image,
8485
@AuthenticationPrincipal Principal userDetails) throws IOException {
8586
studyService.updateStudy(studyId, request, userDetails.getUserId(), image);
86-
return ApiResponse.noContent();
87+
return ResponseEntity.ok(ApiResponse.noContent());
8788
}
8889

8990
@DeleteMapping("/{studyId}")
90-
public ApiResponse<Void> deleteStudy(@PathVariable("studyId") Long studyId,
91+
public ResponseEntity<ApiResponse<Void>> deleteStudy(@PathVariable("studyId") Long studyId,
9192
@AuthenticationPrincipal Principal userDetails) {
9293
studyService.deleteStudy(studyId, userDetails.getUserId());
93-
return ApiResponse.noContent();
94+
return ResponseEntity.ok(ApiResponse.noContent());
9495
}
9596
}

src/main/java/grep/neogulcoder/domain/study/controller/StudyManagementController.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import grep.neogulcoder.global.response.ApiResponse;
1010
import jakarta.validation.Valid;
1111
import lombok.RequiredArgsConstructor;
12+
import org.springframework.http.ResponseEntity;
1213
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1314
import org.springframework.web.bind.annotation.*;
1415

@@ -22,51 +23,50 @@ public class StudyManagementController implements StudyManagementSpecification {
2223
private final StudyManagementService studyManagementService;
2324

2425
@GetMapping("/extension")
25-
public ApiResponse<StudyExtensionResponse> getStudyExtension(@PathVariable("studyId") Long studyId) {
26+
public ResponseEntity<ApiResponse<StudyExtensionResponse>> getStudyExtension(@PathVariable("studyId") Long studyId) {
2627
StudyExtensionResponse studyExtension = studyManagementService.getStudyExtension(studyId);
27-
return ApiResponse.success(studyExtension);
28+
return ResponseEntity.ok(ApiResponse.success(studyExtension));
2829
}
2930

3031
@GetMapping("/extension/participations")
31-
public ApiResponse<List<ExtendParticipationResponse>> getExtendParticipations(@PathVariable("studyId") Long studyId) {
32+
public ResponseEntity<ApiResponse<List<ExtendParticipationResponse>>> getExtendParticipations(@PathVariable("studyId") Long studyId) {
3233
List<ExtendParticipationResponse> extendParticipations = studyManagementService.getExtendParticipations(studyId);
33-
return ApiResponse.success(extendParticipations);
34+
return ResponseEntity.ok(ApiResponse.success(extendParticipations));
3435
}
3536

3637
@DeleteMapping("/me")
37-
public ApiResponse<Void> leaveStudy(@PathVariable("studyId") Long studyId,
38+
public ResponseEntity<ApiResponse<Void>> leaveStudy(@PathVariable("studyId") Long studyId,
3839
@AuthenticationPrincipal Principal userDetails) {
3940
studyManagementService.leaveStudy(studyId, userDetails.getUserId());
40-
return ApiResponse.noContent();
41+
return ResponseEntity.ok(ApiResponse.noContent());
4142
}
4243

4344
@PostMapping("/delegate")
44-
public ApiResponse<Void> delegateLeader(@PathVariable("studyId") Long studyId,
45+
public ResponseEntity<ApiResponse<Void>> delegateLeader(@PathVariable("studyId") Long studyId,
4546
@RequestBody DelegateLeaderRequest request,
4647
@AuthenticationPrincipal Principal userDetails) {
4748
studyManagementService.delegateLeader(studyId, userDetails.getUserId(), request.getNewLeaderId());
48-
return ApiResponse.noContent();
49+
return ResponseEntity.ok(ApiResponse.noContent());
4950
}
5051

5152
@PostMapping("/extension")
52-
public ApiResponse<Long> extendStudy(@PathVariable("studyId") Long studyId,
53+
public ResponseEntity<ApiResponse<Long>> extendStudy(@PathVariable("studyId") Long studyId,
5354
@RequestBody @Valid ExtendStudyRequest request,
5455
@AuthenticationPrincipal Principal userDetails) {
5556
Long extendStudyId = studyManagementService.extendStudy(studyId, request, userDetails.getUserId());
56-
return ApiResponse.success(extendStudyId);
57+
return ResponseEntity.ok(ApiResponse.success(extendStudyId));
5758
}
5859

5960
@PostMapping("/extension/participations")
60-
public ApiResponse<Void> registerExtensionParticipation(@PathVariable("studyId") Long studyId,
61+
public ResponseEntity<ApiResponse<Void>> registerExtensionParticipation(@PathVariable("studyId") Long studyId,
6162
@AuthenticationPrincipal Principal userDetails) {
6263
studyManagementService.registerExtensionParticipation(studyId, userDetails.getUserId());
63-
return ApiResponse.noContent();
64+
return ResponseEntity.ok(ApiResponse.noContent());
6465
}
6566

6667
@PostMapping("/invite/user")
67-
public ApiResponse<Void> inviteUser(@PathVariable("studyId") Long studyId, @AuthenticationPrincipal Principal userDetails, String targetUserNickname) {
68+
public ResponseEntity<ApiResponse<Void>> inviteUser(@PathVariable("studyId") Long studyId, @AuthenticationPrincipal Principal userDetails, String targetUserNickname) {
6869
studyManagementService.inviteTargetUser(studyId, userDetails.getUserId(), targetUserNickname);
69-
return ApiResponse.noContent();
70+
return ResponseEntity.ok(ApiResponse.noContent());
7071
}
71-
7272
}

src/main/java/grep/neogulcoder/domain/study/controller/StudyManagementSpecification.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@
88
import grep.neogulcoder.global.response.ApiResponse;
99
import io.swagger.v3.oas.annotations.Operation;
1010
import io.swagger.v3.oas.annotations.tags.Tag;
11+
import org.springframework.http.ResponseEntity;
1112

1213
import java.util.List;
1314

1415
@Tag(name = "StudyManagement", description = "스터디 관리 API")
1516
public interface StudyManagementSpecification {
1617

1718
@Operation(summary = "스터디 연장 여부 조회", description = "스터디 연장 여부를 조회합니다.")
18-
ApiResponse<StudyExtensionResponse> getStudyExtension(Long studyId);
19+
ResponseEntity<ApiResponse<StudyExtensionResponse>> getStudyExtension(Long studyId);
1920

2021
@Operation(summary = "연장 스터디 참여 멤버 목록 조회", description = "연장 스터디에 참여하는 멤버 목록을 조회합니다.")
21-
ApiResponse<List<ExtendParticipationResponse>> getExtendParticipations(Long studyId);
22+
ResponseEntity<ApiResponse<List<ExtendParticipationResponse>>> getExtendParticipations(Long studyId);
2223

2324
@Operation(summary = "스터디 탈퇴", description = "스터디를 탈퇴합니다.")
24-
ApiResponse<Void> leaveStudy(Long studyId, Principal userDetails);
25+
ResponseEntity<ApiResponse<Void>> leaveStudy(Long studyId, Principal userDetails);
2526

2627
@Operation(summary = "스터디장 위임", description = "스터디원에게 스터디장을 위임합니다.")
27-
ApiResponse<Void> delegateLeader(Long studyId, DelegateLeaderRequest request, Principal userDetails);
28+
ResponseEntity<ApiResponse<Void>> delegateLeader(Long studyId, DelegateLeaderRequest request, Principal userDetails);
2829

2930
@Operation(summary = "스터디 연장", description = "스터디장이 스터디를 연장합니다.")
30-
ApiResponse<Long> extendStudy(Long studyId, ExtendStudyRequest request, Principal userDetails);
31+
ResponseEntity<ApiResponse<Long>> extendStudy(Long studyId, ExtendStudyRequest request, Principal userDetails);
3132

3233
@Operation(summary = "연장 스터디 참여", description = "스터디원이 연장된 스터디에 참여합니다.")
33-
ApiResponse<Void> registerExtensionParticipation(Long studyId, Principal userDetails);
34+
ResponseEntity<ApiResponse<Void>> registerExtensionParticipation(Long studyId, Principal userDetails);
35+
36+
@Operation(summary = "스터디 초대", description = "스터디장이 스터디에 초대합니다.")
37+
ResponseEntity<ApiResponse<Void>> inviteUser(Long studyId, Principal userDetails, String targetUserNickname);
3438
}

src/main/java/grep/neogulcoder/domain/study/controller/StudySpecification.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.swagger.v3.oas.annotations.Operation;
99
import io.swagger.v3.oas.annotations.tags.Tag;
1010
import org.springframework.data.domain.Pageable;
11+
import org.springframework.http.ResponseEntity;
1112
import org.springframework.web.multipart.MultipartFile;
1213

1314
import java.io.IOException;
@@ -17,32 +18,32 @@
1718
public interface StudySpecification {
1819

1920
@Operation(summary = "스터디 목록 조회", description = "가입한 스터디 목록을 조회합니다.")
20-
ApiResponse<StudyItemPagingResponse> getMyStudies(Pageable pageable, Boolean finished, Principal userDetails);
21+
ResponseEntity<ApiResponse<StudyItemPagingResponse>> getMyStudies(Pageable pageable, Boolean finished, Principal userDetails);
2122

2223
@Operation(summary = "종료되지않은 내 스터디 목록 조회", description = "종료되지않은 내 스터디 목록을 조회합니다.")
23-
ApiResponse<List<StudyItemResponse>> getMyUnfinishedStudies(Principal userDetails);
24+
ResponseEntity<ApiResponse<List<StudyItemResponse>>> getMyUnfinishedStudies(Principal userDetails);
2425

2526
@Operation(summary = "스터디 헤더 조회", description = "스터디 헤더 정보를 조회합니다.")
26-
ApiResponse<StudyHeaderResponse> getStudyHeader(Long studyId);
27+
ResponseEntity<ApiResponse<StudyHeaderResponse>> getStudyHeader(Long studyId);
2728

2829
@Operation(summary = "스터디 조회", description = "스터디를 조회합니다.")
29-
ApiResponse<StudyResponse> getStudy(Long studyId);
30+
ResponseEntity<ApiResponse<StudyResponse>> getStudy(Long studyId);
3031

3132
@Operation(summary = "스터디 대표 이미지 조회", description = "참여중인 스터디의 대표 이미지 목록을 조회합니다.")
32-
ApiResponse<List<StudyImageResponse>> getStudyImages(Principal userDetails);
33+
ResponseEntity<ApiResponse<List<StudyImageResponse>>> getStudyImages(Principal userDetails);
3334

3435
@Operation(summary = "스터디 정보 조회", description = "스터디장이 스터디 정보를 조회합니다.")
35-
ApiResponse<StudyInfoResponse> getStudyInfo(Long studyId, Principal userDetails);
36+
ResponseEntity<ApiResponse<StudyInfoResponse>> getStudyInfo(Long studyId, Principal userDetails);
3637

3738
@Operation(summary = "스터디 내 정보 조회", description = "스터디에서 사용자의 정보를 조회합니다.")
38-
ApiResponse<StudyMemberInfoResponse> getMyStudyMemberInfo(Long studyId, Principal userDetails);
39+
ResponseEntity<ApiResponse<StudyMemberInfoResponse>> getMyStudyMemberInfo(Long studyId, Principal userDetails);
3940

4041
@Operation(summary = "스터디 생성", description = "새로운 스터디를 생성합니다.")
41-
ApiResponse<Long> createStudy(StudyCreateRequest request, MultipartFile image, Principal userDetails) throws IOException;
42+
ResponseEntity<ApiResponse<Long>> createStudy(StudyCreateRequest request, MultipartFile image, Principal userDetails) throws IOException;
4243

4344
@Operation(summary = "스터디 수정", description = "스터디를 수정합니다.")
44-
ApiResponse<Void> updateStudy(Long studyId, StudyUpdateRequest request, MultipartFile image, Principal userDetails) throws IOException;
45+
ResponseEntity<ApiResponse<Void>> updateStudy(Long studyId, StudyUpdateRequest request, MultipartFile image, Principal userDetails) throws IOException;
4546

4647
@Operation(summary = "스터디 삭제", description = "스터디를 삭제합니다.")
47-
ApiResponse<Void> deleteStudy(Long studyId, Principal userDetails);
48+
ResponseEntity<ApiResponse<Void>> deleteStudy(Long studyId, Principal userDetails);
4849
}

src/main/java/grep/neogulcoder/domain/study/controller/dto/request/ExtendStudyRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ private ExtendStudyRequest(LocalDateTime newEndDate) {
2222
this.newEndDate = newEndDate;
2323
}
2424

25-
public Study toEntity(Study study) {
25+
public Study toEntity(Study study, Long userId) {
2626
return Study.builder()
27+
.userId(userId)
2728
.originStudyId(study.getId())
2829
.name(study.getName())
2930
.category(study.getCategory())

0 commit comments

Comments
 (0)