Skip to content

Commit

Permalink
refactor: soft-delete 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
tsulocalize committed Aug 1, 2024
1 parent 5273325 commit 22793bc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ public abstract class BaseEntity {
@LastModifiedDate
private LocalDateTime modifiedAt;

private boolean deleted = false;

public LocalDateTime getCreatedAt() {
return createdAt;
}

public LocalDateTime getModifiedAt() {
return modifiedAt;
}

public boolean isDeleted() {
return deleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

public interface CustomChecklistQuestionRepository extends JpaRepository<CustomChecklistQuestion, Long> {

List<CustomChecklistQuestion> findByUser(User user);
@Query("SELECT c FROM CustomChecklistQuestion c WHERE c.user.id = :#{#user.id} AND c.deleted = false " )
List<CustomChecklistQuestion> findByUser(@Param("user") User user);

@Modifying(flushAutomatically = true, clearAutomatically = true)
@Query("DELETE FROM CustomChecklistQuestion WHERE user.id = :#{#user.id}")
@Query("UPDATE CustomChecklistQuestion SET deleted = true WHERE user.id = :#{#user.id}")
void deleteAllByUser(@Param("user") User user);

}
28 changes: 14 additions & 14 deletions backend/bang-ggood/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
INSERT INTO users(id, name, created_at, modified_at)
VALUES (1, '방방이', '2024-07-22 07:56:42', '2024-07-22 07:56:42');
INSERT INTO users(id, name, created_at, modified_at, deleted)
VALUES (1, '방방이', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false);

INSERT INTO custom_checklist_question(user_id, question, created_at, modified_at)
VALUES (1, 'CLEAN_1', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'CLEAN_4', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ROOM_CONDITION_6', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ROOM_CONDITION_7', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ROOM_CONDITION_8', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'AMENITY_12', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ENVIRONMENT_18', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ENVIRONMENT_19', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'SECURITY_23', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'SECURITY_25', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ECONOMIC_31', '2024-07-22 07:56:42', '2024-07-22 07:56:42');
INSERT INTO custom_checklist_question(user_id, question, created_at, modified_at, deleted)
VALUES (1, 'CLEAN_1', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'CLEAN_4', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ROOM_CONDITION_6', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ROOM_CONDITION_7', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ROOM_CONDITION_8', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'AMENITY_12', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ENVIRONMENT_18', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ENVIRONMENT_19', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'SECURITY_23', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'SECURITY_25', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ECONOMIC_31', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false);
16 changes: 12 additions & 4 deletions backend/bang-ggood/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ DROP TABLE IF EXISTS checklist_option CASCADE;
DROP TABLE IF EXISTS checklist_question CASCADE;
DROP TABLE IF EXISTS room CASCADE;
DROP TABLE IF EXISTS users CASCADE;
DROP TABLE IF EXISTS test_entity CASCADE;
DROP TABLE IF EXISTS custom_checklist_question CASCADE;

-- Create tables
CREATE TABLE room
Expand All @@ -15,15 +17,17 @@ CREATE TABLE room
modified_at TIMESTAMP(6),
address VARCHAR(255),
name VARCHAR(255),
station VARCHAR(255)
station VARCHAR(255),
deleted BOOLEAN
);

CREATE TABLE users
(
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6)
modified_at TIMESTAMP(6),
deleted BOOLEAN
);

CREATE TABLE checklist
Expand All @@ -37,6 +41,7 @@ CREATE TABLE checklist
room_id BIGINT NOT NULL UNIQUE,
user_id BIGINT NOT NULL,
real_estate VARCHAR(255),
deleted BOOLEAN,
FOREIGN KEY (room_id) REFERENCES room (id),
FOREIGN KEY (user_id) REFERENCES users (id)
);
Expand All @@ -48,6 +53,7 @@ CREATE TABLE checklist_option
checklist_id BIGINT NOT NULL,
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6),
deleted BOOLEAN,
FOREIGN KEY (checklist_id) REFERENCES checklist (id)
);

Expand All @@ -59,17 +65,18 @@ CREATE TABLE checklist_question
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6),
grade VARCHAR(255),
deleted BOOLEAN,
FOREIGN KEY (checklist_id) REFERENCES checklist (id)
);


