Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
soongjamm committed Aug 4, 2021
2 parents 04921e2 + 7ed039f commit 8760142
Show file tree
Hide file tree
Showing 36 changed files with 205 additions and 624 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.bluedelivery.api.category;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -12,7 +10,6 @@
import org.springframework.web.bind.annotation.RequestMapping;

import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.category.Categories;

@RequestMapping("/categories")
public interface CategoryManagerController {
Expand All @@ -23,7 +20,7 @@ public interface CategoryManagerController {
* @return 카테고리 정보가 담긴 list
*/
@GetMapping
ResponseEntity<HttpResponse<List<Categories>>> getAllCategories();
ResponseEntity<HttpResponse<?>> getAllCategories();

/**
* 카테고리 추가
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.bluedelivery.common.response.ApiException;
import com.bluedelivery.common.response.ErrorCode;
import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.category.Categories;
import com.bluedelivery.domain.category.Category;

@RestController
Expand All @@ -29,7 +28,7 @@ public CategoryManagerControllerImpl(CategoryManagerService categoryManagerServi
this.categoryManagerService = categoryManagerService;
}

public ResponseEntity<HttpResponse<List<Categories>>> getAllCategories() {
public ResponseEntity<HttpResponse<?>> getAllCategories() {
List<Category> categories = categoryManagerService.getAllCategories();
return ResponseEntity.status(HttpStatus.OK).body(response(categories));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

import com.bluedelivery.api.shop.dto.BusinessHoursRequest;
import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.businesshour.BusinessHours;

@RequestMapping("/shops/{shopId}")
public interface ShopUpdateController {

@PutMapping("/business-hours")
ResponseEntity<HttpResponse<BusinessHours>> updateBusinessHours(
ResponseEntity<HttpResponse<?>> updateBusinessHours(
@PathVariable Long shopId, @RequestBody @Valid BusinessHoursRequest dto);

@PatchMapping("/introduce")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static com.bluedelivery.common.response.HttpResponse.FAIL;
import static com.bluedelivery.common.response.HttpResponse.response;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -18,7 +20,7 @@
import com.bluedelivery.common.response.ApiException;
import com.bluedelivery.common.response.ErrorCode;
import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.businesshour.BusinessHours;
import com.bluedelivery.domain.shop.BusinessHour;

@RestController
public class ShopUpdateControllerImpl implements ShopUpdateController {
Expand All @@ -29,9 +31,9 @@ public ShopUpdateControllerImpl(ShopUpdateService updateService) {
this.updateService = updateService;
}

public ResponseEntity<HttpResponse<BusinessHours>> updateBusinessHours(Long shopId, BusinessHoursRequest dto) {
public ResponseEntity<HttpResponse<?>> updateBusinessHours(Long shopId, BusinessHoursRequest dto) {
try {
BusinessHours businessHours = updateService.updateBusinessHour(dto.toTarget(shopId));
List<BusinessHour> businessHours = updateService.updateBusinessHour(dto.toTarget(shopId));
return ResponseEntity.ok(response(businessHours));
} catch (IllegalArgumentException ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response(FAIL, ex.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import javax.validation.constraints.NotNull;

import com.bluedelivery.application.shop.businesshour.BusinessHourType;
import com.bluedelivery.application.shop.dto.BusinessHourParam;
import com.bluedelivery.application.shop.dto.BusinessHoursTarget;
import com.bluedelivery.domain.businesshour.BusinessHourType;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public CategoryManagerServiceHttp(CategoryRepository categoryRepository) {

@Cacheable(value = "categories", cacheManager = "caffeineCacheManager")
public List<Category> getAllCategories() {
// TODO 카테고리 이름의 다국어처리 i18n
return categoryRepository.findAll();
}

Expand All @@ -48,7 +47,11 @@ public void editCategory(EditCategoryParam param) {

@Override
public List<Category> getCategoriesById(List<Long> categoryIds) {
return categoryRepository.findCategoriesByIdIn(categoryIds);
List<Category> categories = categoryRepository.findCategoriesByIdIn(categoryIds);
if (categories.size() != categoryIds.size()) {
throw new CategoryNotFoundException();
}
return categories;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@

import static com.bluedelivery.common.response.ErrorCode.*;

import java.time.DayOfWeek;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

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

import com.bluedelivery.api.shop.UpdateCategoryRequest;
import com.bluedelivery.api.shop.UpdateClosingDaysRequest;
import com.bluedelivery.application.category.CategoryManagerService;
import com.bluedelivery.application.shop.dto.BusinessHourParam;
import com.bluedelivery.application.shop.businesshour.DayOfWeekMapper;
import com.bluedelivery.application.shop.dto.BusinessHoursTarget;
import com.bluedelivery.common.response.ApiException;
import com.bluedelivery.domain.businesshour.BusinessHour;
import com.bluedelivery.domain.businesshour.BusinessHourRepository;
import com.bluedelivery.domain.businesshour.BusinessHours;
import com.bluedelivery.domain.businesshour.DayOfWeekMapper;
import com.bluedelivery.domain.closingday.LegalHolidayClosing;
import com.bluedelivery.domain.closingday.Suspension;
import com.bluedelivery.domain.shop.BusinessHour;
import com.bluedelivery.domain.shop.Shop;
import com.bluedelivery.domain.shop.ShopCategory;
import com.bluedelivery.domain.shop.ShopCategoryRepository;
import com.bluedelivery.domain.shop.ShopRepository;

import lombok.RequiredArgsConstructor;
Expand All @@ -37,29 +28,11 @@ public class ShopUpdateService {

private final ShopRepository shopRepository;
private final CategoryManagerService categoryManagerService;
private final BusinessHourRepository businessHourRepository;
private final ShopCategoryRepository shopCategoryRepository;

public BusinessHours updateBusinessHour(BusinessHoursTarget target) {
public List<BusinessHour> updateBusinessHour(BusinessHoursTarget target) {
Shop shop = getShop(target.getShopId());
List<BusinessHour> all = businessHourRepository.findAllByShop(shop);
// 입력받은 영업일 정책을 실제 요일과 매핑
Map<DayOfWeek, BusinessHourParam> resolved =
DayOfWeekMapper.map(target.getBusinessHourType(), target.getBusinessHours());

// 영업일이 없으면 입력을 그대로 저장
if (all.size() == 0) {
List<BusinessHour> list = resolved.entrySet().stream()
.map(entry -> entry.getValue().toEntity(entry.getKey()))
.collect(Collectors.toList());
Collections.sort(list);
return new BusinessHours(list);
}

for (BusinessHour businessHour : all) {
businessHour.update(resolved.get(businessHour.getDayOfWeek()));
}
return new BusinessHours(all);
shop.updateBusinessHours(DayOfWeekMapper.map(target));
return shop.getBusinessHours();
}

public void editIntroduce(Long id, String introduce) {
Expand All @@ -84,11 +57,7 @@ public void rename(Long id, String name) {

public void updateCategory(Long shopId, UpdateCategoryRequest dto) {
Shop shop = getShop(shopId);
shopCategoryRepository.deleteByShopId(shopId);
List<ShopCategory> shopCategories = categoryManagerService.getCategoriesById(dto.getCategoryIds()).stream()
.map(category -> new ShopCategory(shop, category))
.collect(Collectors.toList());
shopCategoryRepository.saveAll(shopCategories);
shop.updateCategoryIds(categoryManagerService.getCategoriesById(dto.getCategoryIds()));
}

public void updateClosingDays(Long id, UpdateClosingDaysRequest closingDays) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.bluedelivery.domain.businesshour;
package com.bluedelivery.application.shop.businesshour;

import java.time.DayOfWeek;
import java.util.List;
import java.util.Map;

import com.bluedelivery.api.shop.dto.BusinessHourDay;
import com.bluedelivery.application.shop.dto.BusinessHourParam;
import com.bluedelivery.domain.shop.BusinessHour;

public interface BusinessHourCondition {

boolean isSatisfied(BusinessHourType type, Map<BusinessHourDay, BusinessHourParam> params);

Map<DayOfWeek, BusinessHourParam> mapToDayOfWeek(Map<BusinessHourDay, BusinessHourParam> params);
List<BusinessHour> mapToDayOfWeek(Map<BusinessHourDay, BusinessHourParam> params);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bluedelivery.domain.businesshour;
package com.bluedelivery.application.shop.businesshour;

public enum BusinessHourType {
EVERY_SAME_TIME, WEEKDAY_SAT_SUNDAY
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.bluedelivery.domain.businesshour;
package com.bluedelivery.application.shop.businesshour;

import java.time.DayOfWeek;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.bluedelivery.api.shop.dto.BusinessHourDay;
import com.bluedelivery.application.shop.dto.BusinessHourParam;
import com.bluedelivery.application.shop.dto.BusinessHoursTarget;
import com.bluedelivery.domain.shop.BusinessHour;

public class DayOfWeekMapper {
private static final List<BusinessHourCondition> conditions = new ArrayList<>();
Expand All @@ -16,11 +19,15 @@ public class DayOfWeekMapper {
conditions.add(new WeekdayWeekendBusinessHourCondition());
}

public static Map<DayOfWeek, BusinessHourParam> map(
BusinessHourType type, Map<BusinessHourDay, BusinessHourParam> hours) {
public static List<BusinessHour> map(BusinessHoursTarget target) {
BusinessHourType type = target.getBusinessHourType();
Map<BusinessHourDay, BusinessHourParam> hours = target.getBusinessHours();

for (BusinessHourCondition condition : conditions) {
if (condition.isSatisfied(type, hours)) {
return condition.mapToDayOfWeek(hours);
List<BusinessHour> list = condition.mapToDayOfWeek(hours);
Collections.sort(list);
return list;
}
}
throw new IllegalArgumentException("wrong values for business hour");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.bluedelivery.domain.businesshour;
package com.bluedelivery.application.shop.businesshour;

import java.time.DayOfWeek;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.bluedelivery.api.shop.dto.BusinessHourDay;
import com.bluedelivery.application.shop.dto.BusinessHourParam;
import com.bluedelivery.domain.shop.BusinessHour;

public class EverydayBusinessHourCondition implements BusinessHourCondition {

Expand All @@ -20,12 +22,12 @@ public boolean isSatisfied(BusinessHourType type, Map<BusinessHourDay, BusinessH
}

@Override
public Map<DayOfWeek, BusinessHourParam> mapToDayOfWeek(Map<BusinessHourDay, BusinessHourParam> hours) {
Map<DayOfWeek, BusinessHourParam> map = new HashMap<>();
public List<BusinessHour> mapToDayOfWeek(Map<BusinessHourDay, BusinessHourParam> hours) {
List<BusinessHour> bhs = new ArrayList<>();
for (DayOfWeek day : DayOfWeek.values()) {
map.put(day, hours.get(BusinessHourDay.EVERY_DAY));
bhs.add(hours.get(BusinessHourDay.EVERY_DAY).toEntity(day));
}
return map;
return bhs;
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.bluedelivery.domain.businesshour;
package com.bluedelivery.application.shop.businesshour;

import static com.bluedelivery.api.shop.dto.BusinessHourDay.*;

import java.time.DayOfWeek;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.bluedelivery.api.shop.dto.BusinessHourDay;
import com.bluedelivery.application.shop.dto.BusinessHourParam;
import com.bluedelivery.domain.shop.BusinessHour;

public class WeekdayWeekendBusinessHourCondition implements BusinessHourCondition {

Expand All @@ -24,8 +24,8 @@ && hasRequiredDays(hours)) {
}

@Override
public Map<DayOfWeek, BusinessHourParam> mapToDayOfWeek(Map<BusinessHourDay, BusinessHourParam> hours) {
Map<DayOfWeek, BusinessHourParam> map = new HashMap<>();
public List<BusinessHour> mapToDayOfWeek(Map<BusinessHourDay, BusinessHourParam> hours) {
List<BusinessHour> bhs = new ArrayList<>();
BusinessHourParam weekday = hours.get(WEEKDAY);
BusinessHourParam saturday = hours.get(SATURDAY);
BusinessHourParam sunday = hours.get(SUNDAY);
Expand All @@ -34,12 +34,12 @@ public Map<DayOfWeek, BusinessHourParam> mapToDayOfWeek(Map<BusinessHourDay, Bus
if (day.compareTo(DayOfWeek.SATURDAY) >= 0) {
break;
}
map.put(day, weekday);
bhs.add(weekday.toEntity(day));
}
map.put(DayOfWeek.SATURDAY, saturday);
map.put(DayOfWeek.SUNDAY, sunday);
bhs.add(saturday.toEntity(DayOfWeek.SATURDAY));
bhs.add(sunday.toEntity(DayOfWeek.SUNDAY));

return map;
return bhs;
}

private boolean hasRequiredDays(Map<BusinessHourDay, BusinessHourParam> hours) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.DayOfWeek;
import java.time.LocalTime;

import com.bluedelivery.domain.businesshour.BusinessHour;
import com.bluedelivery.domain.shop.BusinessHour;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Map;

import com.bluedelivery.api.shop.dto.BusinessHourDay;
import com.bluedelivery.domain.businesshour.BusinessHourType;
import com.bluedelivery.application.shop.businesshour.BusinessHourType;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public ResponseEntity<HttpResponse> internalServerExceptionHandler(Exception ex)
log.error("500 error ", ex);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(response(
ERROR,
ex.toString()
));
.body(response(ERROR, "ERROR OCCURRED"));
}

}

This file was deleted.

Loading

0 comments on commit 8760142

Please sign in to comment.