Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.example.umc_9th.domain.inquiry;
package com.example.umc_9th.domain.inquiry.entity;


import com.example.umc_9th.domain.member.Gender;
import com.example.umc_9th.domain.member.Member;
import com.example.umc_9th.domain.review.Review;
import com.example.umc_9th.domain.inquiry.InquriesType;
import com.example.umc_9th.domain.member.entity.Member;
import jakarta.persistence.*;
import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.umc_9th.domain.inquiry;
package com.example.umc_9th.domain.inquiry.entity;


import com.example.umc_9th.domain.member.Member;
import jakarta.persistence.*;
import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.umc_9th.domain.member;
package com.example.umc_9th.domain.member.entity;

import com.example.umc_9th.grobal.BaseEntity;
import jakarta.persistence.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.example.umc_9th.domain.member;
package com.example.umc_9th.domain.member.entity;

import com.example.umc_9th.domain.mission.mapping.UserMission;
import com.example.umc_9th.domain.region.Region;
import com.example.umc_9th.domain.region.SubRegion;
import com.example.umc_9th.domain.review.Review;
import com.example.umc_9th.domain.member.Gender;
import com.example.umc_9th.grobal.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;


import java.time.LocalDate;
import java.util.List;

@Entity
@Getter
Expand All @@ -22,7 +17,7 @@ public class Member extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; //pk
private Long memberId; //pk

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private Long id; -> 이렇게 해도 member_id로 컬럼 이름 저장됩니다.
private Long memberId => 이렇게 하면 CammelCase -> snake_case로 자동 변환돼서 member_id로 저장됩니다.

∴ 그냥 id로 저장해도 된다~


@Column(nullable = false, length = 50)
private String name; //이름
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.umc_9th.domain.member.repository;

