Skip to content

Commit

Permalink
fix: Room soft delete로 변경 (#226)
Browse files Browse the repository at this point in the history
* fix: Room soft delete로 변경

* docs: mysql 수정

* fix: checkstyle
  • Loading branch information
ymkim97 authored Dec 2, 2023
1 parent a500b86 commit 96ccb1b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions infra/mysql/initdb.d/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ create table room
announcement varchar(100),
room_image varchar(500),
manager_nickname varchar(30),
deleted_at datetime(6),
created_at datetime(6) not null,
updated_at datetime(6),
primary key (id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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;
Expand Down Expand Up @@ -122,11 +121,6 @@ public void exitRoom(Long memberId, Long roomId) {
return;
}

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

certificationService.deleteCertifications(certifications);
routineRepository.deleteAll(routines);
roomRepository.delete(room);
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/moabam/api/domain/room/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,5 @@ public void updateCertifyCount() {

public void removeRoom() {
this.deletedRoomTitle = this.room.getTitle();
this.room = null;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/moabam/api/domain/room/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import static com.moabam.global.error.model.ErrorMessage.*;
import static java.util.Objects.*;

import java.time.LocalDateTime;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.SQLDelete;

import com.moabam.global.common.entity.BaseTimeEntity;
import com.moabam.global.error.exception.BadRequestException;
Expand All @@ -26,6 +29,7 @@
@Getter
@Table(name = "room")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLDelete(sql = "UPDATE room SET deleted_at = CURRENT_TIMESTAMP where id = ?")
public class Room extends BaseTimeEntity {

private static final int LEVEL_5 = 5;
Expand Down Expand Up @@ -85,6 +89,9 @@ public class Room extends BaseTimeEntity {
@Column(name = "manager_nickname", length = 30)
private String managerNickname;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@Builder
private Room(Long id, String title, String password, RoomType roomType, int certifyTime, int maxUserCount) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,8 @@ void manager_delete_room_success() throws Exception {
.andExpect(status().isOk())
.andDo(print());

List<Room> deletedRoom = roomRepository.findAll();
List<Routine> deletedRoutine = routineRepository.findAll();
List<Participant> deletedParticipant = participantRepository.findAll();

assertThat(deletedRoom).isEmpty();
assertThat(deletedRoutine).hasSize(0);
assertThat(deletedParticipant).hasSize(1);
assertThat(deletedParticipant.get(0).getDeletedAt()).isNotNull();
assertThat(deletedParticipant.get(0).getDeletedRoomTitle()).isNotNull();
Expand Down

0 comments on commit 96ccb1b

Please sign in to comment.