From 5758a2d32e2885032b9a5966bbd5795ad5cf34b2 Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:27:42 +0900 Subject: [PATCH 1/7] =?UTF-8?q?:sparkles:=20Practice(#6)=20:=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring/build.gradle | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spring/build.gradle b/spring/build.gradle index 179c9ba..9b4ee2b 100644 --- a/spring/build.gradle +++ b/spring/build.gradle @@ -2,6 +2,8 @@ plugins { id 'java' id 'org.springframework.boot' version '3.3.4' id 'io.spring.dependency-management' version '1.1.6' + id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" + id 'antlr' } group = 'umc' @@ -31,8 +33,46 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // queryDSL + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" } +sourceSets { + main { + java { + srcDirs = ['src/main/java', 'src/main/resources', 'src/main/generated'] + } + } +} + + tasks.named('test') { useJUnitPlatform() } + +// Querydsl 설정부 +def generated = 'src/main/generated' + +querydsl { + jpa = true + querydslSourcesDir = generated +} + +sourceSets { + main.java.srcDir generated +} + +compileQuerydsl{ + options.annotationProcessorPath = configurations.querydsl +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } + querydsl.extendsFrom compileClasspath +} From 96fb51fcf01a30737df03c5dcec3d85aa5e1666e Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:29:11 +0900 Subject: [PATCH 2/7] =?UTF-8?q?:recycle:=20Practice(#6)=20:=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/umc/spring/domain/Region.java | 22 ++++++++++++++ .../java/umc/spring/domain/Restaurant.java | 29 ++++++++++++++++++- .../main/java/umc/spring/domain/Review.java | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 spring/src/main/java/umc/spring/domain/Region.java diff --git a/spring/src/main/java/umc/spring/domain/Region.java b/spring/src/main/java/umc/spring/domain/Region.java new file mode 100644 index 0000000..b1e1ed6 --- /dev/null +++ b/spring/src/main/java/umc/spring/domain/Region.java @@ -0,0 +1,22 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import lombok.*; + +import umc.spring.domain.common.BaseEntity; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Table(uniqueConstraints = {@UniqueConstraint(columnNames = "name")}) +public class Region extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "region_id") + private Long id; + + @Column(nullable = false, length = 20) + private String name; +} diff --git a/spring/src/main/java/umc/spring/domain/Restaurant.java b/spring/src/main/java/umc/spring/domain/Restaurant.java index 7b98a4a..d806446 100644 --- a/spring/src/main/java/umc/spring/domain/Restaurant.java +++ b/spring/src/main/java/umc/spring/domain/Restaurant.java @@ -4,6 +4,9 @@ import lombok.*; import umc.spring.domain.common.BaseEntity; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @@ -19,11 +22,14 @@ public class Restaurant extends BaseEntity{ @Column(nullable = false, length = 255) private String name; - @Column(nullable = false, length = 100) + @Column(length = 100) private String category; private Float score; + @Column(length = 100) + private String address; + @Column(length = 100) private String addressBig; //시 @@ -32,4 +38,25 @@ public class Restaurant extends BaseEntity{ @Column(length = 100) private String addressSmall; //동 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(nullable = false, name = "region_id") + private Region region; + + @OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL) + private List missionList = new ArrayList<>(); + + @OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL) + private List reviewList = new ArrayList<>(); + + @Override + public String toString() { + return "Restaurant{" + + "id=" + id + + ", name='" + name + '\'' + + ", address='" + address + '\'' + + ", score=" + score + + ", region=" + (region != null ? region.getName() : "N/A") + // region의 이름 출력 + '}'; + } } diff --git a/spring/src/main/java/umc/spring/domain/Review.java b/spring/src/main/java/umc/spring/domain/Review.java index 3db1eed..b24ccff 100644 --- a/spring/src/main/java/umc/spring/domain/Review.java +++ b/spring/src/main/java/umc/spring/domain/Review.java @@ -16,7 +16,7 @@ public class Review extends BaseEntity{ @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false, length = 200) + @Column(length = 200) private String title; private Float rate; From 7cb24dbef83e32a859a073b4b0beb9befa9d755b Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:30:25 +0900 Subject: [PATCH 3/7] =?UTF-8?q?:sparkles:=20Practice(#6)=20:=20Q=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generated/umc/spring/domain/QComment.java | 64 +++++++++++++++ .../umc/spring/domain/QFavoriteFood.java | 61 +++++++++++++++ .../generated/umc/spring/domain/QMember.java | 65 ++++++++++++++++ .../generated/umc/spring/domain/QMission.java | 65 ++++++++++++++++ .../generated/umc/spring/domain/QRegion.java | 47 +++++++++++ .../umc/spring/domain/QRestaurant.java | 77 +++++++++++++++++++ .../umc/spring/domain/QRestaurantImg.java | 61 +++++++++++++++ .../generated/umc/spring/domain/QReview.java | 68 ++++++++++++++++ .../umc/spring/domain/common/QBaseEntity.java | 39 ++++++++++ .../domain/mapping/QMemberFavoriteFood.java | 62 +++++++++++++++ .../spring/domain/mapping/QMemberMission.java | 64 +++++++++++++++ 11 files changed, 673 insertions(+) create mode 100644 spring/src/main/generated/umc/spring/domain/QComment.java create mode 100644 spring/src/main/generated/umc/spring/domain/QFavoriteFood.java create mode 100644 spring/src/main/generated/umc/spring/domain/QMember.java create mode 100644 spring/src/main/generated/umc/spring/domain/QMission.java create mode 100644 spring/src/main/generated/umc/spring/domain/QRegion.java create mode 100644 spring/src/main/generated/umc/spring/domain/QRestaurant.java create mode 100644 spring/src/main/generated/umc/spring/domain/QRestaurantImg.java create mode 100644 spring/src/main/generated/umc/spring/domain/QReview.java create mode 100644 spring/src/main/generated/umc/spring/domain/common/QBaseEntity.java create mode 100644 spring/src/main/generated/umc/spring/domain/mapping/QMemberFavoriteFood.java create mode 100644 spring/src/main/generated/umc/spring/domain/mapping/QMemberMission.java diff --git a/spring/src/main/generated/umc/spring/domain/QComment.java b/spring/src/main/generated/umc/spring/domain/QComment.java new file mode 100644 index 0000000..5134a42 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QComment.java @@ -0,0 +1,64 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QComment is a Querydsl query type for Comment + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QComment extends EntityPathBase { + + private static final long serialVersionUID = -572500941L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QComment comment = new QComment("comment"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + public final StringPath content = createString("content"); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final NumberPath id = createNumber("id", Long.class); + + public final QMember member; + + public final QReview review; + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QComment(String variable) { + this(Comment.class, forVariable(variable), INITS); + } + + public QComment(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QComment(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QComment(PathMetadata metadata, PathInits inits) { + this(Comment.class, metadata, inits); + } + + public QComment(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.member = inits.isInitialized("member") ? new QMember(forProperty("member")) : null; + this.review = inits.isInitialized("review") ? new QReview(forProperty("review"), inits.get("review")) : null; + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/QFavoriteFood.java b/spring/src/main/generated/umc/spring/domain/QFavoriteFood.java new file mode 100644 index 0000000..c29aee7 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QFavoriteFood.java @@ -0,0 +1,61 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QFavoriteFood is a Querydsl query type for FavoriteFood + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QFavoriteFood extends EntityPathBase { + + private static final long serialVersionUID = 1905081030L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QFavoriteFood favoriteFood = new QFavoriteFood("favoriteFood"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final EnumPath food = createEnum("food", umc.spring.domain.enums.Food.class); + + public final NumberPath id = createNumber("id", Long.class); + + public final QMember member; + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QFavoriteFood(String variable) { + this(FavoriteFood.class, forVariable(variable), INITS); + } + + public QFavoriteFood(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QFavoriteFood(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QFavoriteFood(PathMetadata metadata, PathInits inits) { + this(FavoriteFood.class, metadata, inits); + } + + public QFavoriteFood(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.member = inits.isInitialized("member") ? new QMember(forProperty("member")) : null; + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/QMember.java b/spring/src/main/generated/umc/spring/domain/QMember.java new file mode 100644 index 0000000..353cd24 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QMember.java @@ -0,0 +1,65 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QMember is a Querydsl query type for Member + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QMember extends EntityPathBase { + + private static final long serialVersionUID = 1366956614L; + + public static final QMember member = new QMember("member1"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + public final StringPath address = createString("address"); + + public final StringPath birth = createString("birth"); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final StringPath email = createString("email"); + + public final EnumPath gender = createEnum("gender", umc.spring.domain.enums.Gender.class); + + public final NumberPath id = createNumber("id", Long.class); + + public final DatePath inactiveDate = createDate("inactiveDate", java.time.LocalDate.class); + + public final StringPath name = createString("name"); + + public final NumberPath point = createNumber("point", Long.class); + + public final EnumPath socialType = createEnum("socialType", umc.spring.domain.enums.SocialType.class); + + public final EnumPath status = createEnum("status", umc.spring.domain.enums.MemberStatus.class); + + public final StringPath tel = createString("tel"); + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QMember(String variable) { + super(Member.class, forVariable(variable)); + } + + public QMember(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QMember(PathMetadata metadata) { + super(Member.class, metadata); + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/QMission.java b/spring/src/main/generated/umc/spring/domain/QMission.java new file mode 100644 index 0000000..183bb6e --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QMission.java @@ -0,0 +1,65 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QMission is a Querydsl query type for Mission + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QMission extends EntityPathBase { + + private static final long serialVersionUID = -453449888L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QMission mission = new QMission("mission"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + public final StringPath content = createString("content"); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final DatePath deadline = createDate("deadline", java.time.LocalDate.class); + + public final NumberPath id = createNumber("id", Long.class); + + public final NumberPath missionPoint = createNumber("missionPoint", Integer.class); + + public final QRestaurant restaurant; + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QMission(String variable) { + this(Mission.class, forVariable(variable), INITS); + } + + public QMission(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QMission(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QMission(PathMetadata metadata, PathInits inits) { + this(Mission.class, metadata, inits); + } + + public QMission(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.restaurant = inits.isInitialized("restaurant") ? new QRestaurant(forProperty("restaurant")) : null; + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/QRegion.java b/spring/src/main/generated/umc/spring/domain/QRegion.java new file mode 100644 index 0000000..1d2445e --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QRegion.java @@ -0,0 +1,47 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QRegion is a Querydsl query type for Region + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QRegion extends EntityPathBase { + + private static final long serialVersionUID = 1509930656L; + + public static final QRegion region = new QRegion("region"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath name = createString("name"); + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QRegion(String variable) { + super(Region.class, forVariable(variable)); + } + + public QRegion(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QRegion(PathMetadata metadata) { + super(Region.class, metadata); + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/QRestaurant.java b/spring/src/main/generated/umc/spring/domain/QRestaurant.java new file mode 100644 index 0000000..51c4614 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QRestaurant.java @@ -0,0 +1,77 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QRestaurant is a Querydsl query type for Restaurant + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QRestaurant extends EntityPathBase { + + private static final long serialVersionUID = 1563043049L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QRestaurant restaurant = new QRestaurant("restaurant"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + public final StringPath address = createString("address"); + + public final StringPath addressBig = createString("addressBig"); + + public final StringPath addressMiddle = createString("addressMiddle"); + + public final StringPath addressSmall = createString("addressSmall"); + + public final StringPath category = createString("category"); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final NumberPath id = createNumber("id", Long.class); + + public final ListPath missionList = this.createList("missionList", Mission.class, QMission.class, PathInits.DIRECT2); + + public final StringPath name = createString("name"); + + public final QRegion region; + + public final ListPath reviewList = this.createList("reviewList", Review.class, QReview.class, PathInits.DIRECT2); + + public final NumberPath score = createNumber("score", Float.class); + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QRestaurant(String variable) { + this(Restaurant.class, forVariable(variable), INITS); + } + + public QRestaurant(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QRestaurant(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QRestaurant(PathMetadata metadata, PathInits inits) { + this(Restaurant.class, metadata, inits); + } + + public QRestaurant(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.region = inits.isInitialized("region") ? new QRegion(forProperty("region")) : null; + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/QRestaurantImg.java b/spring/src/main/generated/umc/spring/domain/QRestaurantImg.java new file mode 100644 index 0000000..855e070 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QRestaurantImg.java @@ -0,0 +1,61 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QRestaurantImg is a Querydsl query type for RestaurantImg + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QRestaurantImg extends EntityPathBase { + + private static final long serialVersionUID = -1419876838L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QRestaurantImg restaurantImg = new QRestaurantImg("restaurantImg"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath imgKey = createString("imgKey"); + + public final QRestaurant restaurant; + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QRestaurantImg(String variable) { + this(RestaurantImg.class, forVariable(variable), INITS); + } + + public QRestaurantImg(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QRestaurantImg(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QRestaurantImg(PathMetadata metadata, PathInits inits) { + this(RestaurantImg.class, metadata, inits); + } + + public QRestaurantImg(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.restaurant = inits.isInitialized("restaurant") ? new QRestaurant(forProperty("restaurant")) : null; + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/QReview.java b/spring/src/main/generated/umc/spring/domain/QReview.java new file mode 100644 index 0000000..e780891 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/QReview.java @@ -0,0 +1,68 @@ +package umc.spring.domain; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QReview is a Querydsl query type for Review + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QReview extends EntityPathBase { + + private static final long serialVersionUID = 1510377220L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QReview review = new QReview("review"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + public final StringPath content = createString("content"); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final NumberPath id = createNumber("id", Long.class); + + public final QMember member; + + public final NumberPath rate = createNumber("rate", Float.class); + + public final QRestaurant restaurant; + + public final StringPath title = createString("title"); + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QReview(String variable) { + this(Review.class, forVariable(variable), INITS); + } + + public QReview(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QReview(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QReview(PathMetadata metadata, PathInits inits) { + this(Review.class, metadata, inits); + } + + public QReview(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.member = inits.isInitialized("member") ? new QMember(forProperty("member")) : null; + this.restaurant = inits.isInitialized("restaurant") ? new QRestaurant(forProperty("restaurant"), inits.get("restaurant")) : null; + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/common/QBaseEntity.java b/spring/src/main/generated/umc/spring/domain/common/QBaseEntity.java new file mode 100644 index 0000000..0bafae2 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/common/QBaseEntity.java @@ -0,0 +1,39 @@ +package umc.spring.domain.common; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QBaseEntity is a Querydsl query type for BaseEntity + */ +@Generated("com.querydsl.codegen.DefaultSupertypeSerializer") +public class QBaseEntity extends EntityPathBase { + + private static final long serialVersionUID = -1748720885L; + + public static final QBaseEntity baseEntity = new QBaseEntity("baseEntity"); + + public final DateTimePath createdAt = createDateTime("createdAt", java.time.LocalDateTime.class); + + public final DateTimePath updatedAt = createDateTime("updatedAt", java.time.LocalDateTime.class); + + public QBaseEntity(String variable) { + super(BaseEntity.class, forVariable(variable)); + } + + public QBaseEntity(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QBaseEntity(PathMetadata metadata) { + super(BaseEntity.class, metadata); + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/mapping/QMemberFavoriteFood.java b/spring/src/main/generated/umc/spring/domain/mapping/QMemberFavoriteFood.java new file mode 100644 index 0000000..637a867 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/mapping/QMemberFavoriteFood.java @@ -0,0 +1,62 @@ +package umc.spring.domain.mapping; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QMemberFavoriteFood is a Querydsl query type for MemberFavoriteFood + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QMemberFavoriteFood extends EntityPathBase { + + private static final long serialVersionUID = -423625056L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QMemberFavoriteFood memberFavoriteFood = new QMemberFavoriteFood("memberFavoriteFood"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final umc.spring.domain.QFavoriteFood favoriteFood; + + public final NumberPath id = createNumber("id", Long.class); + + public final umc.spring.domain.QMember member; + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QMemberFavoriteFood(String variable) { + this(MemberFavoriteFood.class, forVariable(variable), INITS); + } + + public QMemberFavoriteFood(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QMemberFavoriteFood(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QMemberFavoriteFood(PathMetadata metadata, PathInits inits) { + this(MemberFavoriteFood.class, metadata, inits); + } + + public QMemberFavoriteFood(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.favoriteFood = inits.isInitialized("favoriteFood") ? new umc.spring.domain.QFavoriteFood(forProperty("favoriteFood"), inits.get("favoriteFood")) : null; + this.member = inits.isInitialized("member") ? new umc.spring.domain.QMember(forProperty("member")) : null; + } + +} + diff --git a/spring/src/main/generated/umc/spring/domain/mapping/QMemberMission.java b/spring/src/main/generated/umc/spring/domain/mapping/QMemberMission.java new file mode 100644 index 0000000..29da571 --- /dev/null +++ b/spring/src/main/generated/umc/spring/domain/mapping/QMemberMission.java @@ -0,0 +1,64 @@ +package umc.spring.domain.mapping; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QMemberMission is a Querydsl query type for MemberMission + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QMemberMission extends EntityPathBase { + + private static final long serialVersionUID = 1962779462L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QMemberMission memberMission = new QMemberMission("memberMission"); + + public final umc.spring.domain.common.QBaseEntity _super = new umc.spring.domain.common.QBaseEntity(this); + + //inherited + public final DateTimePath createdAt = _super.createdAt; + + public final NumberPath id = createNumber("id", Long.class); + + public final umc.spring.domain.QMember member; + + public final umc.spring.domain.QMission mission; + + public final EnumPath status = createEnum("status", umc.spring.domain.enums.MissionStatus.class); + + //inherited + public final DateTimePath updatedAt = _super.updatedAt; + + public QMemberMission(String variable) { + this(MemberMission.class, forVariable(variable), INITS); + } + + public QMemberMission(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QMemberMission(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QMemberMission(PathMetadata metadata, PathInits inits) { + this(MemberMission.class, metadata, inits); + } + + public QMemberMission(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.member = inits.isInitialized("member") ? new umc.spring.domain.QMember(forProperty("member")) : null; + this.mission = inits.isInitialized("mission") ? new umc.spring.domain.QMission(forProperty("mission"), inits.get("mission")) : null; + } + +} + From 16cbf1f36e8a3cf5f57928340f679509e96eab71 Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:30:32 +0900 Subject: [PATCH 4/7] =?UTF-8?q?:sparkles:=20Practice(#6)=20:=20QueryDSL=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=8C=8C=EC=9D=BC=20=EB=A7=8C=EB=93=A4?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/umc/spring/config/QueryDSLConfig.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 spring/src/main/java/umc/spring/config/QueryDSLConfig.java diff --git a/spring/src/main/java/umc/spring/config/QueryDSLConfig.java b/spring/src/main/java/umc/spring/config/QueryDSLConfig.java new file mode 100644 index 0000000..f41516e --- /dev/null +++ b/spring/src/main/java/umc/spring/config/QueryDSLConfig.java @@ -0,0 +1,18 @@ +package umc.spring.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@RequiredArgsConstructor +public class QueryDSLConfig { + private final EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory(){ + return new JPAQueryFactory(entityManager); + } +} From 26ca5cd3b25026fd3f202c4a3a9e4ed688a678bf Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:31:06 +0900 Subject: [PATCH 5/7] =?UTF-8?q?:sparkles:=20Practice(#6)=20:=20RestaurantR?= =?UTF-8?q?epository=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RestaurantRepository.java | 7 ++++ .../RestaurantRepositoryCustom.java | 9 +++++ .../RestaurantRepositoryImpl.java | 36 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepository.java create mode 100644 spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryCustom.java create mode 100644 spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryImpl.java diff --git a/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepository.java b/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepository.java new file mode 100644 index 0000000..2f1fb3e --- /dev/null +++ b/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepository.java @@ -0,0 +1,7 @@ +package umc.spring.repository.restaurantRepository; + +import org.springframework.data.jpa.repository.JpaRepository; +import umc.spring.domain.Restaurant; + +public interface RestaurantRepository extends JpaRepository, RestaurantRepositoryCustom { +} diff --git a/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryCustom.java b/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryCustom.java new file mode 100644 index 0000000..6e9ee88 --- /dev/null +++ b/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryCustom.java @@ -0,0 +1,9 @@ +package umc.spring.repository.restaurantRepository; + +import umc.spring.domain.Restaurant; + +import java.util.List; + +public interface RestaurantRepositoryCustom { + List dynamicQueryWithBooleanBuilder(String name, Float score); +} \ No newline at end of file diff --git a/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryImpl.java b/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryImpl.java new file mode 100644 index 0000000..99d09de --- /dev/null +++ b/spring/src/main/java/umc/spring/repository/restaurantRepository/RestaurantRepositoryImpl.java @@ -0,0 +1,36 @@ +package umc.spring.repository.restaurantRepository; + +import com.querydsl.core.BooleanBuilder; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import umc.spring.domain.QRestaurant; +import umc.spring.domain.Restaurant; + + +import java.util.List; + +@Repository +@RequiredArgsConstructor +public class RestaurantRepositoryImpl implements RestaurantRepositoryCustom{ + private final JPAQueryFactory jpaQueryFactory; + private final QRestaurant restaurant = QRestaurant.restaurant; + + @Override + public List dynamicQueryWithBooleanBuilder(String name, Float score) { + BooleanBuilder predicate = new BooleanBuilder(); + + if (name != null) { + predicate.and(restaurant.name.eq(name)); + } + + if (score != null) { + predicate.and(restaurant.score.goe(4.0f)); + } + + return jpaQueryFactory + .selectFrom(restaurant) + .where(predicate) + .fetch(); + } +} \ No newline at end of file From 980c5236d7cacc37187eda307f89fe0a2f3875ba Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:31:28 +0900 Subject: [PATCH 6/7] =?UTF-8?q?:sparkles:=20Practice(#6)=20:=20RestaurantS?= =?UTF-8?q?ervice=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RestaurantQueryService.java | 12 +++++++ .../RestaurantQueryServiceImpl.java | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryService.java create mode 100644 spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryServiceImpl.java diff --git a/spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryService.java b/spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryService.java new file mode 100644 index 0000000..9abf84f --- /dev/null +++ b/spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryService.java @@ -0,0 +1,12 @@ +package umc.spring.service.restaurantService; + +import umc.spring.domain.Restaurant; + +import java.util.List; +import java.util.Optional; + +public interface RestaurantQueryService { + + Optional findRestaurant(Long id); + List findRestaurantsByNameAndScore(String name, Float score); +} diff --git a/spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryServiceImpl.java b/spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryServiceImpl.java new file mode 100644 index 0000000..e75299c --- /dev/null +++ b/spring/src/main/java/umc/spring/service/restaurantService/RestaurantQueryServiceImpl.java @@ -0,0 +1,32 @@ +package umc.spring.service.restaurantService; + +import org.springframework.transaction.annotation.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import umc.spring.domain.Restaurant; +import umc.spring.repository.restaurantRepository.RestaurantRepository; + +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class RestaurantQueryServiceImpl implements RestaurantQueryService{ + + private final RestaurantRepository restaurantRepository; + + @Override + public Optional findRestaurant(Long id) { + return restaurantRepository.findById(id); + } + + @Override + public List findRestaurantsByNameAndScore(String name, Float score) { + List filteredRestaurants = restaurantRepository.dynamicQueryWithBooleanBuilder(name, score); + + filteredRestaurants.forEach(restaurant -> System.out.println("Restaurant: " + restaurant)); + + return filteredRestaurants; + } +} \ No newline at end of file From 19b5ea1e802110135fffeaf6ff53111ffde84bcd Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:31:52 +0900 Subject: [PATCH 7/7] =?UTF-8?q?:sparkles:=20Practice(#6)=20:=20Application?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/umc/spring/Application.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/spring/src/main/java/umc/spring/Application.java b/spring/src/main/java/umc/spring/Application.java index 65b1291..0049fd8 100644 --- a/spring/src/main/java/umc/spring/Application.java +++ b/spring/src/main/java/umc/spring/Application.java @@ -1,16 +1,37 @@ package umc.spring; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import umc.spring.service.restaurantService.RestaurantQueryService; @SpringBootApplication @EnableJpaAuditing public class Application { public static void main(String[] args) { - System.out.println("hello"); SpringApplication.run(Application.class, args); } -} + @Bean + public CommandLineRunner run(ApplicationContext context) { + return args -> { + RestaurantQueryService restaurantService = context.getBean(RestaurantQueryService.class); + + // 파라미터 값 설정 + String name = "요아정"; + Float score = 4.0f; + + // 쿼리 메서드 호출 및 쿼리 문자열과 파라미터 출력 + System.out.println("Executing findStoresByNameAndScore with parameters:"); + System.out.println("Name: " + name); + System.out.println("Score: " + score); + + restaurantService.findRestaurantsByNameAndScore(name, score) + .forEach(System.out::println); + }; + }} +