From f95a4bcbce64d635c5954ced12e71aa394084fa2 Mon Sep 17 00:00:00 2001 From: Donghun Won Date: Sat, 5 Oct 2024 23:30:49 +0900 Subject: [PATCH] =?UTF-8?q?Feat=20:=20=EC=95=BD=EA=B4=80=20=EB=8F=99?= =?UTF-8?q?=EC=9D=98=EC=8B=9C,=20=EB=B9=84=EB=8F=99=EC=9D=98=EC=8B=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=B6=94=EA=B0=80=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/OauthController.java | 1 - .../solitour/auth/entity/Term.java | 45 ++ .../solitour/auth/entity/TermRepository.java | 15 + .../solitour/auth/service/OauthService.java | 24 +- .../user/controller/UserController.java | 19 +- ...Request.java => AgreeUserInfoRequest.java} | 4 +- .../dto/request/DisagreeUserInfoRequest.java | 11 + .../solitour/user/entity/User.java | 14 +- .../user/repository/UserRepository.java | 4 +- .../solitour/user/service/UserService.java | 33 +- .../solitour/user/user_status/UserStatus.java | 1 + src/main/resources/schema.sql | 20 +- src/main/resources/schema_test.sql | 491 ++++++++++-------- 13 files changed, 424 insertions(+), 258 deletions(-) create mode 100644 src/main/java/solitour_backend/solitour/auth/entity/Term.java create mode 100644 src/main/java/solitour_backend/solitour/auth/entity/TermRepository.java rename src/main/java/solitour_backend/solitour/user/dto/request/{UpdateUserInfoRequest.java => AgreeUserInfoRequest.java} (62%) create mode 100644 src/main/java/solitour_backend/solitour/user/dto/request/DisagreeUserInfoRequest.java diff --git a/src/main/java/solitour_backend/solitour/auth/controller/OauthController.java b/src/main/java/solitour_backend/solitour/auth/controller/OauthController.java index 8bec21b..607502a 100644 --- a/src/main/java/solitour_backend/solitour/auth/controller/OauthController.java +++ b/src/main/java/solitour_backend/solitour/auth/controller/OauthController.java @@ -85,7 +85,6 @@ public ResponseEntity logout(HttpServletResponse response, @Authentication return ResponseEntity.ok().build(); } - @PostMapping("/token/refresh") public ResponseEntity reissueAccessToken(HttpServletResponse response, @AuthenticationRefreshPrincipal Long memberId) { diff --git a/src/main/java/solitour_backend/solitour/auth/entity/Term.java b/src/main/java/solitour_backend/solitour/auth/entity/Term.java new file mode 100644 index 0000000..9397192 --- /dev/null +++ b/src/main/java/solitour_backend/solitour/auth/entity/Term.java @@ -0,0 +1,45 @@ +package solitour_backend.solitour.auth.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import solitour_backend.solitour.user.entity.User; + +@Getter +@NoArgsConstructor +@Entity +@Builder +@AllArgsConstructor +@Table(name = "term") +public class Term { + + @Id + @Column(name = "term_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Column(nullable = false, name = "term_condition_agreement") + private Boolean termCondition; + + @Column(nullable = false, name = "term_privacy_agreement") + private Boolean termPrivacy; + + @Column(name="term_created_at") + private LocalDateTime createdAt; + +} diff --git a/src/main/java/solitour_backend/solitour/auth/entity/TermRepository.java b/src/main/java/solitour_backend/solitour/auth/entity/TermRepository.java new file mode 100644 index 0000000..5dcc6ff --- /dev/null +++ b/src/main/java/solitour_backend/solitour/auth/entity/TermRepository.java @@ -0,0 +1,15 @@ +package solitour_backend.solitour.auth.entity; + +import java.util.Optional; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.Repository; +import org.springframework.data.repository.query.Param; +import solitour_backend.solitour.user.entity.User; + +public interface TermRepository extends Repository { + void save(Term term); + + @Query("SELECT t FROM Term t WHERE t.user = :user") + Optional findByUser(User user); +} diff --git a/src/main/java/solitour_backend/solitour/auth/service/OauthService.java b/src/main/java/solitour_backend/solitour/auth/service/OauthService.java index f507a2a..d1f530b 100644 --- a/src/main/java/solitour_backend/solitour/auth/service/OauthService.java +++ b/src/main/java/solitour_backend/solitour/auth/service/OauthService.java @@ -258,7 +258,7 @@ private User saveActiveKakaoUser(KakaoUserResponse kakaoUserResponse, CreateUser UserImage savedUserImage = userImageService.saveUserImage(imageUrl); User user = User.builder() - .userStatus(UserStatus.ACTIVATE) + .userStatus(UserStatus.PENDING) .oauthId(String.valueOf(kakaoUserResponse.getId())) .provider("kakao") .isAdmin(false) @@ -279,7 +279,7 @@ private User saveKakaoUser(KakaoUserResponse response) { UserImage savedUserImage = userImageService.saveUserImage(imageUrl); User user = User.builder() - .userStatus(UserStatus.INACTIVATE) + .userStatus(UserStatus.PENDING) .oauthId(String.valueOf(response.getId())) .provider("kakao") .isAdmin(false) @@ -376,15 +376,15 @@ private String getDefaultProfile(User user) { return USER_PROFILE_NONE; } - private void deleteUserProfileFromS3 (UserImage userImage, String defaultImageUrl){ - String userImageUrl = userImage.getAddress(); - if (userImageUrl.equals(USER_PROFILE_MALE) || userImageUrl.equals(USER_PROFILE_FEMALE) - || userImageUrl.equals( - USER_PROFILE_NONE)) { - return; - } - s3Uploader.deleteImage(userImageUrl); - userImage.changeToDefaultProfile(defaultImageUrl); + private void deleteUserProfileFromS3(UserImage userImage, String defaultImageUrl) { + String userImageUrl = userImage.getAddress(); + if (userImageUrl.equals(USER_PROFILE_MALE) || userImageUrl.equals(USER_PROFILE_FEMALE) + || userImageUrl.equals( + USER_PROFILE_NONE)) { + return; } - + s3Uploader.deleteImage(userImageUrl); + userImage.changeToDefaultProfile(defaultImageUrl); } + +} diff --git a/src/main/java/solitour_backend/solitour/user/controller/UserController.java b/src/main/java/solitour_backend/solitour/user/controller/UserController.java index 6287361..8f586a2 100644 --- a/src/main/java/solitour_backend/solitour/user/controller/UserController.java +++ b/src/main/java/solitour_backend/solitour/user/controller/UserController.java @@ -22,7 +22,8 @@ import solitour_backend.solitour.gathering.dto.response.GatheringMypageResponse; import solitour_backend.solitour.information.dto.response.InformationBriefResponse; import solitour_backend.solitour.user.dto.UpdateNicknameRequest; -import solitour_backend.solitour.user.dto.request.UpdateUserInfoRequest; +import solitour_backend.solitour.user.dto.request.AgreeUserInfoRequest; +import solitour_backend.solitour.user.dto.request.DisagreeUserInfoRequest; import solitour_backend.solitour.user.exception.NicknameAlreadyExistsException; import solitour_backend.solitour.user.exception.UserNotExistsException; import solitour_backend.solitour.user.service.UserService; @@ -44,10 +45,18 @@ public ResponseEntity retrieveUserInfo(@AuthenticationPrincipa return ResponseEntity.ok(response); } - @PutMapping("/info") - public ResponseEntity updateUserInfo(@AuthenticationPrincipal Long userId, - @RequestBody UpdateUserInfoRequest request) { - userService.updateUserInfo(userId, request); + @PutMapping("/info/agree") + public ResponseEntity agreeUserInfo(@AuthenticationPrincipal Long userId, + @RequestBody AgreeUserInfoRequest request) { + userService.agreeUserInfo(userId, request); + + return ResponseEntity.noContent().build(); + } + + @PutMapping("/info/disagree") + public ResponseEntity disagreeUserInfo(@AuthenticationPrincipal Long userId, + @RequestBody DisagreeUserInfoRequest request) { + userService.disagreeUserInfo(userId, request); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/solitour_backend/solitour/user/dto/request/UpdateUserInfoRequest.java b/src/main/java/solitour_backend/solitour/user/dto/request/AgreeUserInfoRequest.java similarity index 62% rename from src/main/java/solitour_backend/solitour/user/dto/request/UpdateUserInfoRequest.java rename to src/main/java/solitour_backend/solitour/user/dto/request/AgreeUserInfoRequest.java index 704c56e..d1b2c5e 100644 --- a/src/main/java/solitour_backend/solitour/user/dto/request/UpdateUserInfoRequest.java +++ b/src/main/java/solitour_backend/solitour/user/dto/request/AgreeUserInfoRequest.java @@ -5,7 +5,9 @@ @NoArgsConstructor @Getter -public class UpdateUserInfoRequest { +public class AgreeUserInfoRequest { + private Boolean termConditionAgreement; + private Boolean privacyPolicyAgreement; private String name; private String age; private String sex; diff --git a/src/main/java/solitour_backend/solitour/user/dto/request/DisagreeUserInfoRequest.java b/src/main/java/solitour_backend/solitour/user/dto/request/DisagreeUserInfoRequest.java new file mode 100644 index 0000000..0acb13d --- /dev/null +++ b/src/main/java/solitour_backend/solitour/user/dto/request/DisagreeUserInfoRequest.java @@ -0,0 +1,11 @@ +package solitour_backend.solitour.user.dto.request; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +public class DisagreeUserInfoRequest { + private Boolean termConditionAgreement; + private Boolean privacyPolicyAgreement; +} diff --git a/src/main/java/solitour_backend/solitour/user/entity/User.java b/src/main/java/solitour_backend/solitour/user/entity/User.java index 3be3753..f5196a0 100644 --- a/src/main/java/solitour_backend/solitour/user/entity/User.java +++ b/src/main/java/solitour_backend/solitour/user/entity/User.java @@ -1,5 +1,6 @@ package solitour_backend.solitour.user.entity; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Convert; import jakarta.persistence.Entity; @@ -15,7 +16,9 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import solitour_backend.solitour.user.dto.request.UpdateUserInfoRequest; +import solitour_backend.solitour.auth.entity.Term; +import solitour_backend.solitour.user.dto.request.AgreeUserInfoRequest; +import solitour_backend.solitour.user.dto.request.DisagreeUserInfoRequest; import solitour_backend.solitour.user.user_status.UserStatus; import solitour_backend.solitour.user.user_status.UserStatusConverter; import solitour_backend.solitour.user_image.entity.UserImage; @@ -47,6 +50,9 @@ public class User { @JoinColumn(name = "user_image_id") private UserImage userImage; + @OneToOne(mappedBy = "user",cascade = CascadeType.ALL) + private Term term; + @Column(name = "user_nickname") private String nickname; @@ -105,10 +111,14 @@ public void updateLoginTime() { this.latestLoginAt = LocalDateTime.now(); } - public void updateUserInfo(UpdateUserInfoRequest request) { + public void agreeUserInfo(AgreeUserInfoRequest request) { this.name = request.getName(); this.userStatus = UserStatus.ACTIVATE; this.age = Integer.valueOf(request.getAge()); this.sex = request.getSex(); } + + public void disagreeUserInfo(DisagreeUserInfoRequest request) { + this.userStatus = UserStatus.INACTIVATE; + } } diff --git a/src/main/java/solitour_backend/solitour/user/repository/UserRepository.java b/src/main/java/solitour_backend/solitour/user/repository/UserRepository.java index 059014d..e518bdb 100644 --- a/src/main/java/solitour_backend/solitour/user/repository/UserRepository.java +++ b/src/main/java/solitour_backend/solitour/user/repository/UserRepository.java @@ -7,10 +7,10 @@ public interface UserRepository extends JpaRepository, UserRepositoryCustom { - @Query("SELECT u FROM User u JOIN FETCH u.userImage WHERE u.id = :userId AND (u.userStatus = '활성화' OR u.userStatus = '비활성화')") + @Query("SELECT u FROM User u JOIN FETCH u.userImage WHERE u.id = :userId AND u.userStatus NOT IN ('차단', '휴먼','삭제')") User findByUserId(Long userId); - @Query("SELECT u FROM User u JOIN FETCH u.userImage WHERE u.oauthId = :oauthId AND (u.userStatus = '활성화' OR u.userStatus = '비활성화')") + @Query("SELECT u FROM User u JOIN FETCH u.userImage WHERE u.oauthId = :oauthId AND u.userStatus NOT IN ('차단', '휴먼','삭제')") Optional findByOauthId(String oauthId); boolean existsByNickname(String nickname); diff --git a/src/main/java/solitour_backend/solitour/user/service/UserService.java b/src/main/java/solitour_backend/solitour/user/service/UserService.java index 92bcd34..03d06b0 100644 --- a/src/main/java/solitour_backend/solitour/user/service/UserService.java +++ b/src/main/java/solitour_backend/solitour/user/service/UserService.java @@ -1,5 +1,6 @@ package solitour_backend.solitour.user.service; +import java.time.LocalDateTime; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; @@ -7,11 +8,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import solitour_backend.solitour.auth.entity.Term; +import solitour_backend.solitour.auth.entity.TermRepository; import solitour_backend.solitour.gathering.dto.response.GatheringApplicantResponse; import solitour_backend.solitour.gathering.dto.response.GatheringMypageResponse; import solitour_backend.solitour.image.s3.S3Uploader; import solitour_backend.solitour.information.dto.response.InformationBriefResponse; -import solitour_backend.solitour.user.dto.request.UpdateUserInfoRequest; +import solitour_backend.solitour.user.dto.request.AgreeUserInfoRequest; +import solitour_backend.solitour.user.dto.request.DisagreeUserInfoRequest; import solitour_backend.solitour.user.entity.User; import solitour_backend.solitour.user.exception.NicknameAlreadyExistsException; import solitour_backend.solitour.user.repository.UserRepository; @@ -26,6 +30,7 @@ public class UserService { private final UserRepository userRepository; private final UserImageService userImageService; + private final TermRepository termRepository; private final S3Uploader s3Uploader; @Value("${user.profile.url.female}") private String femaleProfileUrl; @@ -84,13 +89,33 @@ public Page retrieveGatheringApplicant(Pageable page } @Transactional - public void updateUserInfo(Long userId, UpdateUserInfoRequest request) { + public void agreeUserInfo(Long userId, AgreeUserInfoRequest request) { User user = userRepository.findByUserId(userId); changeUserProfile(user, request); - user.updateUserInfo(request); + if(!termRepository.findByUser(user).isPresent()){ + saveTerm(user, request.getTermConditionAgreement(),request.getPrivacyPolicyAgreement()); + } + user.agreeUserInfo(request); + } + + @Transactional + public void disagreeUserInfo(Long userId, DisagreeUserInfoRequest request) { + User user = userRepository.findByUserId(userId); + saveTerm(user, request.getTermConditionAgreement(),request.getPrivacyPolicyAgreement()); + user.disagreeUserInfo(request); + } + + private void saveTerm(User user, Boolean termCondition, Boolean termPrivacy) { + Term term = Term.builder() + .user(user) + .termCondition(termCondition) + .termPrivacy(termPrivacy) + .createdAt(LocalDateTime.now()) + .build(); + termRepository.save(term); } - private void changeUserProfile(User user, UpdateUserInfoRequest request) { + private void changeUserProfile(User user, AgreeUserInfoRequest request) { String sex = request.getSex(); if(user.getUserImage().equals(noneProfileUrl) && sex.equals("male")){ diff --git a/src/main/java/solitour_backend/solitour/user/user_status/UserStatus.java b/src/main/java/solitour_backend/solitour/user/user_status/UserStatus.java index 3e6759c..a18f459 100644 --- a/src/main/java/solitour_backend/solitour/user/user_status/UserStatus.java +++ b/src/main/java/solitour_backend/solitour/user/user_status/UserStatus.java @@ -5,6 +5,7 @@ @Getter public enum UserStatus { + PENDING("대기"), ACTIVATE("활성화"), INACTIVATE("비활성화"), BLOCK("차단"), diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 80fd873..04f00eb 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -19,11 +19,13 @@ DROP TABLE IF EXISTS `banner`; DROP TABLE IF EXISTS `notice`; DROP TABLE IF EXISTS `qna_message`; DROP TABLE IF EXISTS `qna`; +DROP TABLE IF EXISTS `term`; DROP TABLE IF EXISTS `user`; DROP TABLE IF EXISTS `user_image`; DROP TABLE IF EXISTS `diary_day_content`; DROP TABLE IF EXISTS `diary`; + CREATE TABLE `user_image` ( `user_image_id` BIGINT NOT NULL AUTO_INCREMENT, @@ -55,8 +57,8 @@ CREATE TABLE `user` CREATE TABLE `token` ( - `token_id` BIGINT NOT NULL AUTO_INCREMENT, - `user_id` BIGINT NOT NULL, + `token_id` BIGINT NOT NULL AUTO_INCREMENT, + `user_id` BIGINT NOT NULL, `refresh_token` VARCHAR(250) NULL, `oauth_token` VARCHAR(250) NULL, CONSTRAINT PK_TOKEN PRIMARY KEY (`token_id`), @@ -311,4 +313,16 @@ CREATE TABLE `diary_day_content` `diary_day_content_image` TEXT DEFAULT NULL, PRIMARY KEY (`diary_day_content_id`), CONSTRAINT `FK_diary_day_content_TO_diary` FOREIGN KEY (`diary_id`) REFERENCES `diary` (`diary_id`) -); \ No newline at end of file +); + + +CREATE TABLE `term` +( + `term_id` BIGINT NOT NULL AUTO_INCREMENT, + `user_id` BIGINT NOT NULL, + `term_condition_agreement` BOOLEAN NOT NULL, + `term_privacy_agreement` BOOLEAN NOT NULL, + `term_created_at` DATETIME NOT NULL, + PRIMARY KEY (`term_id`), + CONSTRAINT `FK_term_TO_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) +); diff --git a/src/main/resources/schema_test.sql b/src/main/resources/schema_test.sql index b1b3576..e05c3e1 100644 --- a/src/main/resources/schema_test.sql +++ b/src/main/resources/schema_test.sql @@ -23,233 +23,268 @@ DROP TABLE IF EXISTS "qna_message"; DROP TABLE IF EXISTS "notice"; DROP TABLE IF EXISTS "diary"; DROP TABLE IF EXISTS "diary_day_content"; +DROP TABLE IF EXISTS `term`; -- 테이블 생성 -CREATE TABLE "user_image" ( - "user_image_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_image_address" VARCHAR(200) NOT NULL, - "user_image_created_date" DATE NOT NULL -); - -CREATE TABLE "user" ( - "user_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_image_id" BIGINT NOT NULL, - "user_status_id" VARCHAR(20) NOT NULL, - "user_oauth_id" VARCHAR(100), - "provider" VARCHAR(10), - "user_nickname" VARCHAR(30), - "user_name" VARCHAR(20), - "user_age" INT, - "user_sex" VARCHAR(10), - "user_email" VARCHAR(30), - "user_phone_number" VARCHAR(13), - "is_admin" BOOLEAN NOT NULL, - "user_latest_login_at" DATETIME, - "user_created_at" DATETIME NOT NULL, - "user_deleted_at" DATETIME, - FOREIGN KEY ("user_image_id") REFERENCES "user_image" ("user_image_id") -); - -CREATE TABLE "token" ( - "token_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_id" BIGINT NOT NULL, - "refresh_token" VARCHAR(250) NOT NULL, - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id") -); - -CREATE TABLE "place" ( - "place_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "place_search_id" VARCHAR(30), - "place_name" VARCHAR(30) NOT NULL, - "place_x_axis" DECIMAL(10, 7) NOT NULL, - "place_y_axis" DECIMAL(10, 7) NOT NULL, - "place_address" VARCHAR(50) NOT NULL -); - -CREATE TABLE "zone_category" ( - "zone_category_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "parent_zone_category_id" BIGINT, - "zone_category_name" VARCHAR(20) NOT NULL, - FOREIGN KEY ("parent_zone_category_id") REFERENCES "zone_category" ("zone_category_id") -); - -CREATE TABLE "category" ( - "category_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "parent_category_id" BIGINT, - "category_name" VARCHAR(20) NOT NULL, - FOREIGN KEY ("parent_category_id") REFERENCES "category" ("category_id") -); - -CREATE TABLE "gathering_category" ( - "gathering_category_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "gathering_category_name" VARCHAR(20) NOT NULL -); - -CREATE TABLE "information" ( - "information_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "category_id" BIGINT NOT NULL, - "zone_category_id" BIGINT NOT NULL, - "user_id" BIGINT NOT NULL, - "place_id" BIGINT NOT NULL, - "information_title" VARCHAR(50) NOT NULL, - "information_address" VARCHAR(50) NOT NULL, - "information_created_date" DATETIME NOT NULL, - "information_view_count" INT NOT NULL DEFAULT 0, - "information_content" TEXT, - "information_tip" TEXT, - FOREIGN KEY ("category_id") REFERENCES "category" ("category_id"), - FOREIGN KEY ("zone_category_id") REFERENCES "zone_category" ("zone_category_id"), - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), - FOREIGN KEY ("place_id") REFERENCES "place" ("place_id") -); - -CREATE TABLE "gathering" ( - "gathering_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_id" BIGINT NOT NULL, - "zone_category_id" BIGINT NOT NULL, - "gathering_category_id" BIGINT NOT NULL, - "place_id" BIGINT NOT NULL, - "gathering_title" VARCHAR(50), - "gathering_content" TEXT, - "gathering_person_count" INT, - "gathering_view_count" INT, - "gathering_created_at" DATETIME, - "gathering_edited_at" DATETIME, - "gathering_schedule_start_date" DATETIME, - "gathering_schedule_end_date" DATETIME, - "gathering_is_finish" BOOLEAN, - "gathering_deadline" DATETIME, - "gathering_allowed_sex" VARCHAR(30) NOT NULL, - "gathering_start_age" INT NOT NULL, - "gathering_end_age" INT NOT NULL, - "gathering_is_deleted" BOOLEAN NOT NULL DEFAULT FALSE, - "gathering_open_chatting_url" VARCHAR(255), - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), - FOREIGN KEY ("gathering_category_id") REFERENCES "gathering_category" ("gathering_category_id"), - FOREIGN KEY ("zone_category_id") REFERENCES "zone_category" ("zone_category_id"), - FOREIGN KEY ("place_id") REFERENCES "place" ("place_id") -); - -CREATE TABLE "gathering_applicants" ( - "gathering_applicants_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "gathering_id" BIGINT NOT NULL, - "user_id" BIGINT NOT NULL, - "gathering_applicants_state" VARCHAR(20) NOT NULL, - FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id") -); - -CREATE TABLE "image" ( - "image_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "image_status_id" VARCHAR(20) NOT NULL, - "information_id" BIGINT NOT NULL, - "image_address" VARCHAR(200) NOT NULL, - "image_created_date" DATE NOT NULL, - FOREIGN KEY ("information_id") REFERENCES "information" ("information_id") -); - -CREATE TABLE "great_information" ( - "great_information_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_id" BIGINT NOT NULL, - "information_id" BIGINT NOT NULL, - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), - FOREIGN KEY ("information_id") REFERENCES "information" ("information_id"), - UNIQUE ("user_id", "information_id") -); - -CREATE TABLE "great_gathering" ( - "great_gathering_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_id" BIGINT NOT NULL, - "gathering_id" BIGINT NOT NULL, - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), - FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), - UNIQUE ("user_id", "gathering_id") -); - -CREATE TABLE "book_mark_information" ( - "book_mark_information_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_id" BIGINT NOT NULL, - "information_id" BIGINT NOT NULL, - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), - FOREIGN KEY ("information_id") REFERENCES "information" ("information_id"), - UNIQUE ("user_id", "information_id") -); - -CREATE TABLE "book_mark_gathering" ( - "book_mark_gathering_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_id" BIGINT NOT NULL, - "gathering_id" BIGINT NOT NULL, - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), - FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), - UNIQUE ("user_id", "gathering_id") -); - -CREATE TABLE "tag" ( - "tag_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "tag_name" VARCHAR(16) NOT NULL -); - -CREATE TABLE "info_tag" ( - "info_tag_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "tag_id" BIGINT NOT NULL, - "information_id" BIGINT NOT NULL, - FOREIGN KEY ("tag_id") REFERENCES "tag" ("tag_id"), - FOREIGN KEY ("information_id") REFERENCES "information" ("information_id"), - UNIQUE ("tag_id", "information_id") -); - -CREATE TABLE "gathering_tag" ( - "gathering_tag_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "tag_id" BIGINT NOT NULL, - "gathering_id" BIGINT NOT NULL, - FOREIGN KEY ("tag_id") REFERENCES "tag" ("tag_id"), - FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), - UNIQUE ("tag_id", "gathering_id") -); - -CREATE TABLE "banner" ( - "id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "name" VARCHAR(255) NOT NULL, - "url" VARCHAR(255) NOT NULL -); - -CREATE TABLE "qna" ( - "qna_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "qna_category_name" VARCHAR(255), - "qna_created_at" DATETIME, - "qna_status" VARCHAR(255), - "qna_title" VARCHAR(255), - "qna_updated_at" DATETIME, - "user_id" BIGINT, - FOREIGN KEY ("user_id") REFERENCES "user" ("user_id") -); - -CREATE TABLE "qna_message" ( - "id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "qna_message_content" TEXT, - "qna_message_created_at" DATETIME, - "qna_message_user_id" BIGINT, - "qna_id" BIGINT, - FOREIGN KEY ("qna_id") REFERENCES "qna" ("qna_id"), - FOREIGN KEY ("qna_message_user_id") REFERENCES "user" ("user_id") -); - -CREATE TABLE "notice" ( - "notice_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "notice_category_name" VARCHAR(255), - "notice_content" TEXT, - "notice_created_at" DATETIME, - "notice_is_deleted" BOOLEAN DEFAULT FALSE, - "notice_title" VARCHAR(255) -); - -CREATE TABLE "diary" ( - "diary_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - "user_id" BIGINT NOT NULL, - "diary_title" VARCHAR(50) NOT NULL, - "diary_title_image" VARCHAR(200) DEFAULT NULL, - "diary_start_date" DATETIME NOT NULL, - "diary_end_date" DATETIME NOT NULL, - "diary_created_date" DATETIME NOT NULL, - "diary_edited_date" DATETIME DEFAULT NULL -); \ No newline at end of file +CREATE TABLE "user_image" +( + "user_image_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_image_address" VARCHAR(200) NOT NULL, + "user_image_created_date" DATE NOT NULL +); + +CREATE TABLE "user" +( + "user_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_image_id" BIGINT NOT NULL, + "user_status_id" VARCHAR(20) NOT NULL, + "user_oauth_id" VARCHAR(100), + "provider" VARCHAR(10), + "user_nickname" VARCHAR(30), + "user_name" VARCHAR(20), + "user_age" INT, + "user_sex" VARCHAR(10), + "user_email" VARCHAR(30), + "user_phone_number" VARCHAR(13), + "is_admin" BOOLEAN NOT NULL, + "user_latest_login_at" DATETIME, + "user_created_at" DATETIME NOT NULL, + "user_deleted_at" DATETIME, + FOREIGN KEY ("user_image_id") REFERENCES "user_image" ("user_image_id") +); + +CREATE TABLE "token" +( + "token_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_id" BIGINT NOT NULL, + "refresh_token" VARCHAR(250) NOT NULL, + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id") +); + +CREATE TABLE "place" +( + "place_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "place_search_id" VARCHAR(30), + "place_name" VARCHAR(30) NOT NULL, + "place_x_axis" DECIMAL(10, 7) NOT NULL, + "place_y_axis" DECIMAL(10, 7) NOT NULL, + "place_address" VARCHAR(50) NOT NULL +); + +CREATE TABLE "zone_category" +( + "zone_category_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "parent_zone_category_id" BIGINT, + "zone_category_name" VARCHAR(20) NOT NULL, + FOREIGN KEY ("parent_zone_category_id") REFERENCES "zone_category" ("zone_category_id") +); + +CREATE TABLE "category" +( + "category_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "parent_category_id" BIGINT, + "category_name" VARCHAR(20) NOT NULL, + FOREIGN KEY ("parent_category_id") REFERENCES "category" ("category_id") +); + +CREATE TABLE "gathering_category" +( + "gathering_category_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "gathering_category_name" VARCHAR(20) NOT NULL +); + +CREATE TABLE "information" +( + "information_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "category_id" BIGINT NOT NULL, + "zone_category_id" BIGINT NOT NULL, + "user_id" BIGINT NOT NULL, + "place_id" BIGINT NOT NULL, + "information_title" VARCHAR(50) NOT NULL, + "information_address" VARCHAR(50) NOT NULL, + "information_created_date" DATETIME NOT NULL, + "information_view_count" INT NOT NULL DEFAULT 0, + "information_content" TEXT, + "information_tip" TEXT, + FOREIGN KEY ("category_id") REFERENCES "category" ("category_id"), + FOREIGN KEY ("zone_category_id") REFERENCES "zone_category" ("zone_category_id"), + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), + FOREIGN KEY ("place_id") REFERENCES "place" ("place_id") +); + +CREATE TABLE "gathering" +( + "gathering_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_id" BIGINT NOT NULL, + "zone_category_id" BIGINT NOT NULL, + "gathering_category_id" BIGINT NOT NULL, + "place_id" BIGINT NOT NULL, + "gathering_title" VARCHAR(50), + "gathering_content" TEXT, + "gathering_person_count" INT, + "gathering_view_count" INT, + "gathering_created_at" DATETIME, + "gathering_edited_at" DATETIME, + "gathering_schedule_start_date" DATETIME, + "gathering_schedule_end_date" DATETIME, + "gathering_is_finish" BOOLEAN, + "gathering_deadline" DATETIME, + "gathering_allowed_sex" VARCHAR(30) NOT NULL, + "gathering_start_age" INT NOT NULL, + "gathering_end_age" INT NOT NULL, + "gathering_is_deleted" BOOLEAN NOT NULL DEFAULT FALSE, + "gathering_open_chatting_url" VARCHAR(255), + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), + FOREIGN KEY ("gathering_category_id") REFERENCES "gathering_category" ("gathering_category_id"), + FOREIGN KEY ("zone_category_id") REFERENCES "zone_category" ("zone_category_id"), + FOREIGN KEY ("place_id") REFERENCES "place" ("place_id") +); + +CREATE TABLE "gathering_applicants" +( + "gathering_applicants_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "gathering_id" BIGINT NOT NULL, + "user_id" BIGINT NOT NULL, + "gathering_applicants_state" VARCHAR(20) NOT NULL, + FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id") +); + +CREATE TABLE "image" +( + "image_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "image_status_id" VARCHAR(20) NOT NULL, + "information_id" BIGINT NOT NULL, + "image_address" VARCHAR(200) NOT NULL, + "image_created_date" DATE NOT NULL, + FOREIGN KEY ("information_id") REFERENCES "information" ("information_id") +); + +CREATE TABLE "great_information" +( + "great_information_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_id" BIGINT NOT NULL, + "information_id" BIGINT NOT NULL, + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), + FOREIGN KEY ("information_id") REFERENCES "information" ("information_id"), + UNIQUE ("user_id", "information_id") +); + +CREATE TABLE "great_gathering" +( + "great_gathering_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_id" BIGINT NOT NULL, + "gathering_id" BIGINT NOT NULL, + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), + FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), + UNIQUE ("user_id", "gathering_id") +); + +CREATE TABLE "book_mark_information" +( + "book_mark_information_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_id" BIGINT NOT NULL, + "information_id" BIGINT NOT NULL, + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), + FOREIGN KEY ("information_id") REFERENCES "information" ("information_id"), + UNIQUE ("user_id", "information_id") +); + +CREATE TABLE "book_mark_gathering" +( + "book_mark_gathering_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_id" BIGINT NOT NULL, + "gathering_id" BIGINT NOT NULL, + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id"), + FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), + UNIQUE ("user_id", "gathering_id") +); + +CREATE TABLE "tag" +( + "tag_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "tag_name" VARCHAR(16) NOT NULL +); + +CREATE TABLE "info_tag" +( + "info_tag_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "tag_id" BIGINT NOT NULL, + "information_id" BIGINT NOT NULL, + FOREIGN KEY ("tag_id") REFERENCES "tag" ("tag_id"), + FOREIGN KEY ("information_id") REFERENCES "information" ("information_id"), + UNIQUE ("tag_id", "information_id") +); + +CREATE TABLE "gathering_tag" +( + "gathering_tag_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "tag_id" BIGINT NOT NULL, + "gathering_id" BIGINT NOT NULL, + FOREIGN KEY ("tag_id") REFERENCES "tag" ("tag_id"), + FOREIGN KEY ("gathering_id") REFERENCES "gathering" ("gathering_id"), + UNIQUE ("tag_id", "gathering_id") +); + +CREATE TABLE "banner" +( + "id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "name" VARCHAR(255) NOT NULL, + "url" VARCHAR(255) NOT NULL +); + +CREATE TABLE "qna" +( + "qna_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "qna_category_name" VARCHAR(255), + "qna_created_at" DATETIME, + "qna_status" VARCHAR(255), + "qna_title" VARCHAR(255), + "qna_updated_at" DATETIME, + "user_id" BIGINT, + FOREIGN KEY ("user_id") REFERENCES "user" ("user_id") +); + +CREATE TABLE "qna_message" +( + "id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "qna_message_content" TEXT, + "qna_message_created_at" DATETIME, + "qna_message_user_id" BIGINT, + "qna_id" BIGINT, + FOREIGN KEY ("qna_id") REFERENCES "qna" ("qna_id"), + FOREIGN KEY ("qna_message_user_id") REFERENCES "user" ("user_id") +); + +CREATE TABLE "notice" +( + "notice_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "notice_category_name" VARCHAR(255), + "notice_content" TEXT, + "notice_created_at" DATETIME, + "notice_is_deleted" BOOLEAN DEFAULT FALSE, + "notice_title" VARCHAR(255) +); + +CREATE TABLE "diary" +( + "diary_id" BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + "user_id" BIGINT NOT NULL, + "diary_title" VARCHAR(50) NOT NULL, + "diary_title_image" VARCHAR(200) DEFAULT NULL, + "diary_start_date" DATETIME NOT NULL, + "diary_end_date" DATETIME NOT NULL, + "diary_created_date" DATETIME NOT NULL, + "diary_edited_date" DATETIME DEFAULT NULL +); + +CREATE TABLE `term` +( + `term_id` BIGINT NOT NULL AUTO_INCREMENT, + `user_id` BIGINT NOT NULL, + `term_condition_agreement` BOOLEAN NOT NULL, + `term_privacy_agreement` BOOLEAN NOT NULL, + `term_created_at` DATETIME NOT NULL, + PRIMARY KEY (`term_id`), + CONSTRAINT `FK_term_TO_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) +);