diff --git a/alex/week0/README.md b/alex/week0/README.md new file mode 100644 index 0000000..bb17638 --- /dev/null +++ b/alex/week0/README.md @@ -0,0 +1,16 @@ + +### 전체 ERD +![Main](./main.png) + +### user +![User](./user.png) + +### review +![review](./review.png) + +### store +![store](./store.png) + +### mission +![mission](./mission.png) + diff --git a/alex/week0/main.png b/alex/week0/main.png new file mode 100644 index 0000000..9ac6f26 Binary files /dev/null and b/alex/week0/main.png differ diff --git a/alex/week0/mission.png b/alex/week0/mission.png new file mode 100644 index 0000000..3f77a48 Binary files /dev/null and b/alex/week0/mission.png differ diff --git a/alex/week0/review.png b/alex/week0/review.png new file mode 100644 index 0000000..edb2763 Binary files /dev/null and b/alex/week0/review.png differ diff --git a/alex/week0/store.png b/alex/week0/store.png new file mode 100644 index 0000000..725a90e Binary files /dev/null and b/alex/week0/store.png differ diff --git a/alex/week0/user.png b/alex/week0/user.png new file mode 100644 index 0000000..7e5b8fd Binary files /dev/null and b/alex/week0/user.png differ diff --git a/alex/week1/sql_query.txt b/alex/week1/sql_query.txt new file mode 100644 index 0000000..b2024ed --- /dev/null +++ b/alex/week1/sql_query.txt @@ -0,0 +1,45 @@ +## 1 ## +INSERT INTO review (user_id, store_id, star, content) +VALUES (1, 1, 5, '음 너무 맛있어요...'); +###### + +## 2 ## +SELECT u.id, u.name, u.email, u.phone_num, u.point +FROM user AS u +WHERE u.id = :user_id +###### + +## 3 ## +SELECT + m.point, + m.contnet +FROM user_mission AS um +JOIN mission AS m +ON um.mission_id = m.id +WHERE um.user_id = :user_id + AND um.is_complete = True +ORDER BY um.cmplete_at DESC +LIMIT 15; +###### + +## 4 ## +SELECT + m.content + s.name + fc.name + m.deadline + m.point +FROM user_mission AS um +JOIN mssion AS m +ON um.mission_id = m.id +JOIN store AS s +ON m.store_id = s.id +JOIN food_category AS fc +ON s.category_id = fc.id +WHERE + um.is_complete = false AND + s.addr = '안암동' AND + um.user_id = :user_id +ORDER BY um.complete_at DESC +LIMIT 15; +###### diff --git a/alex/week4/com/exmaple/umc/agreement/Agreement.java b/alex/week4/com/exmaple/umc/agreement/Agreement.java new file mode 100644 index 0000000..ce255ce --- /dev/null +++ b/alex/week4/com/exmaple/umc/agreement/Agreement.java @@ -0,0 +1,16 @@ +package com.example.umc.agreement; + +import com.example.umc.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="agreement") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Agreement extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=1000) + private String content; +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/agreement/UserAgreement.java b/alex/week4/com/exmaple/umc/agreement/UserAgreement.java new file mode 100644 index 0000000..f2de140 --- /dev/null +++ b/alex/week4/com/exmaple/umc/agreement/UserAgreement.java @@ -0,0 +1,24 @@ +package com.example.umc.agreement; + +import com.example.umc.user.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table(name="user_agreement", + uniqueConstraints = @UniqueConstraint(name="uq_user_agreement", columnNames={"user_id","agreement_id"})) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class UserAgreement { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="user_id", nullable=false) + private User user; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="agreement_id", nullable=false) + private Agreement agreement; + + @Column(nullable=false) private Boolean isAgreed; + private LocalDateTime agreedAt; +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/common/BaseTime.java b/alex/week4/com/exmaple/umc/common/BaseTime.java new file mode 100644 index 0000000..32b570b --- /dev/null +++ b/alex/week4/com/exmaple/umc/common/BaseTime.java @@ -0,0 +1,19 @@ +package com.example.umc.common; + +import jakarta.persistence.*; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; +import java.time.LocalDateTime; + +@MappedSuperclass +@Getter +public abstract class BaseTime { + @CreationTimestamp + @Column(name = "created_at", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at", nullable = false) + private LocalDateTime updatedAt; +} diff --git a/alex/week4/com/exmaple/umc/mission/Mission.java b/alex/week4/com/exmaple/umc/mission/Mission.java new file mode 100644 index 0000000..7b13591 --- /dev/null +++ b/alex/week4/com/exmaple/umc/mission/Mission.java @@ -0,0 +1,41 @@ +package com.example.umc.mission; + +import com.example.umc.common.BaseTime; +import com.example.umc.store.Store; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDate; +import java.util.List; + +@Entity +@Table( + name = "mission", + indexes = { + @Index(name = "idx_mission_store", columnList = "store_id") + } +) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Mission extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id", nullable = false) + private Store store; + + @Column(nullable = false, length = 255) + private String content; + + @Column(nullable = false) + private LocalDate deadline; + + @Column(nullable = false) + private Long point; + + @Column(nullable = false) + private Boolean dbStatus = true; + + @OneToMany(mappedBy = "mission", cascade = CascadeType.ALL, orphanRemoval = true) + private List assignments; +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/mission/UserMission.java b/alex/week4/com/exmaple/umc/mission/UserMission.java new file mode 100644 index 0000000..fb1cb5c --- /dev/null +++ b/alex/week4/com/exmaple/umc/mission/UserMission.java @@ -0,0 +1,43 @@ +package com.example.umc.mission; + +import com.example.umc.user.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table( + name = "user_mission", + uniqueConstraints = { + @UniqueConstraint(name = "uq_user_mission", columnNames = {"user_id", "mission_id"}) + }, + indexes = { + @Index(name = "idx_um_user", columnList = "user_id"), + @Index(name = "idx_um_mission", columnList = "mission_id") + } +) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class UserMission { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_id", nullable = false) + private Mission mission; + + @Column(name = "is_complete", nullable = false) + private Boolean isComplete = false; + + @Column(name = "complete_at") + private LocalDateTime completeAt; + + public void completeNow() { + this.isComplete = true; + this.completeAt = LocalDateTime.now(); + } +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/review/Review.java b/alex/week4/com/exmaple/umc/review/Review.java new file mode 100644 index 0000000..cbe0e6e --- /dev/null +++ b/alex/week4/com/exmaple/umc/review/Review.java @@ -0,0 +1,32 @@ +package com.example.umc.review; + +import com.example.umc.common.BaseTime; +import com.example.umc.store.Store; +import com.example.umc.user.User; +import jakarta.persistence.*; +import lombok.*; +import java.util.List; + +@Entity +@Table(name="review") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Review extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="user_id", nullable=false) + private User user; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="store_id", nullable=false) + private Store store; + + @Column(nullable=false) private Integer star; + @Column(nullable=false, length=1000) private String content; + @Column(nullable=false) private Boolean dbStatus; + + @OneToMany(mappedBy="review", cascade=CascadeType.ALL, orphanRemoval=true) + private List images; + + @OneToOne(mappedBy="review", cascade=CascadeType.ALL, orphanRemoval=true, fetch=FetchType.LAZY) + private ReviewReply reply; +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/review/ReviewImage.java b/alex/week4/com/exmaple/umc/review/ReviewImage.java new file mode 100644 index 0000000..0cbcaff --- /dev/null +++ b/alex/week4/com/exmaple/umc/review/ReviewImage.java @@ -0,0 +1,18 @@ +package com.example.umc.review; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="review_image") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class ReviewImage { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="review_id", nullable=false) + private Review review; + + @Column(name="image_url", nullable=false, length=500) + private String imageUrl; +} diff --git a/alex/week4/com/exmaple/umc/review/ReviewReply.java b/alex/week4/com/exmaple/umc/review/ReviewReply.java new file mode 100644 index 0000000..04c2a2a --- /dev/null +++ b/alex/week4/com/exmaple/umc/review/ReviewReply.java @@ -0,0 +1,19 @@ +package com.example.umc.review; + +import com.example.umc.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="review_reply") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class ReviewReply extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch=FetchType.LAZY) @JoinColumn(name="review_id", nullable=false, unique=true) + private Review review; + + @Column(nullable=false, length=1000) + private String content; +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/store/Store.java b/alex/week4/com/exmaple/umc/store/Store.java new file mode 100644 index 0000000..764fd1c --- /dev/null +++ b/alex/week4/com/exmaple/umc/store/Store.java @@ -0,0 +1,25 @@ +package com.example.umc.store; + +import com.example.umc.common.BaseTime; +import com.example.umc.user.FoodCategory; +import jakarta.persistence.*; +import lombok.*; +import java.util.List; + +@Entity +@Table(name="store") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Store extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="category_id", nullable=false) + private FoodCategory category; + + @Column(nullable=false, length=100) private String name; + @Column(nullable=false, length=255) private String addr; + @Column(nullable=false) private Boolean dbStatus; + + @OneToMany(mappedBy="store", cascade=CascadeType.ALL, orphanRemoval=true) + private List images; +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/store/StoreImage.java b/alex/week4/com/exmaple/umc/store/StoreImage.java new file mode 100644 index 0000000..3b85022 --- /dev/null +++ b/alex/week4/com/exmaple/umc/store/StoreImage.java @@ -0,0 +1,18 @@ +package com.example.umc.store; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="store_image") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class StoreImage { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="store_id", nullable=false) + private Store store; + + @Column(name="image_url", nullable=false, length=500) + private String imageUrl; +} \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/user/FoodCategory.java b/alex/week4/com/exmaple/umc/user/FoodCategory.java new file mode 100644 index 0000000..841b137 --- /dev/null +++ b/alex/week4/com/exmaple/umc/user/FoodCategory.java @@ -0,0 +1,16 @@ +package com.example.umc.user; + +import com.example.umc.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="food_category") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class FoodCategory extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=50, unique=true) + private String name; +} diff --git a/alex/week4/com/exmaple/umc/user/SocialType.java b/alex/week4/com/exmaple/umc/user/SocialType.java new file mode 100644 index 0000000..c0a6244 --- /dev/null +++ b/alex/week4/com/exmaple/umc/user/SocialType.java @@ -0,0 +1,5 @@ +package com.example.umc.domain.user; +public enum SocialType { KAKAO, NAVER, GOOGLE, APPLE } + +package com.example.umc.domain.review; +public enum DbStatus { DISABLED, ENABLED } \ No newline at end of file diff --git a/alex/week4/com/exmaple/umc/user/User.java b/alex/week4/com/exmaple/umc/user/User.java new file mode 100644 index 0000000..65457dc --- /dev/null +++ b/alex/week4/com/exmaple/umc/user/User.java @@ -0,0 +1,40 @@ +package com.example.umc.user; + +import com.example.umc.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDate; +import java.util.Set; + +@Entity +@Table(name = "`User`") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class User extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=50) private String name; + @Column(nullable=false) private Boolean sex; + @Column(nullable=false) private LocalDate birth; + @Column(nullable=false, length=255) private String addr; + + @Column(nullable=false) private Boolean userType; + @Column(nullable=false, length=255) private String socialUID; + + @Enumerated(EnumType.STRING) + @Column(nullable=false, length=10) private SocialType socialType; + + @Column(unique=true, length=100) private String email; + @Column(unique=true, length=20) private String phoneNum; + + @Column(nullable=false) private Long point; + @Column(nullable=false) private Boolean dbStatus; + + @ManyToMany + @JoinTable( + name = "user_interest", + joinColumns = @JoinColumn(name="user_id"), + inverseJoinColumns = @JoinColumn(name="food_cat_id") + ) + private Set interests; +} diff --git a/alex/week4/entity/REAMD.md b/alex/week4/entity/REAMD.md new file mode 100644 index 0000000..8033dcc --- /dev/null +++ b/alex/week4/entity/REAMD.md @@ -0,0 +1 @@ +![image](./image.png) \ No newline at end of file diff --git a/alex/week4/entity/image.png b/alex/week4/entity/image.png new file mode 100644 index 0000000..0e28dbd Binary files /dev/null and b/alex/week4/entity/image.png differ diff --git a/alex/week4/sql_query.sql b/alex/week4/sql_query.sql new file mode 100644 index 0000000..0610571 --- /dev/null +++ b/alex/week4/sql_query.sql @@ -0,0 +1,186 @@ +CREATE DATABASE IF NOT EXISTS umc9th; +USE umc9th; + +CREATE TABLE IF NOT EXISTS food_category ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + name VARCHAR(50) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + UNIQUE KEY uq_food_category_name (name) +); + +-- #################### User #################### +CREATE TABLE IF NOT EXISTS `User` ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + name VARCHAR(50) NOT NULL, + sex TINYINT(1) NOT NULL, + birth DATE NOT NULL, + addr VARCHAR(255) NOT NULL, + user_type TINYINT(1) NOT NULL DEFAULT 0, + social_UID VARCHAR(255) NOT NULL, + social_type ENUM('KAKAO','NAVER','GOOGLE','APPLE') NOT NULL, + email VARCHAR(100) DEFAULT NULL, + phone_num VARCHAR(20) DEFAULT NULL, + point BIGINT UNSIGNED NOT NULL DEFAULT 0, + db_status TINYINT(1) NOT NULL DEFAULT 1, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + UNIQUE KEY uq_user_social (social_type, social_UID), + UNIQUE KEY uq_user_email (email), + UNIQUE KEY uq_user_phone (phone_num) +); + +CREATE TABLE IF NOT EXISTS agreement ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '약관 PK', + content VARCHAR(1000) NOT NULL COMMENT '약관 내용', + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '생성일', + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '수정일', + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS user_agreement ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + user_id BIGINT UNSIGNED NOT NULL, + agreement_id BIGINT UNSIGNED NOT NULL, + is_agreed TINYINT(1) NOT NULL DEFAULT 0, + agreed_at DATETIME DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY uq_user_agreement (user_id, agreement_id), + CONSTRAINT fk_useragreement_users + FOREIGN KEY (user_id) REFERENCES `User`(id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT fk_useragreement_agreement + FOREIGN KEY (agreement_id) REFERENCES agreement(id) + ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE IF NOT EXISTS user_interest ( + user_id BIGINT UNSIGNED NOT NULL, + food_cat_id BIGINT UNSIGNED NOT NULL, + + PRIMARY KEY (user_id, food_cat_id), + + CONSTRAINT fk_userinterest_user + FOREIGN KEY (user_id) REFERENCES `User`(id) + ON DELETE CASCADE ON UPDATE CASCADE, + + CONSTRAINT fk_userinterest_foodcat + FOREIGN KEY (food_cat_id) REFERENCES food_category(id) + ON DELETE CASCADE ON UPDATE CASCADE +); + +-- #################### Store #################### +CREATE TABLE IF NOT EXISTS store ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + category_id BIGINT UNSIGNED NOT NULL, + name VARCHAR(100) NOT NULL, + addr VARCHAR(255) NOT NULL, + db_status TINYINT(1) NOT NULL DEFAULT 1, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + KEY idx_store_category (category_id), + CONSTRAINT fk_store_category + FOREIGN KEY (category_id) REFERENCES food_category(id) + ON DELETE RESTRICT ON UPDATE CASCADE, + CHECK (db_status IN (0,1)) +); + +CREATE TABLE IF NOT EXISTS store_image ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + store_id BIGINT UNSIGNED NOT NULL, + image_url VARCHAR(500) NOT NULL, + + PRIMARY KEY (id), + KEY idx_storeimage_store (store_id), + + CONSTRAINT fk_storeimage_store + FOREIGN KEY (store_id) REFERENCES store(id) + ON DELETE CASCADE ON UPDATE CASCADE +); + +-- #################### Mission #################### +CREATE TABLE IF NOT EXISTS mission ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + store_id BIGINT UNSIGNED NOT NULL, + content VARCHAR(255) NOT NULL, + deadline DATE NOT NULL, + point BIGINT UNSIGNED NOT NULL DEFAULT 0, + dbStatus TINYINT(1) NOT NULL DEFAULT 1, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + + PRIMARY KEY (id), + KEY idx_mission_store (store_id), + CONSTRAINT fk_mission_store + FOREIGN KEY (store_id) REFERENCES store(id) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE TABLE IF NOT EXISTS user_mission ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + user_id BIGINT UNSIGNED NOT NULL, + mission_id BIGINT UNSIGNED NOT NULL, + is_complete TINYINT(1) NOT NULL DEFAULT 0, + complete_at DATETIME DEFAULT NULL, + + PRIMARY KEY (id), + UNIQUE KEY uq_user_mission (user_id, mission_id), + KEY idx_um_user (user_id), + KEY idx_um_mission(mission_id), + + CONSTRAINT fk_um_user + FOREIGN KEY (user_id) REFERENCES `User`(id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT fk_um_mission + FOREIGN KEY (mission_id) REFERENCES mission(id) + ON DELETE CASCADE ON UPDATE CASCADE +); + +-- #################### Review #################### +CREATE TABLE IF NOT EXISTS review ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + user_id BIGINT UNSIGNED NOT NULL, + store_id BIGINT UNSIGNED NOT NULL, + star TINYINT UNSIGNED NOT NULL COMMENT '1~5', + content VARCHAR(1000) NOT NULL, + db_status TINYINT(1) NOT NULL DEFAULT 1, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + KEY idx_review_user (user_id), + KEY idx_review_store (store_id), + CONSTRAINT fk_review_user + FOREIGN KEY (user_id) REFERENCES `User`(id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT fk_review_store + FOREIGN KEY (store_id) REFERENCES store(id) + ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE IF NOT EXISTS review_reply ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + review_id BIGINT UNSIGNED NOT NULL, + content VARCHAR(1000) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + KEY idx_reviewreply_review (review_id), + CONSTRAINT fk_reviewreply_review + FOREIGN KEY (review_id) REFERENCES review(id) + ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE IF NOT EXISTS review_image ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + review_id BIGINT UNSIGNED NOT NULL, + image_url VARCHAR(500) NOT NULL, + + PRIMARY KEY (id), + KEY idx_reviewimage_review (review_id), + CONSTRAINT fk_reviewimage_review + FOREIGN KEY (review_id) REFERENCES review(id) + ON DELETE CASCADE ON UPDATE CASCADE +); \ No newline at end of file diff --git a/alex/week4/umc9th/.gitattributes b/alex/week4/umc9th/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/alex/week4/umc9th/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/alex/week4/umc9th/.gitignore b/alex/week4/umc9th/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/alex/week4/umc9th/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/alex/week4/umc9th/build.gradle b/alex/week4/umc9th/build.gradle new file mode 100644 index 0000000..02d91e0 --- /dev/null +++ b/alex/week4/umc9th/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.5.7' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +description = 'umc 9th practice project' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.mysql:mysql-connector-j' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/alex/week4/umc9th/gradle/wrapper/gradle-wrapper.jar b/alex/week4/umc9th/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..1b33c55 Binary files /dev/null and b/alex/week4/umc9th/gradle/wrapper/gradle-wrapper.jar differ diff --git a/alex/week4/umc9th/gradle/wrapper/gradle-wrapper.properties b/alex/week4/umc9th/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d4081da --- /dev/null +++ b/alex/week4/umc9th/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/alex/week4/umc9th/gradlew b/alex/week4/umc9th/gradlew new file mode 100755 index 0000000..23d15a9 --- /dev/null +++ b/alex/week4/umc9th/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH="\\\"\\\"" + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/alex/week4/umc9th/gradlew.bat b/alex/week4/umc9th/gradlew.bat new file mode 100644 index 0000000..db3a6ac --- /dev/null +++ b/alex/week4/umc9th/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH= + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/alex/week4/umc9th/settings.gradle b/alex/week4/umc9th/settings.gradle new file mode 100644 index 0000000..0ec607f --- /dev/null +++ b/alex/week4/umc9th/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'umc9th' diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/Umc9thApplication.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/Umc9thApplication.java new file mode 100644 index 0000000..cf0063f --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/Umc9thApplication.java @@ -0,0 +1,13 @@ +package com.example.umc9th; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Umc9thApplication { + + public static void main(String[] args) { + SpringApplication.run(Umc9thApplication.class, args); + } + +} diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/Agreement.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/Agreement.java new file mode 100644 index 0000000..92c5d10 --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/Agreement.java @@ -0,0 +1,17 @@ +package com.example.umc9th.domain.agreement.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="agreement") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Agreement extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=1000) + private String content; +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/UserAgreement.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/UserAgreement.java new file mode 100644 index 0000000..67e750f --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/UserAgreement.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.agreement.entity; + +import com.example.umc9th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table(name="user_agreement", + uniqueConstraints = @UniqueConstraint(name="uq_user_agreement", columnNames={"user_id","agreement_id"})) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class UserAgreement { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="user_id", nullable=false) + private User user; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="agreement_id", nullable=false) + private Agreement agreement; + + @Column(nullable=false) private Boolean isAgreed; + private LocalDateTime agreedAt; +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java new file mode 100644 index 0000000..d99aaff --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java @@ -0,0 +1,42 @@ +package com.example.umc9th.domain.mission.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.store.entity.Store; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDate; +import java.util.List; + +@Entity +@Table( + name = "mission", + indexes = { + @Index(name = "idx_mission_store", columnList = "store_id") + } +) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Mission extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id", nullable = false) + private Store store; + + @Column(nullable = false, length = 255) + private String content; + + @Column(nullable = false) + private LocalDate deadline; + + @Column(nullable = false) + private Long point; + + @Column(nullable = false) + @Builder.Default + private Boolean dbStatus = true; + + @OneToMany(mappedBy = "mission", cascade = CascadeType.ALL, orphanRemoval = true) + private List assignments; +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java new file mode 100644 index 0000000..f4c1439 --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java @@ -0,0 +1,44 @@ +package com.example.umc9th.domain.mission.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table( + name = "user_mission", + uniqueConstraints = { + @UniqueConstraint(name = "uq_user_mission", columnNames = {"user_id", "mission_id"}) + }, + indexes = { + @Index(name = "idx_um_user", columnList = "user_id"), + @Index(name = "idx_um_mission", columnList = "mission_id") + } +) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class UserMission extends BaseTime{ + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_id", nullable = false) + private Mission mission; + + @Column(name = "is_complete", nullable = false) + private Boolean isComplete = false; + + @Column(name = "complete_at") + private LocalDateTime completeAt; + + public void completeNow() { + this.isComplete = true; + this.completeAt = LocalDateTime.now(); + } +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/Review.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/Review.java new file mode 100644 index 0000000..99f301a --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/Review.java @@ -0,0 +1,32 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.store.entity.Store; +import com.example.umc9th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.util.List; + +@Entity +@Table(name="review") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Review extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="user_id", nullable=false) + private User user; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="store_id", nullable=false) + private Store store; + + @Column(nullable=false) private Integer star; + @Column(nullable=false, length=1000) private String content; + @Column(nullable=false) private Boolean dbStatus; + + @OneToMany(mappedBy="review", cascade=CascadeType.ALL, orphanRemoval=true) + private List images; + + @OneToOne(mappedBy="review", cascade=CascadeType.ALL, orphanRemoval=true, fetch=FetchType.LAZY) + private ReviewReply reply; +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java new file mode 100644 index 0000000..783a013 --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java @@ -0,0 +1,18 @@ +package com.example.umc9th.domain.review.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="review_image") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class ReviewImage { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="review_id", nullable=false) + private Review review; + + @Column(name="image_url", nullable=false, length=500) + private String imageUrl; +} diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java new file mode 100644 index 0000000..7eab41d --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java @@ -0,0 +1,19 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="review_reply") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class ReviewReply extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch=FetchType.LAZY) @JoinColumn(name="review_id", nullable=false, unique=true) + private Review review; + + @Column(nullable=false, length=1000) + private String content; +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/store/entity/Store.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/store/entity/Store.java new file mode 100644 index 0000000..ec7c75a --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/store/entity/Store.java @@ -0,0 +1,25 @@ +package com.example.umc9th.domain.store.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.user.entity.FoodCategory; +import jakarta.persistence.*; +import lombok.*; +import java.util.List; + +@Entity +@Table(name="store") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Store extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="category_id", nullable=false) + private FoodCategory category; + + @Column(nullable=false, length=100) private String name; + @Column(nullable=false, length=255) private String addr; + @Column(nullable=false) private Boolean dbStatus; + + @OneToMany(mappedBy="store", cascade=CascadeType.ALL, orphanRemoval=true) + private List images; +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/store/entity/StoreImage.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/store/entity/StoreImage.java new file mode 100644 index 0000000..c752973 --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/store/entity/StoreImage.java @@ -0,0 +1,18 @@ +package com.example.umc9th.domain.store.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="store_image") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class StoreImage { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="store_id", nullable=false) + private Store store; + + @Column(name="image_url", nullable=false, length=500) + private String imageUrl; +} \ No newline at end of file diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/FoodCategory.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/FoodCategory.java new file mode 100644 index 0000000..1f81e2b --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/FoodCategory.java @@ -0,0 +1,16 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="food_category") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class FoodCategory extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=50, unique=true) + private String name; +} diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/SocialType.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/SocialType.java new file mode 100644 index 0000000..91c738c --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/SocialType.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.user.entity; + +public enum SocialType { + KAKAO, NAVER, GOOGLE, APPLE +} diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/User.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/User.java new file mode 100644 index 0000000..19f49d0 --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/domain/user/entity/User.java @@ -0,0 +1,41 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDate; +import java.util.Set; + +@Entity +@Table(name = "`User`") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class User extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=50) private String name; + @Column(nullable=false) private Boolean sex; + @Column(nullable=false) private LocalDate birth; + @Column(nullable=false, length=255) private String addr; + + @Column(nullable=false) private Boolean userType; + @Column(nullable=false, length=255) private String socialUID; + + @Enumerated(EnumType.STRING) + @Column(nullable=false, length=10) private SocialType socialType; + + @Column(unique=true, length=100) private String email; + @Column(unique=true, length=20) private String phoneNum; + + @Column(nullable=false) private Long point; + @Column(nullable=false) private Boolean dbStatus; + + @ManyToMany + @JoinTable( + name = "user_interest", + joinColumns = @JoinColumn(name="user_id"), + inverseJoinColumns = @JoinColumn(name="food_cat_id") + ) + private Set interests; +} diff --git a/alex/week4/umc9th/src/main/java/com/example/umc9th/global/common/BaseTime.java b/alex/week4/umc9th/src/main/java/com/example/umc9th/global/common/BaseTime.java new file mode 100644 index 0000000..ce566cc --- /dev/null +++ b/alex/week4/umc9th/src/main/java/com/example/umc9th/global/common/BaseTime.java @@ -0,0 +1,21 @@ +package com.example.umc9th.global.common; + +import jakarta.persistence.*; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; +import java.time.LocalDateTime; + +@MappedSuperclass +@Getter +public abstract class BaseTime { + + @CreationTimestamp + @Column(name = "created_at", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at", nullable = false) + private LocalDateTime updatedAt; + +} diff --git a/alex/week4/umc9th/src/main/resources/application.yaml b/alex/week4/umc9th/src/main/resources/application.yaml new file mode 100644 index 0000000..d770c7b --- /dev/null +++ b/alex/week4/umc9th/src/main/resources/application.yaml @@ -0,0 +1,19 @@ +spring: + application: + name: "umc9th" + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/umc9th + username: "root" + password: "12345" + + jpa: + database: mysql + database-platform: org.hibernate.dialect.MySQLDialect + show-sql: true + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: true \ No newline at end of file diff --git a/alex/week4/umc9th/src/test/java/com/example/umc9th/Umc9thApplicationTests.java b/alex/week4/umc9th/src/test/java/com/example/umc9th/Umc9thApplicationTests.java new file mode 100644 index 0000000..bbdf1bd --- /dev/null +++ b/alex/week4/umc9th/src/test/java/com/example/umc9th/Umc9thApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.umc9th; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Umc9thApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/alex/week5/docker-compose.yaml b/alex/week5/docker-compose.yaml new file mode 100644 index 0000000..99fe59d --- /dev/null +++ b/alex/week5/docker-compose.yaml @@ -0,0 +1,24 @@ +version: "3.8" + +services: + mysql: + image: mysql:8.0 + container_name: umc9th-mysql + restart: unless-stopped + + environment: + MYSQL_ROOT_PASSWORD: "12345" + MYSQL_DATABASE: "umc9th" + TZ: "Asia/Seoul" + + ports: + - "3306:3306" + + volumes: + - ./mysql/data:/var/lib/mysql + - ./mysql/conf.d:/etc/mysql/conf.d + + command: + --character-set-server=utf8mb4 + --collation-server=utf8mb4_unicode_ci + --default-authentication-plugin=mysql_native_password diff --git a/alex/week5/umc9th/.gitattributes b/alex/week5/umc9th/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/alex/week5/umc9th/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/alex/week5/umc9th/.gitignore b/alex/week5/umc9th/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/alex/week5/umc9th/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/alex/week5/umc9th/build.gradle b/alex/week5/umc9th/build.gradle new file mode 100644 index 0000000..9355098 --- /dev/null +++ b/alex/week5/umc9th/build.gradle @@ -0,0 +1,60 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.5.7' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +description = 'umc 9th practice project' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.mysql:mysql-connector-j' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + implementation "io.github.openfeign.querydsl:querydsl-jpa:7.0" + implementation "io.github.openfeign.querydsl:querydsl-core:7.0" + implementation 'org.springframework.boot:spring-boot-starter-validation' + annotationProcessor "io.github.openfeign.querydsl:querydsl-apt:7.0:jpa" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" +} + +tasks.named('test') { + useJUnitPlatform() +} + +def querydslDir = layout.buildDirectory.dir("generated/querydsl").get().asFile + +sourceSets { + main.java.srcDirs += [ querydslDir ] +} + +tasks.withType(JavaCompile).configureEach { + options.generatedSourceOutputDirectory.set(querydslDir) +} + +clean.doLast { + file(querydslDir).deleteDir() +} \ No newline at end of file diff --git a/alex/week5/umc9th/gradle/wrapper/gradle-wrapper.jar b/alex/week5/umc9th/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..1b33c55 Binary files /dev/null and b/alex/week5/umc9th/gradle/wrapper/gradle-wrapper.jar differ diff --git a/alex/week5/umc9th/gradle/wrapper/gradle-wrapper.properties b/alex/week5/umc9th/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d4081da --- /dev/null +++ b/alex/week5/umc9th/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/alex/week5/umc9th/gradlew b/alex/week5/umc9th/gradlew new file mode 100755 index 0000000..23d15a9 --- /dev/null +++ b/alex/week5/umc9th/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH="\\\"\\\"" + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/alex/week5/umc9th/gradlew.bat b/alex/week5/umc9th/gradlew.bat new file mode 100644 index 0000000..db3a6ac --- /dev/null +++ b/alex/week5/umc9th/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH= + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/alex/week5/umc9th/settings.gradle b/alex/week5/umc9th/settings.gradle new file mode 100644 index 0000000..0ec607f --- /dev/null +++ b/alex/week5/umc9th/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'umc9th' diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/Umc9thApplication.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/Umc9thApplication.java new file mode 100644 index 0000000..cf0063f --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/Umc9thApplication.java @@ -0,0 +1,13 @@ +package com.example.umc9th; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Umc9thApplication { + + public static void main(String[] args) { + SpringApplication.run(Umc9thApplication.class, args); + } + +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/Agreement.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/Agreement.java new file mode 100644 index 0000000..92c5d10 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/Agreement.java @@ -0,0 +1,17 @@ +package com.example.umc9th.domain.agreement.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="agreement") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Agreement extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=1000) + private String content; +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/UserAgreement.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/UserAgreement.java new file mode 100644 index 0000000..67e750f --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/agreement/entity/UserAgreement.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.agreement.entity; + +import com.example.umc9th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table(name="user_agreement", + uniqueConstraints = @UniqueConstraint(name="uq_user_agreement", columnNames={"user_id","agreement_id"})) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class UserAgreement { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="user_id", nullable=false) + private User user; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="agreement_id", nullable=false) + private Agreement agreement; + + @Column(nullable=false) private Boolean isAgreed; + private LocalDateTime agreedAt; +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java new file mode 100644 index 0000000..d99aaff --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java @@ -0,0 +1,42 @@ +package com.example.umc9th.domain.mission.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.store.entity.Store; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDate; +import java.util.List; + +@Entity +@Table( + name = "mission", + indexes = { + @Index(name = "idx_mission_store", columnList = "store_id") + } +) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Mission extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id", nullable = false) + private Store store; + + @Column(nullable = false, length = 255) + private String content; + + @Column(nullable = false) + private LocalDate deadline; + + @Column(nullable = false) + private Long point; + + @Column(nullable = false) + @Builder.Default + private Boolean dbStatus = true; + + @OneToMany(mappedBy = "mission", cascade = CascadeType.ALL, orphanRemoval = true) + private List assignments; +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java new file mode 100644 index 0000000..2e5c224 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java @@ -0,0 +1,45 @@ +package com.example.umc9th.domain.mission.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table( + name = "user_mission", + uniqueConstraints = { + @UniqueConstraint(name = "uq_user_mission", columnNames = {"user_id", "mission_id"}) + }, + indexes = { + @Index(name = "idx_um_user", columnList = "user_id"), + @Index(name = "idx_um_mission", columnList = "mission_id") + } +) +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class UserMission extends BaseTime{ + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_id", nullable = false) + private Mission mission; + + @Column(name = "is_complete", nullable = false) + @Builder.Default + private Boolean isComplete = false; + + @Column(name = "complete_at") + private LocalDateTime completeAt; + + public void completeNow() { + this.isComplete = true; + this.completeAt = LocalDateTime.now(); + } +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/repository/UserMissionRepository.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/repository/UserMissionRepository.java new file mode 100644 index 0000000..d251c43 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/mission/repository/UserMissionRepository.java @@ -0,0 +1,52 @@ +package com.example.umc9th.domain.mission.repository; + +import com.example.umc9th.domain.mission.entity.Mission; +import com.example.umc9th.domain.mission.entity.UserMission; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Repository; + + +@Repository +public interface UserMissionRepository extends JpaRepository { + + // 미션화면 + // 내가 진행중, 진행 완료한 미션 모아서 보는 쿼리(페이징 포함) + @Query(""" + SELECT m + FROM UserMission um + JOIN um.mission m + WHERE um.user.id = :userId + AND um.isComplete = :isComplete + AND (:lastId IS NULL OR m.id < :lastId) + ORDER BY m.id DESC + """) + Slice findMissionsByIdAll( + @Param("userId") Long userId, + @Param("isComplete") Boolean isComplete, + @Param("lastId") Long lastId, + Pageable pageable + ); + + // 홈 화면 쿼리 + // (현재 선택 된 지역에서 도전이 가능한 미션 목록, 페이징 포함) + @Query(value = """ + SELECT um + FROM UserMission um + JOIN FETCH um.mission m + JOIN FETCH m.store s + JOIN FETCH s.category fc + WHERE um.isComplete = false + AND s.addr = :address + AND um.user.id = :userId + ORDER BY um.completeAt DESC + """) + Slice findMyMissionsAsEntity( + @Param("userId") Long userId, + @Param("address") String address, + Pageable pageable + ); +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/controller/ReviewController.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/controller/ReviewController.java new file mode 100644 index 0000000..76efec5 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/controller/ReviewController.java @@ -0,0 +1,49 @@ +package com.example.umc9th.domain.review.controller; + +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.review.service.ReviewService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.ResponseEntity; + +import com.example.umc9th.domain.review.dto.ReviewResponse; +import com.example.umc9th.global.apiPayload.code.GeneralSuccessCode; +import com.example.umc9th.global.apiPayload.ApiResponse; +import com.example.umc9th.domain.review.dto.ReviewRequestCreate; + +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.ArrayList; +import java.util.List; + + +@RestController +@RequestMapping("/api/v1/reviews") +@RequiredArgsConstructor +public class ReviewController { + + private final ReviewService reviewService; + + @PostMapping + public ApiResponse Create( + @Valid @RequestBody ReviewRequestCreate request + ) { + ReviewResponse resp = reviewService.createReview(request); + return ApiResponse.onSuccess(GeneralSuccessCode.CREATE, resp); + } + + // @GetMapping + // public ApiResponse Search( + // @RequestParam Long userId, + // @RequestParam Long storeId + // ) { + // ReviewResponse resp = reviewService.findbyStore(); + // return ApiResponse.onSuccess(GeneralSuccessCode.GOOD_REQUEST, resp); + // } + +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/dto/ReviewRequestCreate.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/dto/ReviewRequestCreate.java new file mode 100644 index 0000000..c5de120 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/dto/ReviewRequestCreate.java @@ -0,0 +1,15 @@ +package com.example.umc9th.domain.review.dto; + +import jakarta.validation.constraints.*; +import java.util.List; + +public record ReviewRequestCreate( + @NotNull @Min(0) + Long userId, + @NotNull @Min(0) + Long storeId, + @NotBlank + String content, + @NotNull + Float star +) {} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/dto/ReviewResponse.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/dto/ReviewResponse.java new file mode 100644 index 0000000..d643664 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/dto/ReviewResponse.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.review.dto; + +public record ReviewResponse( + Long reviewId, + Long userId, + Long storeId, + String storeName, + String content, + Float star +) {} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/Review.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/Review.java new file mode 100644 index 0000000..c6c38c7 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/Review.java @@ -0,0 +1,34 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.store.entity.Store; +import com.example.umc9th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.util.List; + +@Entity +@Table(name="review") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Review extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="user_id", nullable=false) + private User user; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="store_id", nullable=false) + private Store store; + + @Column(nullable=false) private Float star; + @Column(nullable=false, length=1000) private String content; + @Column(nullable=false) private Boolean dbStatus; + + @OneToMany(mappedBy="review", cascade=CascadeType.ALL, orphanRemoval=true) + private List images; + + @OneToOne(mappedBy="review", cascade=CascadeType.ALL, orphanRemoval=true, fetch=FetchType.LAZY) + private ReviewReply reply; + +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java new file mode 100644 index 0000000..783a013 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java @@ -0,0 +1,18 @@ +package com.example.umc9th.domain.review.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="review_image") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class ReviewImage { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="review_id", nullable=false) + private Review review; + + @Column(name="image_url", nullable=false, length=500) + private String imageUrl; +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java new file mode 100644 index 0000000..7eab41d --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java @@ -0,0 +1,19 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="review_reply") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class ReviewReply extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch=FetchType.LAZY) @JoinColumn(name="review_id", nullable=false, unique=true) + private Review review; + + @Column(nullable=false, length=1000) + private String content; +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDsl.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDsl.java new file mode 100644 index 0000000..792a039 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDsl.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.review.repository; + +import com.example.umc9th.domain.review.entity.Review; +import com.querydsl.core.types.Predicate; +import java.util.List; + +public interface ReviewQueryDsl { + List searchReviewByStore(Predicate predicate); +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDslImpl.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDslImpl.java new file mode 100644 index 0000000..c53a6b4 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDslImpl.java @@ -0,0 +1,32 @@ +package com.example.umc9th.domain.review.repository; + +import com.example.umc9th.domain.review.entity.QReview; +import com.example.umc9th.domain.review.entity.Review; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +@RequiredArgsConstructor +public class ReviewQueryDslImpl implements ReviewQueryDsl { + + private final EntityManager em; + + @Override + public List searchReviewByStore(Predicate predicate) { + + JPAQueryFactory queryFactory = new JPAQueryFactory(em); + QReview review = QReview.review; + + return queryFactory + .selectFrom(review) + .leftJoin(review.store).fetchJoin() + .leftJoin(review.user).fetchJoin() + .where(predicate) + .orderBy(review.createdAt.desc()) //최근에 작성된 리뷰를 먼저 봄. + .fetch(); + } + +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepository.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepository.java new file mode 100644 index 0000000..1594251 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepository.java @@ -0,0 +1,11 @@ +package com.example.umc9th.domain.review.repository; + +import com.example.umc9th.domain.review.entity.Review; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface ReviewRepository extends JpaRepository, ReviewQueryDsl { + +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/service/ReviewService.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/service/ReviewService.java new file mode 100644 index 0000000..3dbe0e8 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/service/ReviewService.java @@ -0,0 +1,11 @@ +package com.example.umc9th.domain.review.service; + +import java.util.List; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.review.dto.ReviewResponse; +import com.example.umc9th.domain.review.dto.ReviewRequestCreate; + +public interface ReviewService { + + ReviewResponse createReview(ReviewRequestCreate reqeust); +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/service/ReviewServiceImpl.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/service/ReviewServiceImpl.java new file mode 100644 index 0000000..25f1609 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/review/service/ReviewServiceImpl.java @@ -0,0 +1,113 @@ +package com.example.umc9th.domain.review.service; + +import com.example.umc9th.domain.review.entity.QReview; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.review.repository.ReviewRepository; +import com.example.umc9th.domain.review.dto.ReviewRequestCreate; +import com.example.umc9th.global.apiPayload.exception.GeneralException; +import com.example.umc9th.global.apiPayload.code.GeneralErrorCode; +import com.example.umc9th.domain.review.dto.ReviewResponse; +import com.querydsl.core.BooleanBuilder; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import jakarta.transaction.Transactional; + +import com.example.umc9th.domain.user.entity.User; +import com.example.umc9th.domain.store.entity.Store; +import com.example.umc9th.domain.store.repository.StoreRepository; +import com.example.umc9th.domain.user.repository.UserRepository; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ReviewServiceImpl implements ReviewService{ + + private final ReviewRepository reviewRepository; + + private final StoreRepository storeRepository; + private final UserRepository userRepository; + + + + @Transactional + public ReviewResponse createReview(ReviewRequestCreate request) { + + User user = userRepository.findById(request.userId()) + .orElseThrow(() -> new GeneralException(GeneralErrorCode.INVALID_DATA)); + + Store store = storeRepository.findById(request.storeId()) + .orElseThrow(() -> new GeneralException(GeneralErrorCode.INVALID_DATA)); + + Review review = Review.builder() + .user(user) + .store(store) + .star(request.star()) + .content(request.content()) + .dbStatus(true) + .build(); + + Review saved = reviewRepository.save(review); + + return toResponse(review); + } + + private ReviewResponse toResponse(Review review) { + + return new ReviewResponse( + review.getId(), + review.getUser().getId(), + review.getStore().getId(), + review.getStore().getName(), + review.getContent(), + review.getStar() + ); + } + + + // public String queryTest(String name) { + // QReview review = QReview.review; + // BooleanBuilder builder = new BooleanBuilder(); + + // if (name != null) { + // builder.and(review.user.name.eq(name)); + // } + + // List reviewList = reviewRepository.searchReview(builder); + // return reviewList.toString(); + // } + + // public List searchReview(String query, String type) { + // QReview review = QReview.review; + // BooleanBuilder builder = new BooleanBuilder(); + + // if ("location".equals(type)) { + // builder.and(review.store.addr.contains(query)); + // } else if ("star".equals(type)) { + // builder.and(review.star.goe(Integer.parseInt(query))); + // } else if ("both".equals(type)) { + // String[] parts = query.split("&"); + // builder.and(review.store.addr.contains(parts[0])); + // builder.and(review.star.goe(Integer.parseInt(parts[1]))); + // } + + // return reviewRepository.searchReview(builder); + // } + + // public List getMyReviews(long userId, String storeName, Integer star) { + // QReview review = QReview.review; + // BooleanBuilder builder = new BooleanBuilder(); + + // builder.and(review.user.id.eq(userId)); + + + // if (storeName != null && !storeName.isEmpty()) { + // builder.and(review.store.name.containsIgnoreCase(storeName)); + // } + + // if (star != null) { + // builder.and(review.star.goe(star)); + // } + + // return reviewRepository.searchReview(builder); + // } +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/entity/Store.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/entity/Store.java new file mode 100644 index 0000000..ec7c75a --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/entity/Store.java @@ -0,0 +1,25 @@ +package com.example.umc9th.domain.store.entity; + +import com.example.umc9th.global.common.BaseTime; +import com.example.umc9th.domain.user.entity.FoodCategory; +import jakarta.persistence.*; +import lombok.*; +import java.util.List; + +@Entity +@Table(name="store") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class Store extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="category_id", nullable=false) + private FoodCategory category; + + @Column(nullable=false, length=100) private String name; + @Column(nullable=false, length=255) private String addr; + @Column(nullable=false) private Boolean dbStatus; + + @OneToMany(mappedBy="store", cascade=CascadeType.ALL, orphanRemoval=true) + private List images; +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/entity/StoreImage.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/entity/StoreImage.java new file mode 100644 index 0000000..c752973 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/entity/StoreImage.java @@ -0,0 +1,18 @@ +package com.example.umc9th.domain.store.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="store_image") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class StoreImage { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="store_id", nullable=false) + private Store store; + + @Column(name="image_url", nullable=false, length=500) + private String imageUrl; +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/repository/StoreQueryDsl.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/repository/StoreQueryDsl.java new file mode 100644 index 0000000..0732221 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/repository/StoreQueryDsl.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.store.repository; + +public interface StoreQueryDsl { +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/repository/StoreRepository.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/repository/StoreRepository.java new file mode 100644 index 0000000..19dd835 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/store/repository/StoreRepository.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.store.repository; + +import com.example.umc9th.domain.store.entity.Store; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface StoreRepository extends JpaRepository, StoreQueryDsl { + +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/FoodCategory.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/FoodCategory.java new file mode 100644 index 0000000..1f81e2b --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/FoodCategory.java @@ -0,0 +1,16 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name="food_category") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class FoodCategory extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=50, unique=true) + private String name; +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/SocialType.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/SocialType.java new file mode 100644 index 0000000..91c738c --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/SocialType.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.user.entity; + +public enum SocialType { + KAKAO, NAVER, GOOGLE, APPLE +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/User.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/User.java new file mode 100644 index 0000000..19f49d0 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/entity/User.java @@ -0,0 +1,41 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.global.common.BaseTime; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDate; +import java.util.Set; + +@Entity +@Table(name = "`User`") +@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder +public class User extends BaseTime { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable=false, length=50) private String name; + @Column(nullable=false) private Boolean sex; + @Column(nullable=false) private LocalDate birth; + @Column(nullable=false, length=255) private String addr; + + @Column(nullable=false) private Boolean userType; + @Column(nullable=false, length=255) private String socialUID; + + @Enumerated(EnumType.STRING) + @Column(nullable=false, length=10) private SocialType socialType; + + @Column(unique=true, length=100) private String email; + @Column(unique=true, length=20) private String phoneNum; + + @Column(nullable=false) private Long point; + @Column(nullable=false) private Boolean dbStatus; + + @ManyToMany + @JoinTable( + name = "user_interest", + joinColumns = @JoinColumn(name="user_id"), + inverseJoinColumns = @JoinColumn(name="food_cat_id") + ) + private Set interests; +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/repository/UserQueryDsl.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/repository/UserQueryDsl.java new file mode 100644 index 0000000..b561713 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/repository/UserQueryDsl.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.user.repository; + +public interface UserQueryDsl { +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/repository/UserRepository.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/repository/UserRepository.java new file mode 100644 index 0000000..3f56a61 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/domain/user/repository/UserRepository.java @@ -0,0 +1,11 @@ +package com.example.umc9th.domain.user.repository; + +import com.example.umc9th.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends JpaRepository, UserQueryDsl{ + +} + diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/ApiResponse.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/ApiResponse.java new file mode 100644 index 0000000..a3b0896 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/ApiResponse.java @@ -0,0 +1,36 @@ +package com.example.umc9th.global.apiPayload; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@JsonPropertyOrder({"isSuccess", "code", "message", "result"}) +public class ApiResponse { + + @JsonProperty("isSuccess") + private final Boolean isSuccess; + + @JsonProperty("code") + private final String code; + + @JsonProperty("message") + private final String message; + + @JsonProperty("result") + private T result; + + // 성공한 경우 (result 포함) + public static ApiResponse onSuccess(BaseErrorCode code, T result) { + return new ApiResponse<>(true, code.getCode(), code.getMessage(), result); + } + + // 실패한 경우 (result 포함) + public static ApiResponse onFailure(BaseErrorCode code, T result) { + return new ApiResponse<>(false, code.getCode(), code.getMessage(), result); + } +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/BaseErrorCode.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/BaseErrorCode.java new file mode 100644 index 0000000..d0d553f --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/BaseErrorCode.java @@ -0,0 +1,10 @@ +package com.example.umc9th.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseErrorCode { + + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/BaseSuccessCode.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/BaseSuccessCode.java new file mode 100644 index 0000000..fb269df --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/BaseSuccessCode.java @@ -0,0 +1,10 @@ +package com.example.umc9th.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseSuccessCode { + + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralErrorCode.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralErrorCode.java new file mode 100644 index 0000000..aa2ee70 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralErrorCode.java @@ -0,0 +1,40 @@ +package com.example.umc9th.global.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum GeneralErrorCode implements BaseErrorCode { + + BAD_REQUEST(HttpStatus.BAD_REQUEST, + "COMMON400_1", + "잘못된 요청입니다."), + + INVALID_DATA(HttpStatus.BAD_REQUEST, + "COMMON4001_2", + "유효하지 않은 데이터입니다."), + + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, + "COMMON401_1", + "인증이 필요합니다."), + + FORBIDDEN(HttpStatus.FORBIDDEN, + "COMMON403_1", + "접근 권한이 없습니다."), + + NOT_FOUND(HttpStatus.NOT_FOUND, + "COMMON404_1", + "요청한 리소스를 찾을 수 없습니다."), + + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, + "COMMON500_1", + "서버 내부 오류가 발생했습니다."), + ; + + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralSuccessCode.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralSuccessCode.java new file mode 100644 index 0000000..6f2ec9b --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralSuccessCode.java @@ -0,0 +1,31 @@ +package com.example.umc9th.global.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum GeneralSuccessCode implements BaseErrorCode { + + GOOD_REQUEST(HttpStatus.OK, + "COMMON200_1", + "정상적인 요청입니다."), + AUTHORIZED(HttpStatus.CREATED, + "AUTH201_1", + "인증이 확인되었습니다."), + CREATE(HttpStatus.CREATED, + "CREATE200_1", + "성공적으로 생성되었습니다."), + ALLOWED(HttpStatus.ACCEPTED, + "AUTH203_1", + "요청이 허용되었습니다."), + FOUND(HttpStatus.FOUND, + "COMMON302_1", + "요청한 리소스를 찾았습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/exception/GeneralException.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/exception/GeneralException.java new file mode 100644 index 0000000..d54216b --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/exception/GeneralException.java @@ -0,0 +1,20 @@ +package com.example.umc9th.global.apiPayload.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.Getter; + +@Getter +public class GeneralException extends RuntimeException { + + private final BaseErrorCode errorCode; + + public GeneralException(BaseErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } + + public GeneralException(BaseErrorCode errorCode, Throwable cause) { + super(errorCode.getMessage(), cause); + this.errorCode = errorCode; + } +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/exception/GlobalExceptionHandler.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..18af8ed --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/exception/GlobalExceptionHandler.java @@ -0,0 +1,56 @@ +package com.example.umc9th.global.apiPayload.exception; + +import com.example.umc9th.global.apiPayload.ApiResponse; +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.code.GeneralErrorCode; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(GeneralException.class) + public ResponseEntity> handleGeneralException(GeneralException e) { + + BaseErrorCode errorCode = e.getErrorCode(); + + log.warn("[GeneralException] {} - {}", errorCode.getCode(), errorCode.getMessage()); + + return ResponseEntity + .status(errorCode.getStatus()) + .body(ApiResponse.onFailure(errorCode, null)); + } + + @ExceptionHandler(IllegalArgumentException.class) + public ResponseEntity> handleIllegalArgument(IllegalArgumentException e) { + + log.warn("[IllegalArgumentException] {}", e.getMessage()); + + return ResponseEntity + .status(GeneralErrorCode.BAD_REQUEST.getStatus()) + .body(ApiResponse.onFailure(GeneralErrorCode.BAD_REQUEST, null)); + } + + @ExceptionHandler(SecurityException.class) + public ResponseEntity> handleSecurityException(SecurityException e) { + + log.warn("[SecurityException] {}", e.getMessage()); + + return ResponseEntity + .status(GeneralErrorCode.UNAUTHORIZED.getStatus()) + .body(ApiResponse.onFailure(GeneralErrorCode.UNAUTHORIZED, null)); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity> handleUnexpectedException(Exception e) { + + log.error("[UnexpectedException]", e); + + return ResponseEntity + .status(GeneralErrorCode.INTERNAL_SERVER_ERROR.getStatus()) + .body(ApiResponse.onFailure(GeneralErrorCode.INTERNAL_SERVER_ERROR, null)); + } +} \ No newline at end of file diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/handler/GeneralExceptionAdvice.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/handler/GeneralExceptionAdvice.java new file mode 100644 index 0000000..7e78339 --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/apiPayload/handler/GeneralExceptionAdvice.java @@ -0,0 +1,42 @@ +package com.example.umc9th.global.apiPayload.handler; + +import com.example.umc9th.global.apiPayload.ApiResponse; +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.code.GeneralErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GeneralExceptionAdvice { + + @ExceptionHandler(GeneralException.class) + public ResponseEntity> handleGeneralException(GeneralException ex) { + + BaseErrorCode errorCode = ex.getErrorCode(); + + // 추가 로깅이나 모니터링 훅도 가능 + // log.warn("[GeneralException] {} - {}", errorCode.getCode(), errorCode.getMessage()); + + return ResponseEntity + .status(errorCode.getStatus()) + .body(ApiResponse.onFailure(errorCode, null)); + } + + @ExceptionHandler({IllegalArgumentException.class, IllegalStateException.class}) + public ResponseEntity> handleBadRequest(RuntimeException ex) { + BaseErrorCode code = GeneralErrorCode.BAD_REQUEST; + return ResponseEntity + .status(code.getStatus()) + .body(ApiResponse.onFailure(code, ex.getMessage())); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity> handleUnexpectedException(Exception ex) { + BaseErrorCode code = GeneralErrorCode.INTERNAL_SERVER_ERROR; + return ResponseEntity + .status(code.getStatus()) + .body(ApiResponse.onFailure(code, ex.getMessage())); + } +} diff --git a/alex/week5/umc9th/src/main/java/com/example/umc9th/global/common/BaseTime.java b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/common/BaseTime.java new file mode 100644 index 0000000..ce566cc --- /dev/null +++ b/alex/week5/umc9th/src/main/java/com/example/umc9th/global/common/BaseTime.java @@ -0,0 +1,21 @@ +package com.example.umc9th.global.common; + +import jakarta.persistence.*; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; +import java.time.LocalDateTime; + +@MappedSuperclass +@Getter +public abstract class BaseTime { + + @CreationTimestamp + @Column(name = "created_at", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at", nullable = false) + private LocalDateTime updatedAt; + +} diff --git a/alex/week5/umc9th/src/main/resources/application.yaml b/alex/week5/umc9th/src/main/resources/application.yaml new file mode 100644 index 0000000..d770c7b --- /dev/null +++ b/alex/week5/umc9th/src/main/resources/application.yaml @@ -0,0 +1,19 @@ +spring: + application: + name: "umc9th" + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/umc9th + username: "root" + password: "12345" + + jpa: + database: mysql + database-platform: org.hibernate.dialect.MySQLDialect + show-sql: true + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: true \ No newline at end of file diff --git a/alex/week5/umc9th/src/test/java/com/example/umc9th/Umc9thApplicationTests.java b/alex/week5/umc9th/src/test/java/com/example/umc9th/Umc9thApplicationTests.java new file mode 100644 index 0000000..bbdf1bd --- /dev/null +++ b/alex/week5/umc9th/src/test/java/com/example/umc9th/Umc9thApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.umc9th; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Umc9thApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/test.sh b/test.sh deleted file mode 100644 index e69de29..0000000