import com.example.umc_9th.domain.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, Long> {


//2 id 로 멤버 테이블 조회
//마이 페이지 화면 쿼리
//(메서드 생성 방식 권장)
Optional<Member> findById(Long id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JpaRepository에 기본 내장되어 있습니다.


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.example.umc_9th.domain.mission;
package com.example.umc_9th.domain.mission.entity;

import com.example.umc_9th.domain.mission.mapping.UserMission;
import com.example.umc_9th.domain.review.Review;
import com.example.umc_9th.domain.review.entity.Review;
import com.example.umc_9th.domain.store.Store;
import com.example.umc_9th.grobal.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import java.util.List;


@Entity
Expand Down Expand Up @@ -41,6 +38,10 @@ public class Mission extends BaseEntity {
// private List<UserMission> userMissions ;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id")
private Store store;

@ManyToOne(fetch = FetchType.LAZY) // 리뷸 테이블 N:1 관계 매핑
@JoinColumn(name = "review_id")
private Review review;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.umc_9th.domain.mission.mapping;


import com.example.umc_9th.domain.member.Member;
import com.example.umc_9th.domain.mission.Mission;
import com.example.umc_9th.domain.member.entity.Member;
import com.example.umc_9th.domain.mission.entity.Mission;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.umc_9th.domain.mission.repository;

import com.example.umc_9th.domain.mission.entity.Mission;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface RegionMissionRepository extends JpaRepository<Mission,Long> {


//4. 홈 화면 쿼리
//(현재 선택 된 지역에서 도전이 가능한 미션 목록, 페이징 포함)


//1. 미션 테이블 통해서 가게 테이블 -> 지역 테이블 -> 세부지역 테이블 미션이 해당

// WHERE r.id = :regionId 는 자리표시자로 값 비교
@Query(value = """
SELECT m FROM Mission m
JOIN FETCH m.store s
JOIN FETCH s.region r
JOIN FETCH r.subRegion sr
WHERE r.id = :regionId
""",
countQuery = "SELECT count(m) FROM Mission m JOIN m.store s WHERE s.region.id = :regionId")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

countQuery -> 이게 뭔가 해서 알아봤는데, fetchJoin + Page 하면 CountQuery를 정상적으로 만들지 못한다는걸 배웠네요. 굿굿

Page<Mission> findMissionsByRegion(
@Param("regionId") Long regionId,
Pageable pageable
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.umc_9th.domain.mission.repository;

import com.example.umc_9th.domain.mission.mapping.UserMission;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface UserMissionRepository extends JpaRepository<UserMission, Long> {


//3.내가 진행중, 진행 완료한 미션 모아서 보는 쿼리(페이징 포함)

// join fetch : um과 연관된 mission 엔티티 정보까지 가져옴 (N+1) 문제 해결합니다
@Query(value="SELECT um from UserMission um join fetch um.mission m"+
// um의 멤버필드에 있는 id가 memgerId이름의 필드를 가져옴
" where um.member.memberId=:memberId",
// 페이징 처리를 위해 전체 데이터가 몇 개인지 계산하는 쿼리 지정합니다
countQuery = " SELECT count(um) FROM UserMission um WHERE um.member.memberId = :memberId")
Page<UserMission>findMyMission(@Param("memberId") Long memberId, Pageable pageable);



}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.umc_9th.domain.region;
package com.example.umc_9th.domain.region.entity;

import com.example.umc_9th.domain.member.Agree;
import com.example.umc_9th.domain.member.Member;
import com.example.umc_9th.domain.member.entity.Member;
import com.example.umc_9th.grobal.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.umc_9th.domain.region;
package com.example.umc_9th.domain.region.entity;


import com.example.umc_9th.grobal.BaseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.umc_9th.domain.review;
package com.example.umc_9th.domain.review.entity;


import com.example.umc_9th.domain.member.Member;
import jakarta.persistence.*;
import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.example.umc_9th.domain.review;
package com.example.umc_9th.domain.review.entity;


import com.example.umc_9th.domain.member.Member;
import com.example.umc_9th.domain.mission.Mission;
import com.example.umc_9th.domain.member.entity.Member;
import com.example.umc_9th.domain.store.Store;
import com.example.umc_9th.grobal.BaseEntity;
import jakarta.persistence.*;
import lombok.*;

import java.util.List;

@Entity
@Getter
@Builder
Expand All @@ -33,7 +31,9 @@ public class Review extends BaseEntity {
private Member member;



@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "shop_id")
private Store store;


//양방향 고려
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.umc_9th.domain.review;
package com.example.umc_9th.domain.review.entity;


import jakarta.persistence.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.umc_9th.domain.review.repository;

import com.example.umc_9th.domain.member.entity.Member;
import com.example.umc_9th.domain.review.entity.Review;
import com.example.umc_9th.domain.store.Store;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface ReviewRepository extends JpaRepository<Review, Long> {



//2. 리뷰 작성하는 쿼리,
//* 사진의 경우는 일단 배제
//(메서드 생성 방식 권장)
// id로 리뷰 조횔 할 떄 member도 같이 조회
// 리뷰 조회할 떄 member 엔티티도 같이 가져오게 하는 에노테이션 = @EntityGraph
@EntityGraph(attributePaths = {"member"})
Optional<Review> findById(Long id);
// Member와 Store를 기준으로 Review 조회
boolean existsByMemberAndStore(Member member, Store store);












}
9 changes: 4 additions & 5 deletions src/main/java/com/example/umc_9th/domain/store/Store.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.example.umc_9th.domain.store;

import com.example.umc_9th.domain.mission.Mission;
import com.example.umc_9th.domain.region.Region;
import com.example.umc_9th.domain.review.ReviewImage;
import com.example.umc_9th.domain.region.entity.Region;
import com.example.umc_9th.domain.store.mapping.FoodCategory;
import com.example.umc_9th.grobal.BaseEntity;
import jakarta.persistence.*;
import lombok.*;

import java.util.List;

@Entity
@Getter
@Builder
Expand Down Expand Up @@ -40,4 +36,7 @@ public class Store extends BaseEntity {
private Region region;





}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.umc_9th.domain.store.mapping;


import com.example.umc_9th.domain.member.Member;
import com.example.umc_9th.domain.member.entity.Member;
import jakarta.persistence.*;
import lombok.*;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spring:
database-platform: org.hibernate.dialect.MySQLDialect #
show-sql: true #
hibernate:
ddl-auto: create #
ddl-auto: create-drop #

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실제로 프젝할 때는 이걸루 두면 안돼요..ㅎ

properties:
hibernate:
format_sql: true #