From 9fe8133464234289f8f90ad2e1dbec7b8b28fcd4 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Mon, 1 Apr 2024 18:53:31 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20NotNull=20=EC=B9=BC=EB=9F=BC=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20nullable=20false=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/jpa/entity/CafeEntity.kt | 70 ++++++++----------- .../jpa/entity/CafeRoomEntity.kt | 10 +-- .../jpa/entity/CafeRoomReviewDetailEntity.kt | 10 +-- .../jpa/entity/CafeRoomReviewEntity.kt | 6 +- .../entity/CafeRoomReviewRatingFieldEntity.kt | 6 +- .../infrastructure/jpa/entity/GenreEntity.kt | 2 +- .../jpa/entity/SocialUserEntity.kt | 26 +++---- .../infrastructure/jpa/entity/UserEntity.kt | 26 +++---- src/main/resources/db/migration/V1__init.sql | 58 +++++++-------- 9 files changed, 101 insertions(+), 113 deletions(-) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt index 6e3f7e2..c307349 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt @@ -10,64 +10,56 @@ class CafeEntity( @Id @Column(name = "cafe_id") val cafeId: String, - - @Column(name = "franchise_id") + @Column(name = "franchise_id", nullable = false) val franchiseId: String, - - @Column(name = "cafe_name") + @Column(name = "cafe_name", nullable = false) val cafeName: String, - - @Column(name = "description") + @Column(name = "description", nullable = false) val description: String, - @Column(name = "address") val address: String?, - @Column(name = "web_url") val webUrl: String?, - @Column(name = "phone_number") val phoneNumber: String?, - @Column(name = "location_lat") val locationLat: Double?, - @Column(name = "location_lng") val locationLng: Double?, - @Column(name = "addr_1") val addressOne: String?, - @Column(name = "addr_2") val addressTwo: String?, ) { - fun toModel() = Cafe( - id = cafeId, - franchiseId = franchiseId, - name = cafeName, - description = description, - address = address, - webUrl = webUrl, - phoneNumber = phoneNumber, - locationLat = locationLat, - locationLng = locationLng, - addressOne = addressOne, - addressTwo = addressTwo, - ) + fun toModel() = + Cafe( + id = cafeId, + franchiseId = franchiseId, + name = cafeName, + description = description, + address = address, + webUrl = webUrl, + phoneNumber = phoneNumber, + locationLat = locationLat, + locationLng = locationLng, + addressOne = addressOne, + addressTwo = addressTwo, + ) companion object { - fun fromModel(cafe: Cafe) = CafeEntity( - cafeId = cafe.id, - franchiseId = cafe.franchiseId, - cafeName = cafe.name, - description = cafe.description, - address = cafe.address, - webUrl = cafe.webUrl, - phoneNumber = cafe.phoneNumber, - locationLat = cafe.locationLat, - locationLng = cafe.locationLng, - addressOne = cafe.addressOne, - addressTwo = cafe.addressTwo, - ) + fun fromModel(cafe: Cafe) = + CafeEntity( + cafeId = cafe.id, + franchiseId = cafe.franchiseId, + cafeName = cafe.name, + description = cafe.description, + address = cafe.address, + webUrl = cafe.webUrl, + phoneNumber = cafe.phoneNumber, + locationLat = cafe.locationLat, + locationLng = cafe.locationLng, + addressOne = cafe.addressOne, + addressTwo = cafe.addressTwo, + ) } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt index 97dba0c..208d08e 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt @@ -10,11 +10,11 @@ class CafeRoomEntity( @Id @Column(name = "room_id") val roomId: String, - @Column(name = "cafe_id") + @Column(name = "cafe_id", nullable = false) val cafeId: String, - @Column(name = "title") + @Column(name = "title", nullable = false) val title: String, - @Column(name = "description") + @Column(name = "description", nullable = false) val description: String, @ManyToMany @JoinTable( @@ -23,9 +23,9 @@ class CafeRoomEntity( inverseJoinColumns = [JoinColumn(name = "genre_id")], ) val genre: MutableSet = mutableSetOf(), - @Column(name = "timeout") + @Column(name = "timeout", nullable = false) val timeout: Int, - @Column(name = "recommend_user") + @Column(name = "recommend_user", nullable = false) val recommendUserCnt: Int, @Column(name = "room_img_url") val roomImgUrl: String?, diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt index eaa2715..592420f 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt @@ -9,14 +9,14 @@ class CafeRoomReviewDetailEntity( @Id @Column(name = "review_id") val reviewId: String, - @Column(name = "user_cnt") + @Column(name = "user_cnt", nullable = false) val userCnt: Int, - @Column(name = "is_cleared") + @Column(name = "is_cleared", nullable = false) val isCleared: Boolean, - @Column(name = "is_life_theme") + @Column(name = "is_life_theme", nullable = false) val isLifeTheme: Boolean, - @Column(name = "used_hint_cnt") + @Column(name = "used_hint_cnt", nullable = false) val usedHintCnt: Int, - @Column(name = "content") + @Column(name = "content", nullable = false) val content: String, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt index ab7b421..457dd81 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt @@ -8,9 +8,9 @@ class CafeRoomReviewEntity( @Id @Column(name = "review_id") val reviewId: String, - @Column(name = "room_id") + @Column(name = "room_id", nullable = false) val roomId: String, - @Column(name = "user_id") + @Column(name = "user_id", nullable = false) val userId: String, @OneToOne @PrimaryKeyJoinColumn @@ -18,6 +18,6 @@ class CafeRoomReviewEntity( @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "review_id") val ratingFields: List = listOf(), - @Column(name = "created_at") + @Column(name = "created_at", nullable = false) val createdAt: Date, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt index 52d1e02..fd234fe 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt @@ -10,10 +10,10 @@ class CafeRoomReviewRatingFieldEntity( @Id @Column(name = "rating_field_id") val ratingFieldId: String, - @Column(name = "review_id") + @Column(name = "review_id", nullable = false) val reviewId: String, - @Column(name = "type") + @Column(name = "type", nullable = false) val fieldType: RatingFieldType, - @Column(name = "value") + @Column(name = "value", nullable = false) val value: Int, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt index 9ab11fd..9fdc3de 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt @@ -10,7 +10,7 @@ class GenreEntity( @Id @Column(name = "genre_id") val genreId: String, - @Column(name = "name") + @Column(name = "name", nullable = false) val name: String, ) { fun toModel(): Genre { diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt index a309152..de3f8a9 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt @@ -12,26 +12,26 @@ class SocialUserEntity( @Enumerated(EnumType.STRING) @Column(name = "social_provider") val socialProvider: SocialProvider, - @Id @Column(name = "social_identifier") val socialIdentifier: String, - - @Column(name = "user_id") + @Column(name = "user_id", nullable = false) val userId: String, ) { - fun toModel() = SocialUser( - provider = socialProvider, - identifier = socialIdentifier, - userId = userId, - ) + fun toModel() = + SocialUser( + provider = socialProvider, + identifier = socialIdentifier, + userId = userId, + ) companion object { - fun fromModel(socialUser: SocialUser) = SocialUserEntity( - socialProvider = socialUser.provider, - socialIdentifier = socialUser.identifier, - userId = socialUser.userId, - ) + fun fromModel(socialUser: SocialUser) = + SocialUserEntity( + socialProvider = socialUser.provider, + socialIdentifier = socialUser.identifier, + userId = socialUser.userId, + ) } override fun equals(other: Any?): Boolean { diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt index c825764..f7c7b96 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt @@ -10,24 +10,24 @@ class UserEntity( @Id @Column(name = "user_id") val userId: String, - - @Column(name = "nickname") + @Column(name = "nickname", nullable = false) val nickname: String, - @Column(name = "profile_img_url") val profileImageUrl: String?, ) { - fun toModel() = User( - userId = userId, - nickname = nickname, - profileImageUrl = profileImageUrl, - ) + fun toModel() = + User( + userId = userId, + nickname = nickname, + profileImageUrl = profileImageUrl, + ) companion object { - fun fromModel(model: User) = UserEntity( - userId = model.userId, - nickname = model.nickname, - profileImageUrl = model.profileImageUrl, - ) + fun fromModel(model: User) = + UserEntity( + userId = model.userId, + nickname = model.nickname, + profileImageUrl = model.profileImageUrl, + ) } } diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql index 6a8a284..50e6f4a 100644 --- a/src/main/resources/db/migration/V1__init.sql +++ b/src/main/resources/db/migration/V1__init.sql @@ -1,21 +1,21 @@ CREATE TABLE app_info ( app_version VARCHAR(255) NOT NULL, - in_service BIT(1) NULL, + in_service BIT(1) NULL, CONSTRAINT pk_app_info PRIMARY KEY (app_version) ); CREATE TABLE cafe ( cafe_id VARCHAR(255) NOT NULL, - franchise_id VARCHAR(255) NULL, - cafe_name VARCHAR(255) NULL, - `description` VARCHAR(255) NULL, + franchise_id VARCHAR(255) NOT NULL, + cafe_name VARCHAR(255) NOT NULL, + `description` VARCHAR(255) NOT NULL, address VARCHAR(255) NULL, web_url VARCHAR(255) NULL, phone_number VARCHAR(255) NULL, - location_lat DOUBLE NULL, - location_lng DOUBLE NULL, + location_lat DOUBLE NULL, + location_lng DOUBLE NULL, addr_1 VARCHAR(255) NULL, addr_2 VARCHAR(255) NULL, CONSTRAINT pk_cafe PRIMARY KEY (cafe_id) @@ -24,14 +24,14 @@ CREATE TABLE cafe CREATE TABLE cafe_room ( room_id VARCHAR(255) NOT NULL, - cafe_id VARCHAR(255) NULL, - title VARCHAR(255) NULL, - `description` VARCHAR(255) NULL, - timeout INT NULL, - recommend_user INT NULL, + cafe_id VARCHAR(255) NOT NULL, + title VARCHAR(255) NOT NULL, + `description` VARCHAR(255) NOT NULL, + timeout INT NOT NULL, + recommend_user INT NOT NULL, room_img_url VARCHAR(255) NULL, - created_at datetime NULL, - updated_at datetime NULL, + created_at datetime NULL, + updated_at datetime NULL, CONSTRAINT pk_cafe_room PRIMARY KEY (room_id) ); @@ -52,37 +52,37 @@ CREATE TABLE cafe_room_like CREATE TABLE cafe_room_review ( review_id VARCHAR(255) NOT NULL, - room_id VARCHAR(255) NULL, - user_id VARCHAR(255) NULL, + room_id VARCHAR(255) NOT NULL, + user_id VARCHAR(255) NOT NULL, detail_review_id VARCHAR(255) NULL, - created_at datetime NULL, + created_at datetime NOT NULL, CONSTRAINT pk_cafe_room_review PRIMARY KEY (review_id) ); CREATE TABLE cafe_room_review_det ( review_id VARCHAR(255) NOT NULL, - user_cnt INT NULL, - is_cleared BIT(1) NULL, - is_life_theme BIT(1) NULL, - used_hint_cnt INT NULL, - content VARCHAR(255) NULL, + user_cnt INT NOT NULL, + is_cleared BIT(1) NOT NULL, + is_life_theme BIT(1) NOT NULL, + used_hint_cnt INT NOT NULL, + content VARCHAR(255) NOT NULL, CONSTRAINT pk_cafe_room_review_det PRIMARY KEY (review_id) ); CREATE TABLE cafe_room_review_rating_field ( rating_field_id VARCHAR(255) NOT NULL, - review_id VARCHAR(255) NULL, - type TINYINT NULL, - value INT NULL, + review_id VARCHAR(255) NOT NULL, + type SMALLINT NOT NULL, + value INT NOT NULL, CONSTRAINT pk_cafe_room_review_rating_field PRIMARY KEY (rating_field_id) ); CREATE TABLE genre ( genre_id VARCHAR(255) NOT NULL, - name VARCHAR(255) NULL, + name VARCHAR(255) NOT NULL, CONSTRAINT pk_genre PRIMARY KEY (genre_id) ); @@ -90,14 +90,14 @@ CREATE TABLE social_user ( social_provider VARCHAR(255) NOT NULL, social_identifier VARCHAR(255) NOT NULL, - user_id VARCHAR(255) NULL, + user_id VARCHAR(255) NOT NULL, CONSTRAINT pk_social_user PRIMARY KEY (social_provider, social_identifier) ); CREATE TABLE user ( user_id VARCHAR(255) NOT NULL, - nickname VARCHAR(255) NULL, + nickname VARCHAR(255) NOT NULL, profile_img_url VARCHAR(255) NULL, CONSTRAINT pk_user PRIMARY KEY (user_id) ); @@ -116,7 +116,3 @@ ALTER TABLE cafe_room_genre ALTER TABLE cafe_room_genre ADD CONSTRAINT fk_cafroogen_on_genre_entity FOREIGN KEY (genre_id) REFERENCES genre (genre_id); - -INSERT INTO user (user_id, nickname, profile_img_url) -VALUES ('01HDNFJHCNS5E2W35YTB030TJ8', '테스트용사용자', - 'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png');