Skip to content

Commit

Permalink
feat: isEvent 추가 (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
Choi-JJunho committed May 9, 2024
1 parent bd168df commit 3955c94
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@

@JsonNaming(value = SnakeCaseStrategy.class)
public record OwnerShopsResponse(
Long count,
Integer count,
List<InnerShopResponse> shops
) {

public static OwnerShopsResponse from(List<Shop> shops) {
return new OwnerShopsResponse(
(long) shops.size(),
shops.stream()
.map(InnerShopResponse::from)
.toList()
);
public static OwnerShopsResponse from(List<InnerShopResponse> shops) {
return new OwnerShopsResponse(shops.size(), shops);
}

@JsonNaming(value = SnakeCaseStrategy.class)
private record InnerShopResponse(
public record InnerShopResponse(
Long id,
String name
String name,
boolean isEvent
) {

public static InnerShopResponse from(Shop shop) {
return new InnerShopResponse(shop.getId(), shop.getName());
public static InnerShopResponse from(Shop shop, boolean isEvent) {
return new InnerShopResponse(shop.getId(), shop.getName(), isEvent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import in.koreatech.koin.domain.owner.repository.OwnerRepository;
import in.koreatech.koin.domain.ownershop.dto.OwnerShopsRequest;
import in.koreatech.koin.domain.ownershop.dto.OwnerShopsResponse;
import in.koreatech.koin.domain.ownershop.dto.OwnerShopsResponse.InnerShopResponse;
import in.koreatech.koin.domain.shop.dto.CreateCategoryRequest;
import in.koreatech.koin.domain.shop.dto.CreateMenuRequest;
import in.koreatech.koin.domain.shop.dto.MenuCategoriesResponse;
Expand Down Expand Up @@ -68,7 +69,12 @@ public class OwnerShopService {

public OwnerShopsResponse getOwnerShops(Long ownerId) {
List<Shop> shops = shopRepository.findAllByOwnerId(ownerId);
return OwnerShopsResponse.from(shops);
var innerShopResponses = shops.stream().map(shop -> {
Boolean eventDuration = eventArticleRepository.isEvent(shop.getId(), LocalDate.now(clock));
return InnerShopResponse.from(shop, eventDuration);
})
.toList();
return OwnerShopsResponse.from(innerShopResponses);
}

@Transactional
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/in/koreatech/koin/domain/shop/dto/ShopsResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public record ShopsResponse(
@Schema(description = "상점 정보")
List<InnerShopResponse> shops
) {
public static ShopsResponse from(List<Shop> shops) {
return new ShopsResponse(
shops.size(),
shops.stream().map(InnerShopResponse::from).toList()
);

public static ShopsResponse from(List<InnerShopResponse> shops) {
return new ShopsResponse(shops.size(), shops);
}

@JsonNaming(value = SnakeCaseStrategy.class)
private record InnerShopResponse(
public record InnerShopResponse(
@Schema(example = "0", description = " 속해있는 상점 카테고리들의 고유 id 리스트")
List<Long> categoryIds,

Expand All @@ -49,9 +47,13 @@ private record InnerShopResponse(
boolean payCard,

@Schema(example = "041-000-0000", description = "전화번호")
String phone
String phone,

@Schema(example = "true", description = "삭제 여부")
boolean isEvent
) {
public static InnerShopResponse from(Shop shop) {

public static InnerShopResponse from(Shop shop, boolean isEvent) {
return new InnerShopResponse(
shop.getShopCategories().stream().map(shopCategoryMap ->
shopCategoryMap.getShopCategory().getId()
Expand All @@ -62,7 +64,8 @@ public static InnerShopResponse from(Shop shop) {
shop.getShopOpens().stream().map(InnerShopOpen::from).toList(),
shop.getPayBank(),
shop.getPayCard(),
shop.getPhone()
shop.getPhone(),
isEvent
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import in.koreatech.koin.domain.shop.dto.ShopMenuResponse;
import in.koreatech.koin.domain.shop.dto.ShopResponse;
import in.koreatech.koin.domain.shop.dto.ShopsResponse;
import in.koreatech.koin.domain.shop.dto.ShopsResponse.InnerShopResponse;
import in.koreatech.koin.domain.shop.model.EventArticle;
import in.koreatech.koin.domain.shop.model.Menu;
import in.koreatech.koin.domain.shop.model.MenuCategory;
Expand Down Expand Up @@ -70,7 +71,12 @@ public ShopMenuResponse getShopMenus(Long shopId) {

public ShopsResponse getShops() {
List<Shop> shops = shopRepository.findAll();
return ShopsResponse.from(shops);
var innerShopResponses = shops.stream().map(shop -> {
Boolean eventDuration = eventArticleRepository.isEvent(shop.getId(), LocalDate.now(clock));
return InnerShopResponse.from(shop, eventDuration);
})
.toList();
return ShopsResponse.from(innerShopResponses);
}

public ShopCategoriesResponse getShopsCategories() {
Expand Down

0 comments on commit 3955c94

Please sign in to comment.