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

Study Controller, Service 추가 #11

Merged
merged 22 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
22dd9b1
feat: 스터디 생성 기능 추가
ybkang1108 Jan 16, 2025
90ad73f
feat: StudyCreateResponse DTO 추가
ybkang1108 Jan 16, 2025
2ea0826
feat: 스터디 전체 목록 조회 기능 추가
ybkang1108 Jan 16, 2025
3310c20
feat: 스터디 정보 조회 기능 추가
ybkang1108 Jan 16, 2025
b700946
feat: 스터디 삭제 기능 추가
ybkang1108 Jan 16, 2025
e99cab5
refactor: delete, detail response dto수정 및 cascade 설정
ybkang1108 Jan 17, 2025
52858dc
feat: 스터디 수정 기능 추가
ybkang1108 Jan 17, 2025
33b6e77
refactor: response에 메시지 제거
ybkang1108 Jan 17, 2025
baf1a6e
refactor: dto를 record로 변경
ybkang1108 Jan 21, 2025
e45b8ad
feat: exception 추가
ybkang1108 Jan 21, 2025
a412bbf
refactor: curriculum 수정
ybkang1108 Jan 22, 2025
2a4f89f
feat: day에 create 추가
ybkang1108 Jan 22, 2025
d864b11
refactor: record로 변경
ybkang1108 Jan 22, 2025
eb57a8f
feat: custom exception 추가
ybkang1108 Jan 22, 2025
6633caf
refactor: record로 변경
ybkang1108 Jan 22, 2025
047112b
feat: study 도메인에 create, update 추가
ybkang1108 Jan 22, 2025
2ce3d78
refactor: study service 수정
ybkang1108 Jan 22, 2025
889051a
refactor: study controller 수정
ybkang1108 Jan 22, 2025
ee5864b
refactor: springdoc 버전 수정
ybkang1108 Jan 23, 2025
ff5eb99
refactor: 불필요한 생성자 제거
ybkang1108 Jan 24, 2025
31ad47d
refactor: create, update 메소드 도메인으로 이동
ybkang1108 Jan 24, 2025
872757d
fix: 잘못된 로직 수정
ybkang1108 Jan 24, 2025
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
Prev Previous commit
Next Next commit
feat: 스터디 수정 기능 추가
스터디 수정 기능을 service와 controller에 추가
ybkang1108 committed Jan 17, 2025
commit 52858dc9a77977e9b006931d254bc76d217ef037
18 changes: 15 additions & 3 deletions src/main/java/com/gdgoc/study_group/study/api/StudyController.java
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -38,23 +38,35 @@ public ResponseEntity<?> getStudyDetail(@PathVariable("studyId") Long studyId) {

if (studyDetail == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다.").build());
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다.").build());
}

return ResponseEntity.status(HttpStatus.OK).body(studyDetail);
}

@PatchMapping("/{studyId}")
public ResponseEntity<?> updateStudy(
@PathVariable("studyId") Long studyId, @RequestBody StudyCreateRequest updateRequest) {
Long updatedStudyId = studyService.updateStudy(studyId, updateRequest);
if (updatedStudyId == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다").build());
}
return ResponseEntity.status(HttpStatus.OK)
.body(StudyCreateResponse.builder().message("스터디가 수정되었습니다.").id(updatedStudyId).build());
}

