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

[WHAT-174] 공결 fix 완료 #83

Merged
merged 1 commit into from
Sep 26, 2023
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 @@ -20,7 +20,7 @@ public class ApplyOfficialAbsent {
private LocalDate absentDate;
private String absentIsAccepted;

@OneToOne
@ManyToOne
@JoinColumn(name = "schedule_id")
private Schedule schedule;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gdg/whatssue/entity/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void setIsChecked(Boolean checked) {
@JoinColumn(name = "club_id")
private Club club;

@OneToOne(mappedBy = "schedule")
private ApplyOfficialAbsent applyOfficialAbsent;
@OneToMany(mappedBy = "schedule")
private List<ApplyOfficialAbsent> applyOfficialAbsents;

@OneToMany(mappedBy = "schedule")
private List<AttendanceByUserBySchedule> attendanceByUserByScheduleList;
Expand Down
78 changes: 59 additions & 19 deletions src/main/java/gdg/whatssue/service/AbsentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand All @@ -44,29 +45,32 @@ public ResponseEntity getAbsentRequest() {

// applyOfficialAbsentList에서 AbsentListDto로 변환
List<AbsentListDto> absentListDtoList = scheduleList.stream()
.map(s -> {
ApplyOfficialAbsent a = s.getApplyOfficialAbsent();
if (a != null && a.getMember() != null) {
return AbsentListDto.builder()
.applyOfficialAbsentId(String.valueOf(a.getApplyOfficialAbsentId()))
.scheduleId(String.valueOf(s.getScheduleId()))
.scheduleTitle(s.getScheduleTitle())
.absentReason(a.getAbsentReason())
.absentDate(String.valueOf(a.getAbsentDate()))
.absentIsAccepted(a.getAbsentIsAccepted())
.memberId(String.valueOf(a.getMember().getMemberId()))
.memberName(a.getMember().getMemberName())
.memberNickName(a.getMember().getMemberNickName())
.memberEmail(a.getMember().getMemberEmail())
.memberPhone(a.getMember().getMemberPhone())
.build();
}
.flatMap(s -> s.getApplyOfficialAbsents().stream())
.map(a -> {
if (a.getMember() != null) {
return AbsentListDto.builder()
.applyOfficialAbsentId(String.valueOf(a.getApplyOfficialAbsentId()))
.scheduleId(String.valueOf(String.valueOf(a.getSchedule().getScheduleId())))
.scheduleTitle(a.getSchedule().getScheduleTitle())
.absentReason(a.getAbsentReason())
.absentDate(String.valueOf(a.getAbsentDate()))
.absentIsAccepted(a.getAbsentIsAccepted())
.memberId(String.valueOf(a.getMember().getMemberId()))
.memberName(a.getMember().getMemberName())
.memberNickName(a.getMember().getMemberNickName())
.memberEmail(a.getMember().getMemberEmail())
.memberPhone(a.getMember().getMemberPhone())
.build();
}

return null; // null인 객체는 건너뛰기
})
.filter(Objects::nonNull) // null인 객체 필터링
.collect(Collectors.toList());




return ResponseEntity.ok(absentListDtoList);

}
Expand Down Expand Up @@ -94,18 +98,52 @@ public ResponseEntity acceptAbsentRequest(Long absentId) {
else{
attendanceByUserBySchedule.changeAttendance("공결");
}
//공결 테이블에서 absentId에 해당하는 값 지우기
//삭제할 applyOfficalAbsent 가 Schedule 에 존재한다면 지우기
Iterator<ApplyOfficialAbsent> iterator = schedule.getApplyOfficialAbsents().iterator();
while(iterator.hasNext()){
ApplyOfficialAbsent applyOfficialAbsent1 = iterator.next();
if(applyOfficialAbsent1.getApplyOfficialAbsentId() == absentId){
iterator.remove();
}
}
applyOfficialAbsentRepository.delete(applyOfficialAbsent);



return ResponseEntity.ok().build();
}

public ResponseEntity refuseAbsentRequest(Long absentId) {
//공결 거절
ApplyOfficialAbsent applyOfficialAbsent = applyOfficialAbsentRepository.findById(absentId).orElse(null);
Schedule schedule = applyOfficialAbsent.getSchedule();
//Member와 Schedule 을 applyOfficialAbsent에서 가져옴
Member member = applyOfficialAbsent.getMember();
if(applyOfficialAbsent == null){
return ResponseEntity.badRequest().build();
}
String absentIsAccepted = "denied";
applyOfficialAbsent.AcceptAbsent(absentIsAccepted);
//공결 승인시 출석 테이블의 출석 여부를 공결로 변경
AttendanceByUserBySchedule attendanceByUserBySchedule = attendanceByUserByScheduleRepository.findByMemberAndSchedule(member, schedule);
//예외처리
if(attendanceByUserBySchedule == null){
return ResponseEntity.ok().build();
}
else{
attendanceByUserBySchedule.changeAttendance("결석");
}
//공결 테이블에서 absentId에 해당하는 값 지우기
//삭제할 applyOfficalAbsent 가 Schedule 에 존재한다면 지우기
Iterator<ApplyOfficialAbsent> iterator = schedule.getApplyOfficialAbsents().iterator();
while(iterator.hasNext()){
ApplyOfficialAbsent applyOfficialAbsent1 = iterator.next();
if(applyOfficialAbsent1.getApplyOfficialAbsentId() == absentId){
iterator.remove();
}
}
applyOfficialAbsentRepository.delete(applyOfficialAbsent);


return ResponseEntity.ok().build();
}

Expand Down Expand Up @@ -137,6 +175,8 @@ public ResponseEntity requestAbsent(Long scheduleId, AbsentRequestDto absentRequ
applyOfficialAbsent1.saveIsAccepted(absentIsAccepted);
applyOfficialAbsentRepository.save(applyOfficialAbsent1);



//ReponseEntity key:value 로 공결 id 리턴
return ResponseEntity.ok().body("absentId :"+applyOfficialAbsent1.getApplyOfficialAbsentId());

Expand Down
Loading