Skip to content

Commit

Permalink
Merge pull request #105 from MoDooS/main
Browse files Browse the repository at this point in the history
refactor : 스터디 생성 시 체크리스트 수정가능하게 변경
  • Loading branch information
xloyeon authored Aug 29, 2023
2 parents 15ea805 + 103c3ac commit d034458
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public MemberProfileResponse getMemberProfile(Member currentMember, Long memberI
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new ModoosException(ErrorCode.MEMBER_NOT_FOUND));

//기본정보와 랭킹, 점수
Long id = member.getId();
String nickname = member.getNickname();
String ranking = member.getRanking();
Long score = member.getScore();

//관심있게 보는 스터디 태그
List<Category> categoryList = heartService.findMostCommonCategoryForMember(member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public RecruitIdResponse changeRecruit(Member currentMember, Long recruitId, Cha
}

//스터디가 이미 생성된 모집공고면 삭제 불가능
if (study.getStatus() == StudyStatus.ONGOING) {
if (study.getStatus() == StudyStatus.ONGOING || study.getStatus() == StudyStatus.STUDY_END) {
throw new ModoosException(ErrorCode.STUDY_NOT_EDIT);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
package com.study.modoos.study.request;

import com.study.modoos.recruit.request.TodoRequest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CreateStudyRequest {
List<TodoRequest> checkList;
private Long id;

private LocalDate start_at;

private LocalDate end_at;

private LocalTime studyTime;

private LocalTime endTime;

private int period; //주기

private int total_turn; //총 회차

private int absent;

private int late;

private int out;
}
35 changes: 35 additions & 0 deletions src/main/java/com/study/modoos/study/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.study.modoos.member.repository.MemberRepository;
import com.study.modoos.participant.entity.Participant;
import com.study.modoos.participant.repository.ParticipantRepository;
import com.study.modoos.recruit.request.TodoRequest;
import com.study.modoos.recruit.response.RecruitIdResponse;
import com.study.modoos.recruit.response.TodoResponse;
import com.study.modoos.study.entity.*;
Expand Down Expand Up @@ -82,6 +83,40 @@ public RecruitIdResponse createStudy(Member currentMember, CreateStudyRequest re
request.getEndTime(), request.getPeriod(), request.getTotal_turn(),
request.getAbsent(), request.getLate(), request.getOut());
study.updateStatus(StudyStatus.ONGOING); //스터디 생성 완료 상태로 변경
//체크리스트 확인해서 update
List<TodoRequest> checkList = request.getCheckList();

List<Todo> todoList = todoRepository.findTodoByStudy(study);

//스터디에 연결된 todoList 확인
for (Todo todo : todoList) {
boolean flag = false;

for (TodoRequest todoRequest : checkList) {
if (todoRequest.getId() != null && todo.getId().equals(todoRequest.getId())) {
todo.setContent(todoRequest.getContent());
flag = true;
todoRepository.save(todo);
break;
}
}

//해당하는 값 없으면 삭제
if (!flag) {
todoRepository.delete(todo);
}
}

for (TodoRequest todoRequest : checkList) {
if (todoRequest.getId() == null) {
Todo todo = Todo.builder()
.study(study)
.content(todoRequest.getContent())
.build();
todoRepository.save(todo);
}
}

studyRepository.save(study);
return RecruitIdResponse.of(study);
}
Expand Down

0 comments on commit d034458

Please sign in to comment.