CREATE TABLE category_priority
CREATE TABLE if not exists category_priority
(
id bigint generated by default as identity,
category_id INTEGER not null,
user_id bigint not null,
created_at TIMESTAMP not null,
modified_at TIMESTAMP not null,
deleted BOOLEAN,
primary key (id),
foreign key (user_id) references users
);
Expand All @@ -81,5 +88,6 @@ CREATE TABLE custom_checklist_question
question VARCHAR(255),
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6),
deleted BOOLEAN,
FOREIGN KEY (user_id) references users
);
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;

import static com.bang_ggood.checklist.CustomChecklistFixture.CUSTOM_CHECKLIST_UPDATE_REQUEST;
Expand Down
28 changes: 14 additions & 14 deletions backend/bang-ggood/src/test/resources/data-test.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
INSERT INTO users(id, name, created_at, modified_at)
VALUES (1, '방방이', '2024-07-22 07:56:42', '2024-07-22 07:56:42');
INSERT INTO users(id, name, created_at, modified_at, deleted)
VALUES (1, '방방이', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false);

INSERT INTO custom_checklist_question(user_id, question, created_at, modified_at)
VALUES (1, 'CLEAN_1', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'CLEAN_4', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ROOM_CONDITION_6', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ROOM_CONDITION_7', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ROOM_CONDITION_8', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'AMENITY_12', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ENVIRONMENT_18', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ENVIRONMENT_19', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'SECURITY_23', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'SECURITY_25', '2024-07-22 07:56:42', '2024-07-22 07:56:42'),
(1, 'ECONOMIC_31', '2024-07-22 07:56:42', '2024-07-22 07:56:42');
INSERT INTO custom_checklist_question(user_id, question, created_at, modified_at, deleted)
VALUES (1, 'CLEAN_1', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'CLEAN_4', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ROOM_CONDITION_6', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ROOM_CONDITION_7', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ROOM_CONDITION_8', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'AMENITY_12', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ENVIRONMENT_18', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ENVIRONMENT_19', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'SECURITY_23', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'SECURITY_25', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false),
(1, 'ECONOMIC_31', '2024-07-22 07:56:42', '2024-07-22 07:56:42', false);
12 changes: 10 additions & 2 deletions backend/bang-ggood/src/test/resources/schema-test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ CREATE TABLE room
modified_at TIMESTAMP(6),
address VARCHAR(255),
name VARCHAR(255),
station VARCHAR(255)
station VARCHAR(255),
deleted BOOLEAN
);

CREATE TABLE users
(
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6)
modified_at TIMESTAMP(6),
deleted BOOLEAN
);

CREATE TABLE checklist
Expand All @@ -39,6 +41,7 @@ CREATE TABLE checklist
room_id BIGINT NOT NULL UNIQUE,
user_id BIGINT NOT NULL,
real_estate VARCHAR(255),
deleted BOOLEAN,
FOREIGN KEY (room_id) REFERENCES room (id),
FOREIGN KEY (user_id) REFERENCES users (id)
);
Expand All @@ -50,6 +53,7 @@ CREATE TABLE checklist_option
checklist_id BIGINT NOT NULL,
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6),
deleted BOOLEAN,
FOREIGN KEY (checklist_id) REFERENCES checklist (id)
);

Expand All @@ -61,6 +65,7 @@ CREATE TABLE checklist_question
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6),
grade VARCHAR(255),
deleted BOOLEAN,
FOREIGN KEY (checklist_id) REFERENCES checklist (id)
);

Expand All @@ -71,6 +76,7 @@ CREATE TABLE if not exists category_priority
user_id bigint not null,
created_at TIMESTAMP not null,
modified_at TIMESTAMP not null,
deleted BOOLEAN,
primary key (id),
foreign key (user_id) references users
);
Expand All @@ -82,6 +88,7 @@ CREATE TABLE test_entity
name varchar(255) not null,
created_at TIMESTAMP not null,
modified_at TIMESTAMP not null,
deleted BOOLEAN,
primary key (id)
);

Expand All @@ -92,5 +99,6 @@ CREATE TABLE custom_checklist_question
question VARCHAR(255),
created_at TIMESTAMP(6),
modified_at TIMESTAMP(6),
deleted BOOLEAN,
FOREIGN KEY (user_id) references users
);

0 comments on commit 22793bc

Please sign in to comment.