Skip to content

Commit

Permalink
fix: 잘못된 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ybkang1108 committed Jan 24, 2025
1 parent 31ad47d commit 872757d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public void updateStudy(Long studyId, StudyCreateUpdateRequest request) {
studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND));

study.update(
request.name(),
request.description(),
request.requirement(),
request.question(),
request.maxParticipants(),
request.studyStatus(),
request.curriculums(),
request.days());
request.name(),
request.description(),
request.requirement(),
request.question(),
request.maxParticipants(),
request.studyStatus(),
request.curriculums(),
request.days());

studyRepository.save(study);
}
Expand Down
56 changes: 29 additions & 27 deletions src/main/java/com/gdgoc/study_group/study/domain/Study.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import com.gdgoc.study_group.day.domain.Day;
import com.gdgoc.study_group.day.dto.DayDTO;
import com.gdgoc.study_group.round.domain.Round;
import com.gdgoc.study_group.study.dto.StudyCreateUpdateRequest;
import com.gdgoc.study_group.studyMember.domain.StudyMember;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import lombok.*;

@Entity
Expand Down Expand Up @@ -64,34 +61,33 @@ public static Study create(
.question(question)
.maxParticipants(maxParticipants)
.studyStatus(status)
.isApplicationClosed(false)
.build();
}

public void addInfo(List<CurriculumDTO> curriculumDTOs, List<DayDTO> dayDTOs) {
// 등록된 커리큘럼이 있다면 엔티티로 변환하여 리스트에 추가
List<Curriculum> curriculums = curriculumDTOs.stream()
.map(curriculumDTO -> Curriculum.create(this, curriculumDTO.week(), curriculumDTO.subject()))
.toList();
this.curriculums =
curriculumDTOs.stream()
.map(
curriculumDTO ->
Curriculum.create(this, curriculumDTO.week(), curriculumDTO.subject()))
.toList();

// 등록된 스터디 날짜가 있다면 엔티티로 변환하여 리스트에 추가
List<Day> days = dayDTOs.stream()
.map(dayDTO -> Day.create(this, dayDTO.day(), dayDTO.startTime()))
.toList();


this.curriculums.addAll(curriculums);
this.days.addAll(days);
this.days =
dayDTOs.stream().map(dayDTO -> Day.create(this, dayDTO.day(), dayDTO.startTime())).toList();
}

public void update(
String name,
String description,
String requirement,
String question,
Integer maxParticipants,
StudyStatus studyStatus,
List<CurriculumDTO> curriculumDTOs,
List<DayDTO> dayDTOs) {
String name,
String description,
String requirement,
String question,
Integer maxParticipants,
StudyStatus studyStatus,
List<CurriculumDTO> curriculumDTOs,
List<DayDTO> dayDTOs) {
this.name = name;
this.description = description;
this.requirement = requirement;
Expand All @@ -100,13 +96,19 @@ public void update(
this.studyStatus = studyStatus;

this.getCurriculums().clear();
this.getCurriculums().addAll(curriculumDTOs.stream()
.map(curriculumDTO -> Curriculum.create(this, curriculumDTO.week(), curriculumDTO.subject()))
.toList());
this.getCurriculums()
.addAll(
curriculumDTOs.stream()
.map(
curriculumDTO ->
Curriculum.create(this, curriculumDTO.week(), curriculumDTO.subject()))
.toList());

this.getDays().clear();
this.getDays().addAll(dayDTOs.stream()
.map(dayDTO -> Day.create(this, dayDTO.day(), dayDTO.startTime()))
.toList());
this.getDays()
.addAll(
dayDTOs.stream()
.map(dayDTO -> Day.create(this, dayDTO.day(), dayDTO.startTime()))
.toList());
}
}

0 comments on commit 872757d

Please sign in to comment.