Skip to content

Commit

Permalink
feat: 출석과 출결 기록의 연관관계 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Youthhing committed Sep 13, 2024
1 parent 96e52f9 commit 1fbda5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public class AttendanceRecord extends BaseTimeEntity {
@Column(name = "member_id", nullable = false)
private Long memberId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "attendance_id")
private Attendance attendance;
@Column(name = "attendance_id", nullable = false)
private Long attendanceId;

@Column(name = "attend_time", nullable = false)
private LocalDateTime attendTime;
Expand All @@ -62,7 +61,7 @@ private AttendanceRecord(AttendanceType attendanceType, AttendanceResult attenda
this.attendanceResult = attendanceResult;
this.locationAccuracy = locationAccuracy;
this.memberId = memberId;
this.attendance = attendance;
this.attendanceId = attendance.getId();
this.attendTime = attendTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import java.util.List;
import java.util.Optional;
import org.cotato.csquiz.domain.attendance.entity.Attendance;
import org.cotato.csquiz.domain.attendance.entity.AttendanceRecord;
import org.cotato.csquiz.domain.attendance.enums.AttendanceType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface AttendanceRecordRepository extends JpaRepository<AttendanceRecord, Long> {
@Query("select a from AttendanceRecord a where a.attendance in :attendances")
List<AttendanceRecord> findAllByAttendanceIdsInQuery(@Param("attendances") List<Attendance> attendances);
@Query("select a from AttendanceRecord a where a.attendanceId in :attendanceIds")
List<AttendanceRecord> findAllByAttendanceIdsInQuery(@Param("attendanceIds") List<Long> attendanceIds);

boolean existsByAttendanceIdAndMemberIdAndAttendanceType(Long attendanceId, Long memberId, AttendanceType attendanceType);

Optional<AttendanceRecord> findByMemberIdAndAttendanceId(Long memberId, Long attendanceId);

@Query("select a from AttendanceRecord a where a.attendance.id in :attendanceIds and a.memberId = :memberId")
@Query("select a from AttendanceRecord a where a.attendanceId in :attendanceIds and a.memberId = :memberId")
List<AttendanceRecord> findAllByAttendanceIdsInQueryAndMemberId(@Param("attendanceIds") List<Long> attendanceIds, @Param("memberId") Long memberId);

List<AttendanceRecord> findAllByAttendanceId(Long attendanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ public class AttendanceRecordService {
private final SessionRepository sessionRepository;

public List<AttendanceRecordResponse> generateAttendanceResponses(List<Attendance> attendances) {
List<AttendanceRecord> records = attendanceRecordRepository.findAllByAttendanceIdsInQuery(
attendances);
List<Long> attendanceIds = attendances.stream()
.map(Attendance::getId)
.toList();

List<AttendanceRecord> records = attendanceRecordRepository.findAllByAttendanceIdsInQuery(attendanceIds);

Map<Long, List<AttendanceRecord>> recordsByMemberId = records.stream()
.collect(Collectors.groupingBy(AttendanceRecord::getMemberId));
Expand Down

0 comments on commit 1fbda5e

Please sign in to comment.