Skip to content
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

Yeeun2 #50

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@PreAuthorize("hasAnyRole('USER')")
@PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN','ROLE_CERTIFIED')")
@RequestMapping("/app/studies")
public class StudyController {
private final StudyService studyService;
Expand Down Expand Up @@ -152,7 +153,7 @@ public BaseResponse<?> checkCompletedStudyWeek(@PathVariable Long study_id, @Req
@GetMapping("/{study_id}/progress")
public BaseResponse<?> getStudyProgressList(@PathVariable Long study_id){
try {
List<ProgressRes> studyProgressList = studyService.getStudyProgressList(study_id, getEmail());
Map<String, Object> studyProgressList = studyService.getStudyProgressList(study_id, getEmail());
return new BaseResponse<>(BaseResponseStatus.SUCCESS, studyProgressList);
}catch (BaseException e){
return new BaseResponse<>(e.getStatus());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.StudyFlexBE.dto.response;

import com.umc.StudyFlexBE.entity.StudyStatus;
import lombok.*;

@Builder
Expand All @@ -9,6 +10,6 @@
public class MyStudyRes {
private Long studyId;
private String name;

private StudyStatus status;
private String thumbnailUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
public class StudyNoticesRes {
private String title;
private LocalDateTime createAt;
private long noticeId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public MyStudyListRes getParticipationStudies(String email) {
throw new BaseException(BaseResponseStatus.NO_SUCH_EMAIL);
}
List<StudyParticipation> studyParticipations = studyParticipationRepository.findAllByMember(member);
System.out.println(studyParticipations);

List<MyStudyRes> myStudyList = studyParticipations.stream()
.map(studyParticipation -> MyStudyRes.builder()
.studyId(studyParticipation.getStudy().getId())
.name(studyParticipation.getStudy().getName())
.status(studyParticipation.getStudy().getStatus())
.thumbnailUrl(studyParticipation.getStudy().getThumbnailUrl())
.build())
.collect(Collectors.toList());
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/umc/StudyFlexBE/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -287,6 +285,7 @@ public StudyNoticesInfoRes getStudyNotices(Long studyId, String email) {
.stream()
.map(studyNotice ->
StudyNoticesRes.builder()
.noticeId(studyNotice.getId())
.title(studyNotice.getTitle())
.createAt(studyNotice.getCreatedAt())
.build()
Expand Down Expand Up @@ -334,7 +333,7 @@ public ProgressRes checkCompletedStudyWeek(long studyId, int week, String email)
.build();
}

public List<ProgressRes> getStudyProgressList(long studyId, String email) {
public Map<String, Object> getStudyProgressList(long studyId, String email) {
Study study = studyRepository.findById(studyId).orElseThrow(
() -> new BaseException(BaseResponseStatus.NO_SUCH_STUDY)
);
Expand All @@ -345,7 +344,7 @@ public List<ProgressRes> getStudyProgressList(long studyId, String email) {
// 멤버와 스터디에 해당하는 StudyParticipation 찾기 (존재하지 않을 수도 있음)
Optional<StudyParticipation> optionalStudyParticipation = studyParticipationRepository.findByStudyAndMember(study, member);

return progressRepository.findAllByStudy(study)
List<ProgressRes> progressList = progressRepository.findAllByStudy(study)
.stream()
.map(progress -> {
Optional<Boolean> isMemberCompleted;
Expand All @@ -370,9 +369,16 @@ public List<ProgressRes> getStudyProgressList(long studyId, String email) {
.completed(isMemberCompleted) // 현재 멤버가 해당 주차를 완료했는지 여부 (null이면 참여하지 않은 것으로 간주)
.build();
}).collect(Collectors.toList());

Map<String, Object> result = new HashMap<>();
result.put("name", study.getName());
result.put("progress", progressList);

return result;
}



public StudyDetailRes getStudyDetail(long studyId){
Study study = studyRepository.findById(studyId).orElseThrow(
() -> new BaseException(BaseResponseStatus.NO_SUCH_STUDY)
Expand Down
Loading