Skip to content

Commit

Permalink
Merge pull request #194 from marinesnow34/refactor
Browse files Browse the repository at this point in the history
Feat: 가게 삭제 구현
  • Loading branch information
marinesnow34 authored Mar 7, 2024
2 parents 3a3cdda + fd2d7f5 commit 0f54baf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import org.hibernate.annotations.ColumnDefault;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -81,6 +83,11 @@ public class Store extends BaseTimeEntity {
@Enumerated(EnumType.STRING)
private Grade grade;

// 삭제 여부
@Column
@ColumnDefault("false")
private boolean isDeleted;

//가게 사장님 연관관계 매핑
@OneToMany(mappedBy = "store")
private List<CeoInfo> ceoInfos = new ArrayList<CeoInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BoardSearchRes toBoardSearchRes(List<Store> stores) {
throw new BusinessLogicException(ExceptionCode.STORE_NOT_FOUND);
}
return BoardSearchRes.builder()
.stores(stores.stream().map(this::toSearchStoreDto).toList())
.stores(stores.stream().filter(store -> !store.isDeleted()).map(this::toSearchStoreDto).toList())
.build();
}

Expand Down
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 0f54baf

Please sign in to comment.