Skip to content

Commit

Permalink
[feat] 구매자 매장상세조회 (#106)
Browse files Browse the repository at this point in the history
* [feat] 구매자 매장 상세 조회 서비스

* [feat] 구매자 매장 상세 조회 Response 객체

- 구매자는 기본적인 매장 상세 정보를 확인할 수 있어야 함

* [feat] 가게주소, 가게카테고리에 대한 getter 추가

호출자 쪽에서의 getter depth 를 줄이기 위함

* [feat] 가게 id로 메뉴 목록을 조회하는 기능

* [feat] 가게 전시 응답에 가게 메뉴를 포함

* [feat] getter 추가

* [feat] 가게 전시 API 엔드포인트 구현

* [refactor] 가게 전시 메서드 이름 변경

* [test] 가게 전시 서비스 계층 단위 테스트

- responseDTO 을 적절히 매핑하여 반환하는지 테스트하기 위함

* [test] 가게 전시 API 컨트롤러 계층 단위 테스트

- API response 명세를 검증 및 추적하기 위함

* [text] 가게 조회 API 단위 테스트 - 메뉴 리스트 검증하도록 수정 및 테스트

* [merge] 머지 컨플릭트 해결
  • Loading branch information
june-777 authored Aug 19, 2024
1 parent 48bcf4b commit 6cc9211
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/main/java/camp/woowak/lab/menu/domain/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ public long updatePrice(long uPrice) {

return this.price;
}

public Long getMenuCategoryId() {
return menuCategory.getId();
}

public String getMenuCategoryName() {
return menuCategory.getName();
}

}
5 changes: 2 additions & 3 deletions src/main/java/camp/woowak/lab/menu/domain/MenuCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
Expand All @@ -22,6 +23,7 @@
@UniqueConstraint(name = "unique_store_name", columnNames = {"store_id", "name"})
}
)
@Getter
public class MenuCategory {

@Id
Expand All @@ -41,8 +43,5 @@ public MenuCategory(Store store, String name) {
this.name = name;
}

public Long getId() {
return id;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface MenuRepository extends JpaRepository<Menu, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT m FROM Menu m where m.id in :ids")
List<Menu> findAllByIdForUpdate(List<Long> ids);

List<Menu> findByStoreId(Long storeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public StoreDTO(Store store) {
this.id = store.getId();
this.name = store.getName();
this.ownerName = store.getOwner().getName();
this.address = store.getStoreAddress().getDistrict();
this.address = store.getStoreAddress();
this.phoneNumber = store.getPhoneNumber();
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/camp/woowak/lab/store/domain/Store.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package camp.woowak.lab.store.domain;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.UUID;

import camp.woowak.lab.store.exception.NotEqualsOwnerException;
Expand Down Expand Up @@ -81,4 +82,33 @@ public boolean isOpen() {

return (now.isEqual(openTime) || now.isAfter(openTime)) && now.isBefore(closeTime);
}

public String getStoreAddress() {
return storeAddress.getDistrict();
}

public Long getStoreCategoryId() {
return storeCategory.getId();
}

public String getStoreCategoryName() {
return storeCategory.getName();
}

public LocalTime getStoreStartTime() {
return storeTime.getStartTime().toLocalTime();
}

public LocalTime getStoreEndTime() {
return storeTime.getEndTime().toLocalTime();
}

public UUID getVendorId() {
return owner.getId();
}

public String getVendorName() {
return owner.getName();
}

}
3 changes: 3 additions & 0 deletions src/main/java/camp/woowak/lab/store/domain/StoreAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public StoreAddress(final String district) {
this.district = district;
}

public String getDistrict() {
return district;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package camp.woowak.lab.store.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import camp.woowak.lab.menu.domain.Menu;
import camp.woowak.lab.menu.repository.MenuRepository;
import camp.woowak.lab.store.domain.Store;
import camp.woowak.lab.store.exception.NotFoundStoreException;
import camp.woowak.lab.store.repository.StoreRepository;
import camp.woowak.lab.store.service.response.StoreDisplayResponse;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class StoreDisplayService {

private final StoreRepository storeRepository;
private final MenuRepository menuRepository;

@Transactional(readOnly = true)
public StoreDisplayResponse displayStore(final Long storeId) {
Store store = findStoreById(storeId);
List<Menu> storeMenus = findMenusByStore(store.getId());

return StoreDisplayResponse.of(store, mapFrom(storeMenus));
}

private Store findStoreById(final Long storeId) {
return storeRepository.findById(storeId)
.orElseThrow(() -> new NotFoundStoreException(storeId + "의 가게를 찾을 수 없습니다."));
}

private List<Menu> findMenusByStore(final Long storeId) {
return menuRepository.findByStoreId(storeId);
}

private List<StoreDisplayResponse.MenuDisplayResponse> mapFrom(final List<Menu> menus) {
return menus.stream()
.map(StoreDisplayResponse.MenuDisplayResponse::of)
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package camp.woowak.lab.store.service.response;

import java.time.LocalTime;
import java.util.List;
import java.util.UUID;

import camp.woowak.lab.menu.domain.Menu;
import camp.woowak.lab.store.domain.Store;

public record StoreDisplayResponse(

Long storeId,
String storeName,
String storeAddress,
String storePhoneNumber,
Integer storeMinOrderPrice,

Long storeCategoryId,
String storeCategoryName,

LocalTime storeStartTime,
LocalTime storeEndTime,

UUID vendorId,
String vendorName,

List<MenuDisplayResponse> menus
) {

public static StoreDisplayResponse of(final Store store, final List<MenuDisplayResponse> menus) {
return new StoreDisplayResponse(
store.getId(),
store.getName(),
store.getStoreAddress(),
store.getPhoneNumber(),
store.getMinOrderPrice(),

store.getStoreCategoryId(),
store.getStoreCategoryName(),

store.getStoreStartTime(),
store.getStoreEndTime(),

store.getVendorId(),
store.getVendorName(),
menus
);
}

public record MenuDisplayResponse(
Long menuCategoryId,
String menuCategoryName,

Long menuId,
String menuName,
Long menuPrice
) {

public static MenuDisplayResponse of(final Menu menu) {
return new MenuDisplayResponse(
menu.getMenuCategoryId(),
menu.getMenuCategoryName(),

menu.getId(),
menu.getName(),
menu.getPrice()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -13,11 +14,13 @@
import camp.woowak.lab.menu.service.MenuCategoryRegistrationService;
import camp.woowak.lab.menu.service.MenuPriceUpdateService;
import camp.woowak.lab.menu.service.command.MenuCategoryRegistrationCommand;
import camp.woowak.lab.store.service.StoreDisplayService;
import camp.woowak.lab.menu.service.command.MenuPriceUpdateCommand;
import camp.woowak.lab.store.service.StoreMenuRegistrationService;
import camp.woowak.lab.store.service.StoreRegistrationService;
import camp.woowak.lab.store.service.command.StoreMenuRegistrationCommand;
import camp.woowak.lab.store.service.command.StoreRegistrationCommand;
import camp.woowak.lab.store.service.response.StoreDisplayResponse;
import camp.woowak.lab.web.authentication.LoginVendor;
import camp.woowak.lab.web.authentication.annotation.AuthenticationPrincipal;
import camp.woowak.lab.web.dao.store.StoreDao;
Expand All @@ -43,6 +46,7 @@ public class StoreApiController {
private final MenuCategoryRegistrationService menuCategoryRegistrationService;
private final MenuPriceUpdateService menuPriceUpdateService;
private final StoreDao storeDao;
private final StoreDisplayService storeDisplayService;

@GetMapping("/stores")
public StoreInfoListResponse getStoreInfos(
Expand Down Expand Up @@ -111,4 +115,8 @@ public MenuCategoryRegistrationResponse storeCategoryRegistration(@Authenticatio
return new MenuCategoryRegistrationResponse(registeredId);
}

@GetMapping("/stores/{storeId}")
public StoreDisplayResponse storeDisplay(@PathVariable Long storeId) {
return storeDisplayService.displayStore(storeId);
}
}
Loading

0 comments on commit 6cc9211

Please sign in to comment.