-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 상점 메뉴 조회 API 구현 #112
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c9144d2
feat: 메뉴 관련 엔티티들 추가
Invidam 255b936
feat: 메뉴 조회위한 뼈대 완성
Invidam 3bbc9a2
test: 메뉴 조회 테스트 완성
Invidam 372c206
refactor: 패키지 구조 변경
Invidam 3bcba96
refactor: 응답 데이터를 구성하는 로직 수정
Invidam 917836d
test: 응답 데이터 테스트 추가
Invidam fc57bd1
refactor: 리팩터링 진행
Invidam 66e610e
refactor: 리팩터링 진행
Invidam d59e3e3
refactor: 포매팅 적용
Invidam 060637a
refactor: 리뷰 반영
Invidam 0d8954b
feat: 로깅 추가
Invidam ad8aa03
refactor: DTO 레코드로 변경
Invidam e3e75dd
chore: 불필요한 래핑 제거
Invidam 9960e09
refactor: 예외 처리 위한 로직 줄바꿈 추가
Invidam b999250
refactor: 로그 메시지 개선
Invidam c71fb10
fix: 예약어 사용 위해 백틱 추가
Invidam f8720d5
Merge remote-tracking branch 'origin/feature/41-find-menu' into featu…
Invidam 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
23 changes: 23 additions & 0 deletions
23
src/main/java/in/koreatech/koin/controller/shop/ShopController.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package in.koreatech.koin.controller.shop; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import in.koreatech.koin.dto.shop.ShopMenuResponse; | ||
import in.koreatech.koin.service.shop.ShopService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ShopController { | ||
|
||
private final ShopService shopService; | ||
|
||
@GetMapping("/shops/{shopId}/menus/{menuId}") | ||
public ResponseEntity<ShopMenuResponse> findMenu(@PathVariable Long shopId, @PathVariable Long menuId) { | ||
ShopMenuResponse shopMenu = shopService.findMenu(menuId); | ||
return ResponseEntity.ok(shopMenu); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package in.koreatech.koin.domain.shop; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import in.koreatech.koin.domain.BaseEntity; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "shop_menus") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Menu extends BaseEntity { | ||
|
||
private static final int SINGLE_OPTION_COUNT = 1; | ||
|
||
@Id | ||
@Column(name = "id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotNull | ||
@Column(name = "shop_id", nullable = false) | ||
private Long shopId; | ||
|
||
@Size(max = 255) | ||
@NotNull | ||
@Column(name = "name", nullable = false) | ||
private String name; | ||
|
||
@Size(max = 255) | ||
@Column(name = "description") | ||
private String description; | ||
|
||
@NotNull | ||
@Column(name = "is_hidden", nullable = false) | ||
private Boolean isHidden = false; | ||
|
||
@NotNull | ||
@Column(name = "is_deleted", nullable = false) | ||
private Boolean isDeleted = false; | ||
|
||
@OneToMany(mappedBy = "menu", orphanRemoval = true, cascade = CascadeType.ALL) | ||
private List<MenuCategoryMap> menuCategoryMaps = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "menu", orphanRemoval = true, cascade = CascadeType.ALL) | ||
private List<MenuOption> menuOptions = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "menu", orphanRemoval = true, cascade = CascadeType.ALL) | ||
private List<MenuImage> menuImages = new ArrayList<>(); | ||
|
||
@Builder | ||
private Menu(Long shopId, String name, String description) { | ||
this.shopId = shopId; | ||
this.name = name; | ||
this.description = description; | ||
} | ||
|
||
public boolean hasMultipleOption() { | ||
return menuOptions.size() > SINGLE_OPTION_COUNT; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Menu{" + | ||
"id=" + id + | ||
", shopId=" + shopId + | ||
", name='" + name + '\'' + | ||
'}'; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/in/koreatech/koin/domain/shop/MenuCategory.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package in.koreatech.koin.domain.shop; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import in.koreatech.koin.domain.BaseEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "shop_menu_categories") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public final class MenuCategory extends BaseEntity { | ||
|
||
@Id | ||
@Column(name = "id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotNull | ||
@Column(name = "shop_id", nullable = false) | ||
private Long shopId; | ||
|
||
@Size(max = 255) | ||
@NotNull | ||
@Column(name = "name", nullable = false) | ||
private String name; | ||
|
||
@NotNull | ||
@Column(name = "is_deleted", nullable = false) | ||
private Boolean isDeleted = false; | ||
|
||
@OneToMany(mappedBy = "menuCategory") | ||
private List<MenuCategoryMap> menuCategoryMaps = new ArrayList<>(); | ||
|
||
@Builder | ||
private MenuCategory(Long shopId, String name) { | ||
this.shopId = shopId; | ||
this.name = name; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/in/koreatech/koin/domain/shop/MenuCategoryMap.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package in.koreatech.koin.domain.shop; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "shop_menu_category_map") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class MenuCategoryMap { | ||
|
||
@Id | ||
@Column(name = "id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "shop_menu_id") | ||
private Menu menu; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) | ||
@JoinColumn(name = "shop_menu_category_id") | ||
private MenuCategory menuCategory; | ||
|
||
public static MenuCategoryMap create() { | ||
return new MenuCategoryMap(); | ||
} | ||
|
||
public void map(Menu menu, MenuCategory menuCategory) { | ||
setMenu(menu); | ||
setMenuCategory(menuCategory); | ||
} | ||
|
||
private void setMenu(Menu menu) { | ||
if (menu.equals(this.menu)) { | ||
return; | ||
} | ||
|
||
if (this.menu != null) { | ||
this.menu.getMenuCategoryMaps().remove(this); | ||
} | ||
|
||
this.menu = menu; | ||
menu.getMenuCategoryMaps().add(this); | ||
} | ||
|
||
private void setMenuCategory(MenuCategory menuCategory) { | ||
if (menuCategory.equals(this.menuCategory)) { | ||
return; | ||
} | ||
|
||
if (this.menuCategory != null) { | ||
this.menuCategory.getMenuCategoryMaps().remove(this); | ||
} | ||
|
||
this.menuCategory = menuCategory; | ||
menuCategory.getMenuCategoryMaps().add(this); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/in/koreatech/koin/domain/shop/MenuImage.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package in.koreatech.koin.domain.shop; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "shop_menu_images") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class MenuImage { | ||
|
||
@Id | ||
@Column(name = "id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "shop_menu_id") | ||
private Menu menu; | ||
|
||
@Size(max = 255) | ||
@NotNull | ||
@Column(name = "image_url", nullable = false) | ||
private String imageUrl; | ||
|
||
@Builder | ||
private MenuImage(String imageUrl) { | ||
this.imageUrl = imageUrl; | ||
} | ||
|
||
public void setMenu(Menu menu) { | ||
if (menu.equals(this.menu)) { | ||
return; | ||
} | ||
|
||
if (this.menu != null) { | ||
this.menu.getMenuImages().remove(this); | ||
} | ||
this.menu = menu; | ||
this.menu.getMenuImages().add(this); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/in/koreatech/koin/domain/shop/MenuOption.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package in.koreatech.koin.domain.shop; | ||
|
||
import in.koreatech.koin.domain.BaseEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "shop_menu_details") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class MenuOption extends BaseEntity { | ||
|
||
@Id | ||
@Column(name = "id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "shop_menu_id") | ||
private Menu menu; | ||
|
||
@Size(max = 255) | ||
@Column(name = "`option`") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. option의 Column 이름을 `option` 으로 한 이유가 있나요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JPA Buddy 활용한 것 뿐인데, 버그가 있었떤 것 같네요.. 앞으로 JPA Buddy 이용해 코드 생성하더라도, 한 번씩 살펴보겠습니다~ |
||
private String option; | ||
|
||
@NotNull | ||
@Column(name = "price", nullable = false) | ||
private Integer price; | ||
|
||
@Builder | ||
private MenuOption(String option, Integer price) { | ||
this.option = option; | ||
this.price = price; | ||
} | ||
|
||
public void setMenu(Menu menu) { | ||
if (menu.equals(this.menu)) { | ||
return; | ||
} | ||
|
||
if (this.menu != null) { | ||
this.menu.getMenuOptions().remove(this); | ||
} | ||
this.menu = menu; | ||
this.menu.getMenuOptions().add(this); | ||
} | ||
} |
Oops, something went wrong.
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.
C
중간테이블이군요...
ManyToMany 관계라 어쩔수 없으려나요