diff --git a/src/main/java/org/sopt/makers/operation/controller/web/AttendanceController.java b/src/main/java/org/sopt/makers/operation/controller/web/AttendanceController.java index 8c4250a7..e5432011 100644 --- a/src/main/java/org/sopt/makers/operation/controller/web/AttendanceController.java +++ b/src/main/java/org/sopt/makers/operation/controller/web/AttendanceController.java @@ -3,7 +3,7 @@ import static org.sopt.makers.operation.common.ResponseMessage.*; import org.sopt.makers.operation.common.ApiResponse; -import org.sopt.makers.operation.dto.attendance.AttendUpdateRequestDTO; +import org.sopt.makers.operation.dto.attendance.SubAttendanceUpdateRequestDTO; import org.sopt.makers.operation.entity.Part; import org.sopt.makers.operation.service.AttendanceService; import org.springframework.data.domain.Pageable; @@ -28,19 +28,19 @@ public class AttendanceController { @ApiOperation(value = "출석 상태 변경") @PatchMapping - public ResponseEntity updateAttendanceStatus(@RequestBody AttendUpdateRequestDTO requestDTO) { - val response = attendanceService.updateAttendanceStatus(requestDTO); + public ResponseEntity updateSubAttendance(@RequestBody SubAttendanceUpdateRequestDTO requestDTO) { + val response = attendanceService.updateSubAttendance(requestDTO); return ResponseEntity.ok(ApiResponse.success(SUCCESS_UPDATE_ATTENDANCE_STATUS.getMessage(), response)); } - @ApiOperation(value = "유저별 출석 정보 조회") + @ApiOperation(value = "회원별 출석 정보 조회") @GetMapping("/{memberId}") public ResponseEntity findAttendancesByMember(@PathVariable Long memberId) { val response = attendanceService.findAttendancesByMember(memberId); return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_MEMBER_ATTENDANCE.getMessage(), response)); } - @ApiOperation(value = "출석 점수 갱신 성공") + @ApiOperation(value = "출석 점수 갱신") @PatchMapping("/member/{memberId}") public ResponseEntity updateMemberScore(@PathVariable Long memberId) { val response = attendanceService.updateMemberScore(memberId); diff --git a/src/main/java/org/sopt/makers/operation/dto/attendance/AttendUpdateRequestDTO.java b/src/main/java/org/sopt/makers/operation/dto/attendance/AttendUpdateRequestDTO.java deleted file mode 100644 index c45cf6ec..00000000 --- a/src/main/java/org/sopt/makers/operation/dto/attendance/AttendUpdateRequestDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sopt.makers.operation.dto.attendance; - -import org.sopt.makers.operation.entity.AttendanceStatus; -import org.sopt.makers.operation.entity.lecture.Attribute; - -public record AttendUpdateRequestDTO( - Long subAttendanceId, - AttendanceStatus status, - Attribute attribute -) { -} diff --git a/src/main/java/org/sopt/makers/operation/dto/attendance/AttendanceMemberResponseDTO.java b/src/main/java/org/sopt/makers/operation/dto/attendance/AttendanceMemberResponseDTO.java index 4c284455..ed0909b9 100644 --- a/src/main/java/org/sopt/makers/operation/dto/attendance/AttendanceMemberResponseDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/attendance/AttendanceMemberResponseDTO.java @@ -1,7 +1,5 @@ package org.sopt.makers.operation.dto.attendance; -import static org.sopt.makers.operation.util.Generation32.*; - import java.util.List; import org.sopt.makers.operation.entity.Attendance; @@ -36,7 +34,7 @@ record LectureVO( public static LectureVO of(Attendance attendance) { return new LectureVO( attendance.getLecture().getName(), - getUpdateScore(attendance.getLecture().getAttribute(), attendance.getStatus()), + attendance.getScore(), attendance.getStatus().getName(), attendance.getSubAttendances().stream().map(AttendanceVO::of).toList()); } diff --git a/src/main/java/org/sopt/makers/operation/dto/attendance/MemberResponseDTO.java b/src/main/java/org/sopt/makers/operation/dto/attendance/MemberResponseDTO.java index 242243f1..6921ec3b 100644 --- a/src/main/java/org/sopt/makers/operation/dto/attendance/MemberResponseDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/attendance/MemberResponseDTO.java @@ -1,9 +1,5 @@ package org.sopt.makers.operation.dto.attendance; -import static org.sopt.makers.operation.util.Generation32.*; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.List; import org.sopt.makers.operation.entity.Attendance; @@ -15,14 +11,15 @@ public record MemberResponseDTO ( Long attendanceId, MemberVO member, List attendances, - float updatedScore) { + float updatedScore +) { public static MemberResponseDTO of(Attendance attendance) { return new MemberResponseDTO( attendance.getId(), MemberVO.of(attendance.getMember()), attendance.getSubAttendances().stream().map(SubAttendanceVO::of).toList(), - getUpdateScore(attendance.getLecture().getAttribute(), attendance.getStatus())); + attendance.getScore()); } } diff --git a/src/main/java/org/sopt/makers/operation/dto/attendance/SubAttendanceUpdateRequestDTO.java b/src/main/java/org/sopt/makers/operation/dto/attendance/SubAttendanceUpdateRequestDTO.java new file mode 100644 index 00000000..ba430b0d --- /dev/null +++ b/src/main/java/org/sopt/makers/operation/dto/attendance/SubAttendanceUpdateRequestDTO.java @@ -0,0 +1,9 @@ +package org.sopt.makers.operation.dto.attendance; + +import org.sopt.makers.operation.entity.AttendanceStatus; + +public record SubAttendanceUpdateRequestDTO( + Long subAttendanceId, + AttendanceStatus status +) { +} diff --git a/src/main/java/org/sopt/makers/operation/dto/attendance/AttendUpdateResponseDTO.java b/src/main/java/org/sopt/makers/operation/dto/attendance/SubAttendanceUpdateResponseDTO.java similarity index 50% rename from src/main/java/org/sopt/makers/operation/dto/attendance/AttendUpdateResponseDTO.java rename to src/main/java/org/sopt/makers/operation/dto/attendance/SubAttendanceUpdateResponseDTO.java index 630db03d..482b529a 100644 --- a/src/main/java/org/sopt/makers/operation/dto/attendance/AttendUpdateResponseDTO.java +++ b/src/main/java/org/sopt/makers/operation/dto/attendance/SubAttendanceUpdateResponseDTO.java @@ -3,11 +3,11 @@ import org.sopt.makers.operation.entity.AttendanceStatus; import org.sopt.makers.operation.entity.SubAttendance; -public record AttendUpdateResponseDTO( +public record SubAttendanceUpdateResponseDTO( Long subAttendanceId, AttendanceStatus status ) { - public static AttendUpdateResponseDTO of(SubAttendance subAttendance) { - return new AttendUpdateResponseDTO(subAttendance.getId(), subAttendance.getStatus()); + public static SubAttendanceUpdateResponseDTO of(SubAttendance subAttendance) { + return new SubAttendanceUpdateResponseDTO(subAttendance.getId(), subAttendance.getStatus()); } } diff --git a/src/main/java/org/sopt/makers/operation/entity/Attendance.java b/src/main/java/org/sopt/makers/operation/entity/Attendance.java index a029bad5..7539f0f4 100644 --- a/src/main/java/org/sopt/makers/operation/entity/Attendance.java +++ b/src/main/java/org/sopt/makers/operation/entity/Attendance.java @@ -1,6 +1,8 @@ package org.sopt.makers.operation.entity; import static javax.persistence.GenerationType.*; +import static org.sopt.makers.operation.common.ExceptionMessage.*; +import static org.sopt.makers.operation.entity.AttendanceStatus.*; import java.util.ArrayList; import java.util.List; @@ -8,6 +10,7 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EntityNotFoundException; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.FetchType; @@ -19,8 +22,7 @@ import org.sopt.makers.operation.entity.lecture.Lecture; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Entity @NoArgsConstructor @@ -51,8 +53,49 @@ public Attendance(Member member, Lecture lecture) { this.status = AttendanceStatus.ABSENT; } - public void updateStatus(AttendanceStatus status) { - this.status = status; + public void updateStatus() { + this.status = getStatus(); + } + + public AttendanceStatus getStatus() { + val first = getSubAttendanceByRound(1); + val second = getSubAttendanceByRound(2); + return switch (this.lecture.getAttribute()) { + case SEMINAR -> second.getStatus().equals(ATTENDANCE) + ? first.getStatus().equals(ATTENDANCE) ? ATTENDANCE : TARDY + : ABSENT; + case EVENT -> second.getStatus().equals(ATTENDANCE) ? ATTENDANCE : ABSENT; + case ETC -> second.getStatus().equals(ATTENDANCE) ? PARTICIPATE : NOT_PARTICIPATE; + }; + } + + public float getScore() { + return switch (this.lecture.getAttribute()) { + case SEMINAR -> { + if (this.status.equals(ABSENT)) { + yield -1f; + } else if (this.status.equals(TARDY)) { + yield -0.5f; + } else { + yield 0f; + } + } + case EVENT -> this.status.equals(ATTENDANCE) ? 0.5f : 0f; + default -> 0f; + }; + } + + public void updateMemberScore() { + this.member.updateScore(this.getScore()); + } + + public void revertMemberScore() { + this.member.updateScore((-1) * this.getScore()); + } + + private SubAttendance getSubAttendanceByRound(int round) { + return this.subAttendances.stream().filter(o -> o.getSubLecture().getRound() == round).findFirst() + .orElseThrow(() -> new EntityNotFoundException(INVALID_SUB_ATTENDANCE.getName())); } private void setMember(Member member) { diff --git a/src/main/java/org/sopt/makers/operation/entity/Member.java b/src/main/java/org/sopt/makers/operation/entity/Member.java index 08725fae..e0b3de09 100644 --- a/src/main/java/org/sopt/makers/operation/entity/Member.java +++ b/src/main/java/org/sopt/makers/operation/entity/Member.java @@ -1,7 +1,6 @@ package org.sopt.makers.operation.entity; import static org.sopt.makers.operation.entity.lecture.LectureStatus.*; -import static org.sopt.makers.operation.util.Generation32.*; import java.util.ArrayList; import java.util.List; @@ -68,12 +67,8 @@ public void updateScore(float score) { public void updateTotalScore() { this.score = (float) (2 + this.attendances.stream() - .mapToDouble(attendance -> { - Lecture lecture = attendance.getLecture(); - return lecture.getLectureStatus().equals(END) - ? getUpdateScore(lecture.getAttribute(), attendance.getStatus()) - : 0; - }) + .filter(attendance -> attendance.getLecture().getLectureStatus().equals(END)) + .mapToDouble(Attendance::getScore) .sum()); } } diff --git a/src/main/java/org/sopt/makers/operation/entity/SubAttendance.java b/src/main/java/org/sopt/makers/operation/entity/SubAttendance.java index 44560443..0099b00d 100644 --- a/src/main/java/org/sopt/makers/operation/entity/SubAttendance.java +++ b/src/main/java/org/sopt/makers/operation/entity/SubAttendance.java @@ -61,5 +61,6 @@ private void setSubLecture(SubLecture subLecture) { public void updateStatus(AttendanceStatus status) { this.status = status; + this.attendance.updateStatus(); } } diff --git a/src/main/java/org/sopt/makers/operation/entity/lecture/Lecture.java b/src/main/java/org/sopt/makers/operation/entity/lecture/Lecture.java index 96bb92dc..29201733 100644 --- a/src/main/java/org/sopt/makers/operation/entity/lecture/Lecture.java +++ b/src/main/java/org/sopt/makers/operation/entity/lecture/Lecture.java @@ -1,7 +1,6 @@ package org.sopt.makers.operation.entity.lecture; import static javax.persistence.GenerationType.*; -import static org.sopt.makers.operation.util.Generation32.*; import java.time.LocalDateTime; import java.util.ArrayList; @@ -16,7 +15,6 @@ import javax.persistence.OneToMany; import org.sopt.makers.operation.entity.Attendance; -import org.sopt.makers.operation.entity.AttendanceStatus; import org.sopt.makers.operation.entity.BaseEntity; import org.sopt.makers.operation.entity.Part; import org.sopt.makers.operation.entity.SubLecture; @@ -78,12 +76,6 @@ public void updateStatus(LectureStatus status) { public void finish() { this.lectureStatus = LectureStatus.END; - attendances.forEach(this::updateScore); - } - - private void updateScore(Attendance attendance) { - Attribute attribute = this.attribute; - AttendanceStatus status = attendance.getStatus(); - attendance.getMember().updateScore(getUpdateScore(attribute, status)); + attendances.forEach(Attendance::updateMemberScore); } } diff --git a/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceCustomRepository.java b/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceCustomRepository.java index bb76f066..6204b952 100644 --- a/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceCustomRepository.java +++ b/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceCustomRepository.java @@ -1,9 +1,9 @@ package org.sopt.makers.operation.repository.attendance; import java.util.List; -import java.util.Optional; import org.sopt.makers.operation.entity.Attendance; +import org.sopt.makers.operation.entity.Member; import org.sopt.makers.operation.entity.Part; import org.sopt.makers.operation.entity.SubAttendance; import org.sopt.makers.operation.entity.lecture.Lecture; @@ -11,10 +11,8 @@ public interface AttendanceCustomRepository { List findAttendanceByMemberId(Long memberId); - List findAttendancesByLecture(Long lectureId, Part part, Pageable pageable); - List findAttendancesByMember(Long memberId); - Optional findAttendanceBySubAttendance(SubAttendance subAttendance); - List findByLecture(Lecture lecture); + List findByLecture(Long lectureId, Part part, Pageable pageable); + List findByMember(Member member); List findCurrentAttendanceByMember(Long playGroundId); List findSubAttendanceByAttendanceId(Long attendanceId); } diff --git a/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java b/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java index 8591ff8b..a0fd92e3 100644 --- a/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java +++ b/src/main/java/org/sopt/makers/operation/repository/attendance/AttendanceRepositoryImpl.java @@ -10,16 +10,14 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; -import java.util.Optional; import lombok.val; import org.sopt.makers.operation.config.GenerationConfig; import org.sopt.makers.operation.entity.Attendance; +import org.sopt.makers.operation.entity.Member; import org.sopt.makers.operation.entity.Part; -import org.sopt.makers.operation.entity.QSubAttendance; import org.sopt.makers.operation.entity.SubAttendance; -import org.sopt.makers.operation.entity.lecture.Lecture; import org.sopt.makers.operation.entity.lecture.LectureStatus; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; @@ -52,14 +50,13 @@ public List findAttendanceByMemberId(Long memberId) { } @Override - public List findAttendancesByLecture(Long lectureId, Part part, Pageable pageable) { + public List findByLecture(Long lectureId, Part part, Pageable pageable) { return queryFactory - .select(attendance) - .from(attendance) - .join(attendance.subAttendances, subAttendance).fetchJoin() - .join(subAttendance.subLecture, subLecture).fetchJoin() - .join(attendance.lecture, lecture).fetchJoin() - .join(attendance.member, member).fetchJoin().distinct() + .selectFrom(attendance) + .leftJoin(attendance.subAttendances, subAttendance).fetchJoin().distinct() + .leftJoin(subAttendance.subLecture, subLecture).fetchJoin() + .leftJoin(attendance.lecture, lecture).fetchJoin() + .leftJoin(attendance.member, member).fetchJoin().distinct() .where( attendance.lecture.id.eq(lectureId), partEq(part) @@ -71,39 +68,17 @@ public List findAttendancesByLecture(Long lectureId, Part part, Page } @Override - public List findAttendancesByMember(Long memberId) { + public List findByMember(Member member) { return queryFactory - .select(attendance) - .from(attendance) + .selectFrom(attendance) .leftJoin(attendance.subAttendances, subAttendance).fetchJoin().distinct() .leftJoin(attendance.lecture, lecture).fetchJoin() .leftJoin(subAttendance.subLecture, subLecture).fetchJoin() - .where(attendance.member.id.eq(memberId)) + .where(attendance.member.eq(member)) .orderBy(lecture.startDate.desc()) .fetch(); } - @Override - public Optional findAttendanceBySubAttendance(SubAttendance subAttendance) { - return queryFactory - .select(attendance) - .from(attendance) - .join(attendance.subAttendances, QSubAttendance.subAttendance).fetchJoin() - .join(QSubAttendance.subAttendance.subLecture, subLecture).fetchJoin() - .where(attendance.subAttendances.contains(subAttendance)) - .stream().findFirst(); - } - - @Override - public List findByLecture(Lecture lecture) { - return queryFactory - .select(attendance) - .from(attendance) - .leftJoin(attendance.member, member).fetchJoin().distinct() - .where(attendance.lecture.eq(lecture)) - .fetch(); - } - @Override public List findCurrentAttendanceByMember(Long playGroundId) { val now = LocalDateTime.now(); diff --git a/src/main/java/org/sopt/makers/operation/repository/lecture/LectureCustomRepository.java b/src/main/java/org/sopt/makers/operation/repository/lecture/LectureCustomRepository.java index d2055f05..b17ca536 100644 --- a/src/main/java/org/sopt/makers/operation/repository/lecture/LectureCustomRepository.java +++ b/src/main/java/org/sopt/makers/operation/repository/lecture/LectureCustomRepository.java @@ -3,8 +3,10 @@ import org.sopt.makers.operation.entity.Part; import org.sopt.makers.operation.entity.lecture.Lecture; import java.util.List; +import java.util.Optional; public interface LectureCustomRepository { List findLectures(int generation, Part part); List findLecturesToBeEnd(); + Optional find(Long lectureId); } diff --git a/src/main/java/org/sopt/makers/operation/repository/lecture/LectureRepositoryImpl.java b/src/main/java/org/sopt/makers/operation/repository/lecture/LectureRepositoryImpl.java index 6be84ec8..85772ee1 100644 --- a/src/main/java/org/sopt/makers/operation/repository/lecture/LectureRepositoryImpl.java +++ b/src/main/java/org/sopt/makers/operation/repository/lecture/LectureRepositoryImpl.java @@ -9,6 +9,7 @@ import java.time.LocalDateTime; import java.util.List; +import java.util.Optional; import static java.util.Objects.*; import static org.sopt.makers.operation.entity.QAttendance.*; @@ -46,6 +47,16 @@ public List findLecturesToBeEnd() { .fetch(); } + @Override + public Optional find(Long lectureId) { + return queryFactory + .selectFrom(lecture) + .leftJoin(lecture.attendances, attendance).fetchJoin().distinct() + .leftJoin(attendance.member, member).fetchJoin().distinct() + .where(lecture.id.eq(lectureId)) + .stream().findFirst(); + } + private BooleanExpression partEq(Part part) { return nonNull(part) ? lecture.part.eq(part) : null; } diff --git a/src/main/java/org/sopt/makers/operation/repository/member/MemberCustomRepository.java b/src/main/java/org/sopt/makers/operation/repository/member/MemberCustomRepository.java index 9168564f..43884ef8 100644 --- a/src/main/java/org/sopt/makers/operation/repository/member/MemberCustomRepository.java +++ b/src/main/java/org/sopt/makers/operation/repository/member/MemberCustomRepository.java @@ -10,5 +10,5 @@ public interface MemberCustomRepository { List search(MemberSearchCondition condition, Pageable pageable); List search(MemberSearchCondition condition); - Optional findMemberByIdFetchJoinAttendances(Long memberId); + Optional find(Long memberId); } diff --git a/src/main/java/org/sopt/makers/operation/repository/member/MemberRepositoryImpl.java b/src/main/java/org/sopt/makers/operation/repository/member/MemberRepositoryImpl.java index a8195354..6d5dce7b 100644 --- a/src/main/java/org/sopt/makers/operation/repository/member/MemberRepositoryImpl.java +++ b/src/main/java/org/sopt/makers/operation/repository/member/MemberRepositoryImpl.java @@ -3,6 +3,7 @@ import static java.util.Objects.*; import static org.sopt.makers.operation.entity.QAttendance.*; import static org.sopt.makers.operation.entity.QMember.*; +import static org.sopt.makers.operation.entity.lecture.QLecture.*; import java.util.List; import java.util.Optional; @@ -12,7 +13,6 @@ import org.sopt.makers.operation.dto.member.MemberSearchCondition; import org.sopt.makers.operation.entity.Member; import org.sopt.makers.operation.entity.Part; -import org.sopt.makers.operation.entity.lecture.QLecture; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; @@ -58,12 +58,11 @@ public List search(MemberSearchCondition condition) { } @Override - public Optional findMemberByIdFetchJoinAttendances(Long memberId) { + public Optional find(Long memberId) { return queryFactory - .select(member) - .from(member) + .selectFrom(member) .join(member.attendances, attendance).fetchJoin().distinct() - .join(attendance.lecture, QLecture.lecture).fetchJoin() + .join(attendance.lecture, lecture).fetchJoin() .where(member.id.eq(memberId)) .stream().findFirst(); } diff --git a/src/main/java/org/sopt/makers/operation/service/AttendanceService.java b/src/main/java/org/sopt/makers/operation/service/AttendanceService.java index 54007815..683f6689 100644 --- a/src/main/java/org/sopt/makers/operation/service/AttendanceService.java +++ b/src/main/java/org/sopt/makers/operation/service/AttendanceService.java @@ -3,15 +3,15 @@ import java.util.List; import org.sopt.makers.operation.dto.attendance.AttendanceMemberResponseDTO; -import org.sopt.makers.operation.dto.attendance.AttendUpdateRequestDTO; -import org.sopt.makers.operation.dto.attendance.AttendUpdateResponseDTO; +import org.sopt.makers.operation.dto.attendance.SubAttendanceUpdateRequestDTO; +import org.sopt.makers.operation.dto.attendance.SubAttendanceUpdateResponseDTO; import org.sopt.makers.operation.dto.attendance.MemberResponseDTO; import org.sopt.makers.operation.entity.Part; import org.springframework.data.domain.Pageable; import org.sopt.makers.operation.dto.attendance.*; public interface AttendanceService { - AttendUpdateResponseDTO updateAttendanceStatus(AttendUpdateRequestDTO requestDTO); + SubAttendanceUpdateResponseDTO updateSubAttendance(SubAttendanceUpdateRequestDTO requestDTO); AttendanceMemberResponseDTO findAttendancesByMember(Long memberId); float updateMemberScore(Long memberId); List findAttendancesByLecture(Long lectureId, Part part, Pageable pageable); diff --git a/src/main/java/org/sopt/makers/operation/service/AttendanceServiceImpl.java b/src/main/java/org/sopt/makers/operation/service/AttendanceServiceImpl.java index 32de464a..b1416ba4 100644 --- a/src/main/java/org/sopt/makers/operation/service/AttendanceServiceImpl.java +++ b/src/main/java/org/sopt/makers/operation/service/AttendanceServiceImpl.java @@ -2,13 +2,12 @@ import static java.util.Objects.nonNull; import static org.sopt.makers.operation.common.ExceptionMessage.*; -import static org.sopt.makers.operation.util.Generation32.*; import java.util.List; import org.sopt.makers.operation.dto.attendance.AttendanceMemberResponseDTO; -import org.sopt.makers.operation.dto.attendance.AttendUpdateRequestDTO; -import org.sopt.makers.operation.dto.attendance.AttendUpdateResponseDTO; +import org.sopt.makers.operation.dto.attendance.SubAttendanceUpdateRequestDTO; +import org.sopt.makers.operation.dto.attendance.SubAttendanceUpdateResponseDTO; import org.sopt.makers.operation.dto.attendance.MemberResponseDTO; import lombok.val; import org.sopt.makers.operation.dto.attendance.*; @@ -47,26 +46,23 @@ public class AttendanceServiceImpl implements AttendanceService { @Override @Transactional - public AttendUpdateResponseDTO updateAttendanceStatus(AttendUpdateRequestDTO requestDTO) { + public SubAttendanceUpdateResponseDTO updateSubAttendance(SubAttendanceUpdateRequestDTO requestDTO) { val subAttendance = findSubAttendance(requestDTO.subAttendanceId()); - val attendance = attendanceRepository.findAttendanceBySubAttendance(subAttendance) - .orElseThrow(() -> new LectureException(INVALID_ATTENDANCE.getName())); subAttendance.updateStatus(requestDTO.status()); - attendance.updateStatus(getAttendanceStatus(requestDTO.attribute(), attendance.getSubAttendances())); - return AttendUpdateResponseDTO.of(subAttendance); + return SubAttendanceUpdateResponseDTO.of(subAttendance); } @Override public AttendanceMemberResponseDTO findAttendancesByMember(Long memberId) { val member = findMember(memberId); - val attendances = attendanceRepository.findAttendancesByMember(memberId); + val attendances = attendanceRepository.findByMember(member); return AttendanceMemberResponseDTO.of(member, attendances); } @Override @Transactional public float updateMemberScore(Long memberId) { - Member member = memberRepository.findMemberByIdFetchJoinAttendances(memberId) + Member member = memberRepository.find(memberId) .orElseThrow(() -> new MemberException(INVALID_MEMBER.getName())); member.updateTotalScore(); return member.getScore(); @@ -74,7 +70,7 @@ public float updateMemberScore(Long memberId) { @Override public List findAttendancesByLecture(Long lectureId, Part part, Pageable pageable) { - val attendances = attendanceRepository.findAttendancesByLecture(lectureId, part, pageable); + val attendances = attendanceRepository.findByLecture(lectureId, part, pageable); return attendances.stream().map(MemberResponseDTO::of).toList(); } @@ -120,7 +116,7 @@ public AttendResponseDTO attend(Long playGroundId, AttendRequestDTO requestDTO) currentRoundSubAttendance.updateStatus(AttendanceStatus.ATTENDANCE); - attendance.updateStatus(getAttendanceStatus(attendance.getLecture().getAttribute(), attendance.getSubAttendances())); + attendance.updateStatus(); return AttendResponseDTO.of(subLecture.getId()); } diff --git a/src/main/java/org/sopt/makers/operation/service/LectureServiceImpl.java b/src/main/java/org/sopt/makers/operation/service/LectureServiceImpl.java index 93ba3751..d6c93891 100644 --- a/src/main/java/org/sopt/makers/operation/service/LectureServiceImpl.java +++ b/src/main/java/org/sopt/makers/operation/service/LectureServiceImpl.java @@ -3,8 +3,8 @@ import static java.util.Objects.nonNull; import static org.sopt.makers.operation.common.ExceptionMessage.*; import static org.sopt.makers.operation.entity.AttendanceStatus.*; +import static org.sopt.makers.operation.entity.Part.*; import static org.sopt.makers.operation.entity.lecture.LectureStatus.*; -import static org.sopt.makers.operation.util.Generation32.*; import java.time.LocalDateTime; import java.time.LocalTime; @@ -235,21 +235,19 @@ public LectureCurrentRoundResponseDTO getCurrentLectureRound(Long lectureId) { @Override @Transactional public void deleteLecture(Long lectureId) { - Lecture lecture = findLecture(lectureId); + val lecture = lectureRepository.find(lectureId) + .orElseThrow(() -> new LectureException(INVALID_LECTURE.getName())); + + // 출석 종료된 세션: 출석 점수 갱신 전으로 복구 if (lecture.getLectureStatus().equals(END)) { - revertMemberScore(lecture); + lecture.getAttendances().forEach(Attendance::revertMemberScore); } + + // 연관 관계의 객체 삭제 후 세션 삭제 subAttendanceRepository.deleteAllBySubLectureIn(lecture.getSubLectures()); subLectureRepository.deleteAllByLecture(lecture); attendanceRepository.deleteAllByLecture(lecture); - lectureRepository.deleteById(lectureId); - } - - private void revertMemberScore(Lecture lecture) { - attendanceRepository.findByLecture(lecture).forEach(attendance -> { - float score = getUpdateScore(lecture.getAttribute(), attendance.getStatus()); - attendance.getMember().updateScore((-1) * score); - }); + lectureRepository.delete(lecture); } @Override @@ -260,7 +258,7 @@ public LectureDetailResponseDTO getLectureDetail(Long lectureId) { private MemberSearchCondition getMemberSearchCondition(LectureRequestDTO requestDTO) { return new MemberSearchCondition( - requestDTO.part() != Part.ALL ? requestDTO.part() : null, + !requestDTO.part().equals(ALL) ? requestDTO.part() : null, requestDTO.generation() ); } diff --git a/src/main/java/org/sopt/makers/operation/util/Generation32.java b/src/main/java/org/sopt/makers/operation/util/Generation32.java deleted file mode 100644 index 616c66d5..00000000 --- a/src/main/java/org/sopt/makers/operation/util/Generation32.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.sopt.makers.operation.util; - -import static org.sopt.makers.operation.entity.AttendanceStatus.*; - -import java.util.List; - -import org.sopt.makers.operation.entity.AttendanceStatus; -import org.sopt.makers.operation.entity.SubAttendance; -import org.sopt.makers.operation.entity.lecture.Attribute; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class Generation32 { - - public static float getUpdateScore(Attribute attribute, AttendanceStatus status) { - return switch (attribute) { - case SEMINAR -> getUpdateScoreInSeminar(status); - case EVENT -> getUpdateScoreInEvent(status); - default -> 0; - }; - } - - private static float getUpdateScoreInSeminar(AttendanceStatus status) { - return switch (status) { - case TARDY -> -0.5f; - case ABSENT -> -1f; - default -> 0f; - }; - } - - private static float getUpdateScoreInEvent(AttendanceStatus status) { - if (status.equals(ATTENDANCE)) { - return 0.5f; - } - return 0; - } - - public static AttendanceStatus getAttendanceStatus(Attribute attribute, List subAttendances) { - int firstRound = subAttendances.get(0).getSubLecture().getRound() == 1 ? 0 : 1; - SubAttendance first = subAttendances.get(firstRound); - SubAttendance second = subAttendances.get(1 - firstRound); - return switch (attribute) { - case SEMINAR -> getAttendanceStatusInSeminar(first, second); - case EVENT -> getAttendanceStatusInEvent(second); - case ETC -> getAttendanceStatusInEtc(second); - }; - } - - private static AttendanceStatus getAttendanceStatusInSeminar(SubAttendance first, SubAttendance second) { - if (first.getStatus().equals(ATTENDANCE) && second.getStatus().equals(ATTENDANCE)) { - return ATTENDANCE; - } else if (first.getStatus().equals(ABSENT) && second.getStatus().equals(ATTENDANCE)) { - return TARDY; - } - return ABSENT; - } - - private static AttendanceStatus getAttendanceStatusInEvent(SubAttendance second) { - if (second.getStatus().equals(ATTENDANCE)) { - return ATTENDANCE; - } - return ABSENT; - } - - private static AttendanceStatus getAttendanceStatusInEtc(SubAttendance second) { - if (second.getStatus().equals(ATTENDANCE)) { - return PARTICIPATE; - } - return NOT_PARTICIPATE; - } -}