Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Room soft delete로 변경 #226

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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