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
Expand Up @@ -9,7 +9,8 @@
@SpringBootApplication(scanBasePackages = {
"com.nowait.applicationadmin",
"com.nowait.infraaws",
"com.nowait.adminsecurity"
"com.nowait.adminsecurity",
"com.nowait.config"
})
@EntityScan(basePackages = {
"com.nowait.menu.entity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import com.nowait.infraaws.s3.S3Service;
import com.nowait.menu.entity.Menu;
import com.nowait.menu.entity.MenuImage;
import com.nowait.menu.exception.MenuImageEmptyException;
import com.nowait.menu.exception.MenuImageNotFoundException;
import com.nowait.menu.exception.MenuNotFoundException;
import com.nowait.menu.repository.MenuImageRepository;
import com.nowait.menu.repository.MenuRepository;

Expand All @@ -23,10 +26,13 @@ public class MenuImageService {

@Transactional
public MenuImageUploadResponse save(Long menuId, MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new MenuImageEmptyException();
}

String type = "menu";
Menu menu = menuRepository.findById(menuId)
.orElseThrow(() -> new IllegalArgumentException("Menu not found with id: " + menuId));
.orElseThrow(MenuNotFoundException::new);

S3Service.S3UploadResult uploadResult = s3Service.upload(type, menuId, file).join();

Expand All @@ -46,7 +52,7 @@ public MenuImageUploadResponse save(Long menuId, MultipartFile file) {
@Transactional
public void delete(Long id) {
MenuImage menuImage = menuImageRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("MenuImage not found with id: " + id));
.orElseThrow(MenuImageNotFoundException::new);

s3Service.delete(menuImage.getFileKey());
menuImageRepository.delete(menuImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import com.nowait.applicationadmin.menu.dto.MenuUpdateRequest;
import com.nowait.menu.entity.Menu;
import com.nowait.menu.entity.MenuImage;
import com.nowait.menu.exception.MenuNotFoundException;
import com.nowait.menu.repository.MenuImageRepository;
import com.nowait.menu.repository.MenuRepository;
import com.nowait.order.exception.OrderParameterEmptyException;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -53,8 +55,12 @@ public MenuReadResponse getAllMenusByStoreId(Long storeId) {

@Transactional(readOnly = true)
public MenuReadDto getMenuById(Long storeId, Long menuId) {
if (storeId == null || menuId == null) {
throw new OrderParameterEmptyException();
}

Menu menu = menuRepository.findByStoreIdAndIdAndDeletedFalse(storeId, menuId)
.orElseThrow(() -> new IllegalArgumentException("Menu not found with id: " + menuId));
.orElseThrow(MenuNotFoundException::new);

List<MenuImage> images = menuImageRepository.findByMenu(menu);
List<MenuImageUploadResponse> imageDto = images.stream()
Expand All @@ -68,7 +74,7 @@ public MenuReadDto getMenuById(Long storeId, Long menuId) {
@Transactional
public MenuReadDto updateMenu(Long menuId, MenuUpdateRequest request) {
Menu menu = menuRepository.findByIdAndDeletedFalse(menuId)
.orElseThrow(() -> new IllegalArgumentException("Menu not found with id: " + menuId));
.orElseThrow(MenuNotFoundException::new);

menu.updateInfo(
request.getName(),
Expand All @@ -89,7 +95,7 @@ public MenuReadDto updateMenu(Long menuId, MenuUpdateRequest request) {
@Transactional
public String deleteMenu(Long menuId) {
Menu menu = menuRepository.findById(menuId)
.orElseThrow(() -> new IllegalArgumentException("Menu is already deleted with id: " + menuId));
.orElseThrow(MenuNotFoundException::new);

menu.markAsDeleted();
menuRepository.save(menu);
Expand All @@ -100,7 +106,7 @@ public String deleteMenu(Long menuId) {
@Transactional
public Boolean toggleSoldOut(Long menuId) {
Menu menu = menuRepository.findById(menuId)
.orElseThrow(() -> new IllegalArgumentException("해당 메뉴가 존재하지 않습니다."));
.orElseThrow(MenuNotFoundException::new);

menu.toggleSoldOut();
menuRepository.save(menu);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.nowait.applicationadmin.reservation.dto.ReservationGetResponseDto;
import com.nowait.applicationadmin.reservation.dto.ReservationStatusSummaryDto;
import com.nowait.applicationadmin.reservation.dto.ReservationStatusUpdateRequestDto;
import com.nowait.applicationadmin.reservation.exception.ReservationNotFoundException;
import com.nowait.reservation.entity.Reservation;
import com.nowait.reservation.repository.ReservationRepository;
import com.nowait.common.enums.ReservationStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.nowait.store.entity.Store;

import com.nowait.store.entity.StoreImage;
import com.nowait.store.exception.StoreImageEmptyException;
import com.nowait.store.exception.StoreImageNotFoundException;
import com.nowait.store.exception.StoreNotFoundException;
import com.nowait.store.repository.StoreImageRepository;
import com.nowait.store.repository.StoreRepository;
import com.nowait.infraaws.s3.S3Service;
Expand All @@ -29,10 +32,11 @@ public class StoreImageService {

@Transactional
public List<StoreImageUploadResponse> saveAll(Long storeId, List<MultipartFile> files) {
if (files == null || files.isEmpty()) throw new StoreImageEmptyException();

String type = "store";
Store store = storeRepository.findById(storeId)
.orElseThrow(() -> new EntityNotFoundException("Store not found with id: " + storeId));
.orElseThrow(StoreNotFoundException::new);

// 모든 파일을 비동기로 업로드
List<CompletableFuture<S3Service.S3UploadResult>> uploadFutures = new ArrayList<>();
Expand All @@ -52,8 +56,7 @@ public List<StoreImageUploadResponse> saveAll(Long storeId, List<MultipartFile>

// DB 저장은 모든 S3 업로드 성공 후 수행
List<StoreImageUploadResponse> imageUploadResponses = new ArrayList<>();
for (int i = 0; i < uploadResults.size(); i++) {
S3Service.S3UploadResult uploadResult = uploadResults.get(i);
for (S3Service.S3UploadResult uploadResult : uploadResults) {
StoreImage storeImage = StoreImage.builder()
.store(store)
.imageUrl(uploadResult.url())
Expand All @@ -70,7 +73,7 @@ public List<StoreImageUploadResponse> saveAll(Long storeId, List<MultipartFile>
@Transactional
public void delete(Long storeImageId) {
StoreImage storeImage = storeImageRepository.findById(storeImageId)
.orElseThrow(() -> new EntityNotFoundException("StoreImage not found with id: " + storeImageId));
.orElseThrow(StoreImageNotFoundException::new);

s3Service.delete(storeImage.getFileKey());
storeImageRepository.delete(storeImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.nowait.applicationadmin.store.dto.StoreUpdateRequest;
import com.nowait.store.entity.Store;
import com.nowait.store.entity.StoreImage;
import com.nowait.store.exception.StoreNotFoundException;
import com.nowait.store.exception.StoreParamEmptyException;
import com.nowait.store.repository.StoreImageRepository;
import com.nowait.store.repository.StoreRepository;

Expand All @@ -28,6 +30,8 @@ public class StoreServiceImpl implements StoreService {
@Override
@Transactional
public StoreCreateResponse createStore(StoreCreateRequest request) {
if (request == null) throw new StoreParamEmptyException();

Store toSave = request.toEntity();

Store saved = storeRepository.save(toSave);
Expand All @@ -38,8 +42,10 @@ public StoreCreateResponse createStore(StoreCreateRequest request) {
@Override
@Transactional(readOnly = true)
public StoreReadDto getStoreByStoreId(Long storeId) {
if (storeId == null) throw new StoreParamEmptyException();

Store store = storeRepository.findByStoreIdAndDeletedFalse(storeId)
.orElseThrow(() -> new EntityNotFoundException(storeId + " store not found."));
.orElseThrow(StoreNotFoundException::new);

List<StoreImage> images = storeImageRepository.findByStore(store);
List<StoreImageUploadResponse> imageDto = images.stream()
Expand All @@ -52,8 +58,10 @@ public StoreReadDto getStoreByStoreId(Long storeId) {
@Override
@Transactional
public StoreReadDto updateStore(Long storeId, StoreUpdateRequest request) {
if (storeId == null || request == null) throw new StoreParamEmptyException();

Store store = storeRepository.findByStoreIdAndDeletedFalse(storeId)
.orElseThrow(() -> new EntityNotFoundException(storeId + " store not found."));
.orElseThrow(StoreNotFoundException::new);

store.updateInfo(
request.getName(),
Expand All @@ -74,8 +82,12 @@ public StoreReadDto updateStore(Long storeId, StoreUpdateRequest request) {
@Override
@Transactional
public String deleteStore(Long storeId) {
if (storeId == null) {
throw new StoreParamEmptyException();
}

Store store = storeRepository.findByStoreIdAndDeletedFalse(storeId)
.orElseThrow(() -> new EntityNotFoundException(storeId + " store not found."));
.orElseThrow(StoreNotFoundException::new);

store.markAsDeleted();
storeRepository.save(store);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
@SpringBootApplication(scanBasePackages = {
"com.nowait.applicationuser",
"com.nowait.frontsecurity",
"com.nowait.externaloauth"
"com.nowait.externaloauth",
"com.nowait.config"
})
@EntityScan(basePackages = {
"com.nowait.menu.entity",
Expand All @@ -19,7 +20,6 @@
"com.nowait.user.entity",
"com.nowait.bookmark.entity",
"com.nowait.reservation.entity",
"com.nowait.order.entity",
"com.nowait.order.entity"
})
@EnableJpaRepositories(basePackages = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.nowait.applicationuser.menu.dto.MenuReadResponse;
import com.nowait.menu.entity.Menu;
import com.nowait.menu.entity.MenuImage;
import com.nowait.menu.exception.MenuNotFoundException;
import com.nowait.menu.exception.MenuParamEmptyException;
import com.nowait.menu.repository.MenuImageRepository;
import com.nowait.menu.repository.MenuRepository;

Expand All @@ -25,6 +27,9 @@ public class MenuService {

@Transactional(readOnly = true)
public MenuReadResponse getAllMenusByStoreId(Long storeId) {
if (storeId == null) {
throw new MenuParamEmptyException();
}
List<Menu> menus = menuRepository.findAllByStoreIdAndDeletedFalse(storeId);

List<MenuReadDto> menuReadResponse = menus.stream()
Expand All @@ -42,8 +47,12 @@ public MenuReadResponse getAllMenusByStoreId(Long storeId) {

@Transactional(readOnly = true)
public MenuReadDto getMenuById(Long storeId, Long menuId) {
if (storeId == null || menuId == null) {
throw new MenuParamEmptyException();
}

Menu menu = menuRepository.findByStoreIdAndIdAndDeletedFalse(storeId, menuId)
.orElseThrow(() -> new IllegalArgumentException("Menu not found with id: " + menuId));
.orElseThrow(MenuNotFoundException::new);

List<MenuImage> images = menuImageRepository.findByMenu(menu);
List<MenuImageUploadResponse> imageDto = images.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.nowait.applicationuser.store.dto.StoreReadResponse;
import com.nowait.store.entity.Store;
import com.nowait.store.entity.StoreImage;
import com.nowait.store.exception.StoreNotFoundException;
import com.nowait.store.exception.StoreParamEmptyException;
import com.nowait.store.repository.StoreImageRepository;
import com.nowait.store.repository.StoreRepository;

Expand Down Expand Up @@ -68,8 +70,10 @@ public StoreReadResponse getAllStoresByPage(Pageable pageable) {
@Override
@Transactional(readOnly = true)
public StoreReadDto getStoreByStoreId(Long storeId) {
if (storeId == null) throw new StoreParamEmptyException();

Store store = storeRepository.findByStoreIdAndDeletedFalse(storeId)
.orElseThrow(() -> new EntityNotFoundException(storeId + " store not found."));
.orElseThrow(StoreNotFoundException::new);

List<StoreImage> images = storeImageRepository.findByStore(store);
List<StoreImageUploadResponse> imageDto = images.stream()
Expand All @@ -81,6 +85,10 @@ public StoreReadDto getStoreByStoreId(Long storeId) {

@Override
public List<StoreReadDto> searchStoresByName(String name) {
if (name == null || name.isBlank()) {
throw new StoreParamEmptyException();
}

List<Store> stores = storeRepository.findByNameContainingIgnoreCaseAndDeletedFalse(name);
return stores.stream()
.map(store -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ public enum ErrorMessage {

// bookmark
DUPLICATE_BOOKMARK("이미 북마크한 주점입니다.", "bookmark001"),
NOT_OWN_BOOKMARK("해당 주점은 다른 사용자가 북마크한 주점입니다.", "bookmark002");
NOT_OWN_BOOKMARK("해당 주점은 다른 사용자가 북마크한 주점입니다.", "bookmark002"),

// menu
MENU_PARAMETER_EMPTY("메뉴 생성 시 파라미터 정보가 없습니다.", "menu001"),
MENU_NOT_FOUND("해당 메뉴를 찾을 수 없습니다.", "menu001"),

// store
STORE_PARAMETER_EMPTY("주점 생성 시 파라미터 정보가 없습니다.", "store001"),
STORE_NOT_FOUND("해당 주점을 찾을 수 없습니다.", "store002"),

// image
IMAGE_FILE_EMPTY("이미지 파일을 업로드 해주세요", "image001"),
IMAGE_FILE_NOT_FOUND("이미지 파일을 업로드 해주세요", "image001"),

// search
SEARCH_PARAMETER_EMPTY("검색어가 비어있습니다.", "search001");

private final String message;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.menu.exception;

import com.nowait.common.exception.ErrorMessage;

public class MenuImageEmptyException extends RuntimeException {
public MenuImageEmptyException() {
super(ErrorMessage.IMAGE_FILE_EMPTY.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.menu.exception;

import com.nowait.common.exception.ErrorMessage;

public class MenuImageNotFoundException extends RuntimeException {
public MenuImageNotFoundException() {
super(ErrorMessage.IMAGE_FILE_NOT_FOUND.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.menu.exception;

import com.nowait.common.exception.ErrorMessage;

public class MenuNotFoundException extends RuntimeException {
public MenuNotFoundException() {
super(ErrorMessage.MENU_NOT_FOUND.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.menu.exception;

import com.nowait.common.exception.ErrorMessage;

public class MenuParamEmptyException extends RuntimeException {
public MenuParamEmptyException() {
super(ErrorMessage.MENU_PARAMETER_EMPTY.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.store.exception;

import com.nowait.common.exception.ErrorMessage;

public class StoreImageEmptyException extends RuntimeException {
public StoreImageEmptyException() {
super(ErrorMessage.IMAGE_FILE_EMPTY.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.store.exception;

import com.nowait.common.exception.ErrorMessage;

public class StoreImageNotFoundException extends RuntimeException {
public StoreImageNotFoundException() {
super(ErrorMessage.IMAGE_FILE_NOT_FOUND.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.store.exception;

import com.nowait.common.exception.ErrorMessage;

public class StoreKeywordEmptyException extends RuntimeException {
public StoreKeywordEmptyException() {
super(ErrorMessage.STORE_PARAMETER_EMPTY.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.store.exception;

import com.nowait.common.exception.ErrorMessage;

public class StoreNotFoundException extends RuntimeException {
public StoreNotFoundException() {
super(ErrorMessage.STORE_NOT_FOUND.getMessage());
}
}
Loading