Skip to content

Commit

Permalink
Refactor: 스토어 파사드 패턴 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
marinesnow34 committed Mar 4, 2024
1 parent f3e1a5b commit f75e712
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.readyvery.readyverydemo.src.store;

import org.springframework.stereotype.Service;

import com.readyvery.readyverydemo.domain.Store;
import com.readyvery.readyverydemo.domain.repository.StoreRepository;
import com.readyvery.readyverydemo.global.exception.BusinessLogicException;
import com.readyvery.readyverydemo.global.exception.ExceptionCode;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class StoreServiceFacade {
private final StoreRepository storeRepository;

public Store getStoreById(Long storeId) {
return storeRepository.findById(storeId)
.orElseThrow(() -> new BusinessLogicException(ExceptionCode.STORE_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import org.springframework.stereotype.Service;

import com.readyvery.readyverydemo.domain.Store;
import com.readyvery.readyverydemo.domain.repository.StoreRepository;
import com.readyvery.readyverydemo.global.exception.BusinessLogicException;
import com.readyvery.readyverydemo.global.exception.ExceptionCode;
import com.readyvery.readyverydemo.src.store.dto.StoreDetailRes;
import com.readyvery.readyverydemo.src.store.dto.StoreEventRes;
import com.readyvery.readyverydemo.src.store.dto.StoreMapper;
Expand All @@ -16,29 +13,24 @@
@Service
@RequiredArgsConstructor
public class StoreServiceImpl implements StoreService {
private final StoreRepository storeRepository;
private final StoreServiceFacade storeServiceFacade;
private final StoreMapper storeMapper;

@Override
public StoreDetailRes getStoreDetail(Long storeId) {
Store store = getStore(storeId);
Store store = storeServiceFacade.getStoreById(storeId);
return storeMapper.storeToStoreDetailRes(store);
}

private Store getStore(Long storeId) {
return storeRepository.findById(storeId)
.orElseThrow(() -> new BusinessLogicException(ExceptionCode.STORE_NOT_FOUND));
}

@Override
public StoreMenuRes getStoreMenu(Long storeId) {
Store store = getStore(storeId);
Store store = storeServiceFacade.getStoreById(storeId);
return storeMapper.storeToStoreMenuRes(store);
}

@Override
public StoreEventRes getStoreEvent(Long storeId) {
Store store = getStore(storeId);
Store store = storeServiceFacade.getStoreById(storeId);
return storeMapper.storeToStoreEventRes(store);
}

Expand Down

0 comments on commit f75e712

Please sign in to comment.