Skip to content

Commit

Permalink
�fix: 인증된 참여자의 방 나가기 후 방 정보 불러오기 안되는 버그 해결 (#221)
Browse files Browse the repository at this point in the history
* fix: 인증하고 나간 참여자 정보 불러오기

* fix: 인증된 방이 삭제되지 않는 버그 수정
  • Loading branch information
ymkim97 authored Dec 2, 2023
1 parent bd3fb6b commit cf650c4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public Certification findCertification(Long certificationId) {
.orElseThrow(() -> new NotFoundException(CERTIFICATION_NOT_FOUND));
}

public List<Certification> findCertifications(List<Routine> routines) {
return certificationsSearchRepository.findCertificationsByRoutines(routines);
}

public void deleteCertifications(List<Certification> certifications) {
certificationRepository.deleteAll(certifications);
}

private void validateCertifyTime(LocalDateTime now, int certifyTime) {
LocalTime targetTime = LocalTime.of(certifyTime, 0);
LocalDateTime targetDateTime = LocalDateTime.of(now.toLocalDate(), targetTime);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/moabam/api/application/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.moabam.api.domain.room.RoomType.*;
import static com.moabam.global.error.model.ErrorMessage.*;

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

import org.apache.commons.lang3.StringUtils;
Expand All @@ -14,10 +15,12 @@
import com.moabam.api.application.room.mapper.RoomMapper;
import com.moabam.api.application.room.mapper.RoutineMapper;
import com.moabam.api.domain.member.Member;
import com.moabam.api.domain.room.Certification;
import com.moabam.api.domain.room.Participant;
import com.moabam.api.domain.room.Room;
import com.moabam.api.domain.room.RoomType;
import com.moabam.api.domain.room.Routine;
import com.moabam.api.domain.room.repository.DailyMemberCertificationRepository;
import com.moabam.api.domain.room.repository.ParticipantRepository;
import com.moabam.api.domain.room.repository.ParticipantSearchRepository;
import com.moabam.api.domain.room.repository.RoomRepository;
Expand All @@ -43,6 +46,7 @@ public class RoomService {
private final RoutineRepository routineRepository;
private final ParticipantRepository participantRepository;
private final ParticipantSearchRepository participantSearchRepository;
private final DailyMemberCertificationRepository dailyMemberCertificationRepository;
private final CertificationService certificationService;
private final MemberService memberService;
private final ClockHolder clockHolder;
Expand Down Expand Up @@ -118,6 +122,9 @@ public void exitRoom(Long memberId, Long roomId) {
}

List<Routine> routines = routineRepository.findAllByRoomId(roomId);
List<Certification> certifications = certificationService.findCertifications(routines);

certificationService.deleteCertifications(certifications);
routineRepository.deleteAll(routines);
roomRepository.delete(room);
}
Expand Down Expand Up @@ -216,5 +223,10 @@ private void validateRoomExit(Participant participant, Room room) {
if (participant.isManager() && room.getCurrentUserCount() != 1) {
throw new BadRequestException(ROOM_EXIT_MANAGER_FAIL);
}

if (dailyMemberCertificationRepository.existsByMemberIdAndRoomIdAndCreatedAtBetween(participant.getMemberId(),
room.getId(), clockHolder.date().atStartOfDay(), clockHolder.date().atTime(LocalTime.MAX))) {
throw new BadRequestException(CERTIFIED_ROOM_EXIT_FAILED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private List<TodayCertificateRankResponse> getTodayCertificateRankResponses(Long

List<TodayCertificateRankResponse> responses = new ArrayList<>();
List<Certification> certifications = certificationsSearchRepository.findCertifications(roomId, date);
List<Participant> participants = participantSearchRepository.findParticipantsByRoomId(roomId);
List<Participant> participants = participantSearchRepository.findAllParticipantsByRoomId(roomId);
List<Member> members = memberService.getRoomMembers(participants.stream()
.map(Participant::getMemberId)
.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.moabam.api.domain.room.Certification;
import com.moabam.api.domain.room.DailyMemberCertification;
import com.moabam.api.domain.room.DailyRoomCertification;
import com.moabam.api.domain.room.Routine;
import com.querydsl.jpa.impl.JPAQueryFactory;

import jakarta.persistence.LockModeType;
Expand All @@ -35,6 +36,14 @@ public List<Certification> findCertifications(Long roomId, LocalDate date) {
.fetch();
}

public List<Certification> findCertificationsByRoutines(List<Routine> routines) {
return jpaQueryFactory.selectFrom(certification)
.where(
certification.routine.in(routines)
)
.fetch();
}

public Optional<DailyMemberCertification> findDailyMemberCertification(Long memberId, Long roomId, LocalDate date) {
return Optional.ofNullable(jpaQueryFactory
.selectFrom(dailyMemberCertification)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public List<Participant> findParticipantsByRoomId(Long roomId) {
.fetch();
}

public List<Participant> findAllParticipantsByRoomId(Long roomId) {
return jpaQueryFactory
.selectFrom(participant)
.where(
participant.room.id.eq(roomId)
)
.fetch();
}

public List<Participant> findNotDeletedParticipantsByMemberId(Long memberId) {
return jpaQueryFactory
.selectFrom(participant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum ErrorMessage {
PARTICIPANT_DEPORT_ERROR("방장은 자신을 추방할 수 없습니다."),
IMAGE_CONVERT_FAIL("이미지 변환을 실패했습니다."),
UNAVAILABLE_TO_CHANGE_CERTIFY_TIME("이미 한명 이상이 인증을 하면 인증 시간을 바꿀 수 없습니다."),
CERTIFIED_ROOM_EXIT_FAILED("오늘 인증한 방은 나갈 수 없습니다."),

LOGIN_FAILED("로그인에 실패했습니다."),
LOGIN_FAILED_ADMIN_KEY("어드민키가 달라요"),
Expand Down

0 comments on commit cf650c4

Please sign in to comment.