This repository was archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Category 영역에 대한 JPA Migration #71
Open
beaniejoy
wants to merge
1
commit into
main
Choose a base branch
from
refactor/category-jpa-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
src/main/java/kr/fiveminutesmarket/category/dto/response/MainCategoryResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
package kr.fiveminutesmarket.category.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import java.util.List; | ||
|
||
public class MainCategoryResponse { | ||
|
||
private Long mainCategoryId; | ||
|
||
private String mainCategoryName; | ||
|
||
public Long getMainCategoryId() { | ||
return mainCategoryId; | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private List<SubCategoryResponse> subCategoryResponses; | ||
|
||
public MainCategoryResponse() { | ||
} | ||
|
||
public void setMainCategoryId(Long mainCategoryId) { | ||
public MainCategoryResponse(Long mainCategoryId, String mainCategoryName, List<SubCategoryResponse> subCategoryResponses) { | ||
this.mainCategoryId = mainCategoryId; | ||
this.mainCategoryName = mainCategoryName; | ||
this.subCategoryResponses = subCategoryResponses; | ||
} | ||
|
||
public Long getMainCategoryId() { | ||
return mainCategoryId; | ||
} | ||
|
||
public String getMainCategoryName() { | ||
return mainCategoryName; | ||
} | ||
|
||
public void setMainCategoryName(String mainCategoryName) { | ||
this.mainCategoryName = mainCategoryName; | ||
public List<SubCategoryResponse> getSubCategoryResponses() { | ||
return subCategoryResponses; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 3 additions & 18 deletions
21
src/main/java/kr/fiveminutesmarket/category/repository/MainCategoryRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,9 @@ | ||
package kr.fiveminutesmarket.category.repository; | ||
|
||
import kr.fiveminutesmarket.category.domain.MainCategory; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
public interface MainCategoryRepository extends JpaRepository<MainCategory, Long> { | ||
|
||
@Mapper | ||
public interface MainCategoryRepository { | ||
|
||
int insert(@Param("mainCategory") MainCategory mainCategory); | ||
|
||
List<MainCategory> findAll(); | ||
|
||
MainCategory findById(@Param("mainCategoryId") Long mainCategoryId); | ||
|
||
int countByName(@Param("mainCategoryName") String mainCategoryName); | ||
|
||
int updateMainCategory(@Param("mainCategoryId") Long mainCategoryId, | ||
@Param("mainCategory") MainCategory mainCategory); | ||
|
||
void deleteById(@Param("mainCategoryId") Long mainCategoryId); | ||
long countByMainCategoryName(String mainCategoryName); | ||
} |
23 changes: 3 additions & 20 deletions
23
src/main/java/kr/fiveminutesmarket/category/repository/SubCategoryRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,9 @@ | ||
package kr.fiveminutesmarket.category.repository; | ||
|
||
import kr.fiveminutesmarket.category.domain.SubCategory; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
public interface SubCategoryRepository extends JpaRepository<SubCategory, Long> { | ||
|
||
@Mapper | ||
public interface SubCategoryRepository { | ||
|
||
int insert(@Param("subCategory") SubCategory subCategory); | ||
|
||
List<SubCategory> findAll(); | ||
|
||
SubCategory findById(@Param("subCategoryId") Long subCategoryId); | ||
|
||
int countByName(@Param("subCategoryName") String subCategoryName); | ||
|
||
int updateSubCategory(@Param("subCategoryId") Long subCategoryId, | ||
@Param("subCategory") SubCategory subCategory); | ||
|
||
void deleteById(@Param("subCategoryId") Long subCategoryId); | ||
|
||
void deleteByMainCategoryId(@Param("mainCategoryId") Long mainCategoryId); | ||
long countBySubCategoryName(String subCategoryName); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subCategoryList가 Lazy로 fetch하면 얻는 이점이 어떤게 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f-lab-bright
lazy loading은 DB에서 조회해 연관된 엔티티를 한꺼번에 영속성 컨텍스트에 올려놓는 것이 아니라 실제로 subCatgory를 사용할 때 DB조회하기 때문에 불필요한 쿼리 낭비가 없다는 것이 장점 중에 하나입니다.
그런데 MainCategory 조회시 보통 SubCategory도 같이 사용된다는 점에서 EAGER, 즉시로딩으로 하는 것도 좋다고 생각합니다!
(보통 페이지에서 Category 조회시에도 SubCategory까지 같이 조회한다는 것을 고려)