Skip to content

Commit

Permalink
refactor: 코드 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkim97 committed Nov 1, 2023
1 parent c299ac3 commit a0bacae
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/moabam/api/application/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.moabam.api.domain.entity.Room;
import com.moabam.api.domain.entity.Routine;
import com.moabam.api.domain.repository.ParticipantRepository;
import com.moabam.api.domain.repository.ParticipantSearchRepository;
import com.moabam.api.domain.repository.RoomRepository;
import com.moabam.api.domain.repository.RoutineRepository;
import com.moabam.api.dto.CreateRoomRequest;
Expand All @@ -29,6 +30,7 @@ public class RoomService {
private final RoomRepository roomRepository;
private final RoutineRepository routineRepository;
private final ParticipantRepository participantRepository;
private final ParticipantSearchRepository participantSearchRepository;

@Transactional
public void createRoom(Long memberId, CreateRoomRequest createRoomRequest) {
Expand All @@ -39,7 +41,6 @@ public void createRoom(Long memberId, CreateRoomRequest createRoomRequest) {
.memberId(memberId)
.build();
participant.enableManager();

roomRepository.save(room);
routineRepository.saveAll(routines);
participantRepository.save(participant);
Expand All @@ -48,7 +49,7 @@ public void createRoom(Long memberId, CreateRoomRequest createRoomRequest) {
@Transactional
public void modifyRoom(Long memberId, Long roomId, ModifyRoomRequest modifyRoomRequest) {
// TODO: 추후에 별도 메서드로 뺄듯
Participant participant = participantRepository.findParticipantByRoomIdAndMemberId(roomId, memberId)
Participant participant = participantSearchRepository.findParticipant(roomId, memberId)
.orElseThrow(() -> new NotFoundException(PARTICIPANT_NOT_FOUND));

if (!participant.isManager()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class Certification extends BaseTimeEntity {
private String image;

@Builder
private Certification(Routine routine, Long memberId, String image) {
private Certification(Long id, Routine routine, Long memberId, String image) {
this.id = id;
this.routine = requireNonNull(routine);
this.memberId = requireNonNull(memberId);
this.image = requireNonNull(image);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/moabam/api/domain/entity/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Entity
@Getter
@Table(name = "participant")
@SQLDelete(sql = "UPDATE participants SET deleted_at = CURRENT_TIMESTAMP where id = ?")
@SQLDelete(sql = "UPDATE participant SET deleted_at = CURRENT_TIMESTAMP where id = ?")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Participant {

Expand All @@ -49,7 +49,8 @@ public class Participant {
private LocalDateTime deletedAt;

@Builder
private Participant(Room room, Long memberId) {
private Participant(Long id, Room room, Long memberId) {
this.id = id;
this.room = requireNonNull(room);
this.memberId = requireNonNull(memberId);
this.isManager = false;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/moabam/api/domain/entity/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class Room extends BaseTimeEntity {
private static final String ROOM_LEVEL_0_IMAGE = "'temptemp'";
private static final String ROOM_LEVEL_10_IMAGE = "'temp'";
private static final String ROOM_LEVEL_20_IMAGE = "'tempp'";

private static final int MORNING_START_TIME = 4;
private static final int MORNING_END_TIME = 10;
private static final int NIGHT_START_TIME = 20;
Expand All @@ -55,7 +54,7 @@ public class Room extends BaseTimeEntity {
private int level;

@Enumerated(value = EnumType.STRING)
@Column(name = "type")
@Column(name = "room_type")
private RoomType roomType;

@Column(name = "certify_time", nullable = false)
Expand All @@ -76,7 +75,8 @@ public class Room extends BaseTimeEntity {
private String roomImage;

@Builder
private Room(String title, String password, RoomType roomType, int certifyTime, int maxUserCount) {
private Room(Long id, String title, String password, RoomType roomType, int certifyTime, int maxUserCount) {
this.id = id;
this.title = requireNonNull(title);
this.password = password;
this.level = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/moabam/api/domain/entity/Routine.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class Routine extends BaseTimeEntity {
private String content;

@Builder
private Routine(Room room, String content) {
private Routine(Long id, Room room, String content) {
this.id = id;
this.room = requireNonNull(room);
this.content = requireNonNull(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum RoomType {

MORNING, NIGHT
MORNING,
NIGHT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.moabam.api.domain.repository;

import static com.moabam.api.domain.entity.QParticipant.*;

import java.util.Optional;

import org.springframework.stereotype.Repository;

import com.moabam.api.domain.entity.Participant;
import com.moabam.global.common.util.DynamicQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class ParticipantSearchRepository {

private final JPAQueryFactory jpaQueryFactory;

public Optional<Participant> findParticipant(Long roomId, Long memberId) {
return Optional.ofNullable(
jpaQueryFactory.selectFrom(participant)
.where(
DynamicQuery.generateEq(roomId, participant.room.id::eq),
DynamicQuery.generateEq(memberId, participant.memberId::eq)
).fetchOne()
);
}
}

0 comments on commit a0bacae

Please sign in to comment.