@DeleteMapping("/{studyId}")
public ResponseEntity<MessageResponse> deleteStudy(@PathVariable("studyId") Long studyId) {
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved

boolean isStudyExist = studyService.deleteStudy(studyId);

if (isStudyExist) {
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
return ResponseEntity.status(HttpStatus.NO_CONTENT)
.body(MessageResponse.builder().message("스터디가 삭제되었습니다.").build());
.body(MessageResponse.builder().message("스터디가 삭제되었습니다.").build());
}

return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다.").build());
.body(MessageResponse.builder().message("해당하는 스터디가 없습니다.").build());
}
}
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
import com.gdgoc.study_group.study.dao.StudyRepository;
import com.gdgoc.study_group.study.domain.Study;
import com.gdgoc.study_group.study.dto.*;
import com.gdgoc.study_group.studyMember.domain.StudyMember;
import com.gdgoc.study_group.studyMember.domain.StudyMemberStatus;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -27,32 +25,25 @@ public StudyService(StudyRepository studyRepository, MemberRepository memberRepo

private Curriculum createCurriculum(CurriculumDTO curriculumDTO, Study study) {
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
return Curriculum.builder()
.study(study)
.week(curriculumDTO.getWeek())
.subject(curriculumDTO.getSubject())
.build();
.study(study)
.week(curriculumDTO.getWeek())
.subject(curriculumDTO.getSubject())
.build();
}

private CurriculumDTO curriculumEntityToDTO(Curriculum curriculum) {
return CurriculumDTO.builder()
.week(curriculum.getWeek())
.subject(curriculum.getSubject())
.build();
.week(curriculum.getWeek())
.subject(curriculum.getSubject())
.build();
}

private DayDTO dayEntityToDTO(Day day) {
return DayDTO.builder()
.day(day.getDay())
.startTime(day.getStartTime())
.build();
return DayDTO.builder().day(day.getDay()).startTime(day.getStartTime()).build();
}

private Day createDay(DayDTO dayDTO, Study study) {
return Day.builder()
.study(study)
.day(dayDTO.getDay())
.startTime(dayDTO.getStartTime())
.build();
return Day.builder().study(study).day(dayDTO.getDay()).startTime(dayDTO.getStartTime()).build();
}

/**
@@ -129,32 +120,34 @@ public List<StudyListResponse> getStudyList() {
* @return 스터디 정보 반환
*/
public StudyDetailResponse getStudyDetail(Long studyId) {
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Optional<Study> study = studyRepository.findById(studyId);
Optional<Study> existingStudy = studyRepository.findById(studyId);

if (existingStudy.isPresent()) { // 해당 아이디를 가진 스터디가 존재할 때
Study study = existingStudy.get();

if (study.isPresent()) { // 해당 아이디를 가진 스터디가 존재할 때
StudyDetailResponse detailResponse =
StudyDetailResponse.builder()
.id(studyId)
.name(study.get().getName())
.description(study.get().getDescription())
.requirement(study.get().getRequirement())
.question(study.get().getQuestion())
.name(study.getName())
.description(study.getDescription())
.requirement(study.getRequirement())
.question(study.getQuestion())
.curriculums(new ArrayList<>())
.days(new ArrayList<>())
.maxParticipants(study.get().getMaxParticipants())
.isApplicationClosed(study.get().getIsApplicationClosed())
.maxParticipants(study.getMaxParticipants())
.isApplicationClosed(study.getIsApplicationClosed())
.build();

// curriculum이 있다면 curriculumDTO로 변환해 response에 추가
if (study.get().getCurriculums() != null) {
for (Curriculum curriculum : study.get().getCurriculums()) {
if (study.getCurriculums() != null) {
for (Curriculum curriculum : study.getCurriculums()) {
detailResponse.getCurriculums().add(curriculumEntityToDTO(curriculum));
}
}

// day가 있다면 dayDTO로 변환해 response에 추가
if (study.get().getDays() != null) {
for (Day day : study.get().getDays()) {
if (study.getDays() != null) {
for (Day day : study.getDays()) {
detailResponse.getDays().add(dayEntityToDTO(day));
}
}
@@ -164,6 +157,44 @@ public StudyDetailResponse getStudyDetail(Long studyId) {
return null;
}

public Long updateStudy(Long studyId, StudyCreateRequest updateRequest) {
Optional<Study> study = studyRepository.findById(studyId);

if (study.isEmpty()) {}

Study existingStudy = studyRepository.findById(studyId).get();
Study updatedStudy =
Study.builder()
.id(existingStudy.getId())
.name(existingStudy.getName())
.description(existingStudy.getDescription())
.requirement(existingStudy.getRequirement())
.question(existingStudy.getQuestion())
.curriculums(new ArrayList<>())
.days(new ArrayList<>())
.maxParticipants(existingStudy.getMaxParticipants())
.isApplicationClosed(existingStudy.getIsApplicationClosed())
.build();

// 등록된 커리큘럼이 있다면 엔티티로 변환하여 스터디에 추가
if (updateRequest.getCurriculums() != null) {
for (CurriculumDTO curriculumDTO : updateRequest.getCurriculums()) {
updatedStudy.getCurriculums().add(createCurriculum(curriculumDTO, updatedStudy));
}
}

// 등록된 스터디 날짜가 있다면 엔티티로 변환하여 스터디에 추가
if (updatedStudy.getDays() != null) {
for (DayDTO dayDTO : updateRequest.getDays()) {
updatedStudy.getDays().add(createDay(dayDTO, updatedStudy));
}
}

studyRepository.save(updatedStudy);

return updatedStudy.getId();
}

/**
* 스터디장 권한 확인 필요 스터디를 삭제합니다
*