Skip to content

Commit

Permalink
Merge pull request #46 from StudyFlexUMC5th/yeeun2
Browse files Browse the repository at this point in the history
Fix: 마이스터디
  • Loading branch information
Yeeun411 authored Jan 13, 2024
2 parents c320f7e + 01c3dea commit e170d8f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/app/myPage")
Expand Down Expand Up @@ -36,7 +38,7 @@ public BaseResponse<?> getMyPage(){
public BaseResponse<?> getParticipationStudy(){
try {
String email = getEmail();
GetParticipationStudyRes res = myPageService.getParticipationStudy(email);
List<GetParticipationStudyRes> res = myPageService.getParticipationStudies(email);
return new BaseResponse<>(BaseResponseStatus.SUCCESS,res);
} catch (BaseException e) {
if(e.getStatus().equals(BaseResponseStatus.NO_SUCH_EMAIL)) {
Expand Down
59 changes: 44 additions & 15 deletions src/main/java/com/umc/StudyFlexBE/service/MyPageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,65 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class MyPageService {

private final StudyParticipationRepository studyParticipationRepository;
private final MemberRepository memberRepository;


public GetParticipationStudyRes getParticipationStudy(String email) {
public List<GetParticipationStudyRes> getParticipationStudies(String email) {
Member member = memberRepository.findByEmail(email);
if (member == null) {
throw new BaseException(BaseResponseStatus.NO_SUCH_EMAIL);
}
List<StudyParticipation> studyParticipations = studyParticipationRepository.findByMember(member);
System.out.println(studyParticipations);

StudyParticipation studyParticipation = studyParticipationRepository.findByMember(member).orElse(null);

if(studyParticipation == null){
return GetParticipationStudyRes.builder()
.isParticipation(true)
.studyId(studyParticipation.getStudy().getId())
.build();
if (studyParticipations.isEmpty()) {
// 참여 중인 스터디가 없는 경우
return List.of(GetParticipationStudyRes.builder()
.isParticipation(false)
.studyId(-1L)
.build());
} else {
// 참여 중인 스터디가 있는 경우
return studyParticipations.stream()
.map(studyParticipation -> GetParticipationStudyRes.builder()
.isParticipation(true)
.studyId(studyParticipation.getStudy().getId())
.build())
.collect(Collectors.toList());
}

return GetParticipationStudyRes.builder()
.isParticipation(false)
.studyId(-1L)
.build();

}

//
// public GetParticipationStudyRes getParticipationStudy(String email) {
// Member member = memberRepository.findByEmail(email);
// if (member == null) {
// throw new BaseException(BaseResponseStatus.NO_SUCH_EMAIL);
// }
//
// List<StudyParticipation> studyParticipation = studyParticipationRepository.findByMember(member);
//
// if(studyParticipation == null){
// return GetParticipationStudyRes.builder()
// .isParticipation(true)
// .studyId(studyParticipation.getStudy().getId())
// .build();
// }
//
// return GetParticipationStudyRes.builder()
// .isParticipation(false)
// .studyId(-1L)
// .build();
//
// }

public MyPageRes getMyPage(String email) {
Member member = memberRepository.findByEmail(email);
if (member == null) {
Expand Down

0 comments on commit e170d8f

Please sign in to comment.