-
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
[POM-94] feat: image 관련 mappedSuperclass로 분리, menu 도메인 엔티티 validation 및 전체적 구조 설정 #43
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3603800
feat: h2 설정 추가
juno-junho b86433f
refactor: 이미지 mappedSuperClass로 분리
juno-junho 66a2310
feat: 메뉴 도메인 엔티티 생성
juno-junho 95ccadf
feat: 메뉴 등록 기능 구현 관련 전체적인 구조 생성
juno-junho 5333aa4
test: mapped super class 테스트 및 메뉴 엔티티 테스트
juno-junho f547cf9
Revert "feat: h2 설정 추가"
juno-junho 046207a
Revert "test: mapped super class 테스트 및 메뉴 엔티티 테스트"
juno-junho 24e25d7
refactor: 리뷰 반영
juno-junho 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/com/ray/pominowner/global/domain/BaseFileEntity.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 com.ray.pominowner.global.domain; | ||
|
||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.util.Assert; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
public abstract class BaseFileEntity extends BaseTimeEntity { | ||
|
||
protected String path; | ||
|
||
protected String uploadName; | ||
|
||
protected String fileName; | ||
|
||
protected void validateImage(String path, String uploadName, String fileName) { | ||
Assert.hasText(path, "경로는 빈 값일 수 없습니다."); | ||
Assert.hasText(uploadName, "파일 이름은 빈 값일 수 없습니다."); | ||
Assert.hasText(fileName, "파일 이름은 빈 값일 수 없습니다."); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/ray/pominowner/menu/controller/MenuController.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,31 @@ | ||
package com.ray.pominowner.menu.controller; | ||
|
||
import com.ray.pominowner.menu.controller.dto.MenuInfoRequest; | ||
import com.ray.pominowner.menu.domain.MenuImage; | ||
import com.ray.pominowner.menu.service.MenuService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.net.URI; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/menu/") | ||
public class MenuController { | ||
|
||
private final MenuService menuService; | ||
|
||
@PostMapping("{storeId}") | ||
public ResponseEntity<Void> registerMenu(@RequestBody MenuInfoRequest request, @PathVariable Long storeId) { | ||
MenuImage image = menuService.createImage(request.image()); | ||
Long menuId = menuService.registerMenu(request.generateMenuEntityWithImage(image)); | ||
|
||
return ResponseEntity.created(URI.create("/api/v1/menu/" + storeId + "/" + menuId)).build(); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/ray/pominowner/menu/controller/dto/MenuInfoRequest.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,20 @@ | ||
package com.ray.pominowner.menu.controller.dto; | ||
|
||
import com.ray.pominowner.menu.domain.Menu; | ||
import com.ray.pominowner.menu.domain.MenuImage; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public record MenuInfoRequest(String name, MultipartFile image, String info, int price, Long storeId) { | ||
|
||
public Menu generateMenuEntityWithImage(MenuImage image) { | ||
|
||
return Menu.builder() | ||
.name(name) | ||
.info(info) | ||
.price(price) | ||
.menuImageId(image.getId()) | ||
.storeId(storeId) | ||
.build(); | ||
} | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/ray/pominowner/menu/domain/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,34 @@ | ||
package com.ray.pominowner.menu.domain; | ||
|
||
import com.ray.pominowner.global.domain.BaseFileEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class MenuImage extends BaseFileEntity { | ||
|
||
@Id | ||
@Column(name = "MENU_IMAGE_ID") | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@Builder | ||
private MenuImage(String path, String uploadName, String fileName) { | ||
validateImage(path, uploadName, fileName); | ||
|
||
this.path = path; | ||
this.uploadName = uploadName; | ||
this.fileName = fileName; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/ray/pominowner/menu/repository/MenuRepository.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,8 @@ | ||
package com.ray.pominowner.menu.repository; | ||
|
||
import com.ray.pominowner.menu.domain.Menu; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MenuRepository extends JpaRepository<Menu, Long> { | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/ray/pominowner/menu/service/MenuService.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,26 @@ | ||
package com.ray.pominowner.menu.service; | ||
|
||
import com.ray.pominowner.menu.domain.Menu; | ||
import com.ray.pominowner.menu.domain.MenuImage; | ||
import com.ray.pominowner.menu.repository.MenuRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MenuService { | ||
|
||
private final MenuRepository menuRepository; | ||
|
||
public Long registerMenu(Menu menu) { | ||
// 구현 예정 | ||
return menuRepository.save(menu).getId(); | ||
} | ||
|
||
public MenuImage createImage(MultipartFile image) { | ||
// 구현 예정 | ||
return null; | ||
} | ||
|
||
} |
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
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.
이 private 생성자는 어디에서 호출 되나요?
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.
호출 안되고 builder로만 사용하려고 막아놓은거에요