Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
# openjdk8 base image
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
# config server uri: dockder run --e 로 변경 가능
|
||||
ENV SPRING_CLOUD_CONFIG_URI https://egov-config.paas-ta.org
|
||||
# jar 파일이 복사되는 위치
|
||||
ENV APP_HOME=/usr/app/
|
||||
# 작업 시작 위치
|
||||
|
||||
@@ -10,7 +10,7 @@ applications:
|
||||
- egov-discovery-provided-service # discovery service binding
|
||||
env:
|
||||
spring_profiles_active: cf
|
||||
spring_cloud_config_uri: https://egov-config.paas-ta.org
|
||||
spring_cloud_config_uri: http://localhost:8888
|
||||
app_name: egov-reserve-item-service # logstash custom app name
|
||||
TZ: Asia/Seoul
|
||||
JAVA_OPTS: -Xss349k
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
package org.egovframe.cloud.reserveitemservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
import reactivefeign.spring.config.EnableReactiveFeignClients;
|
||||
import reactor.blockhound.BlockHound;
|
||||
|
||||
import java.security.Security;
|
||||
|
||||
@ComponentScan({"org.egovframe.cloud.common", "org.egovframe.cloud.reactive", "org.egovframe.cloud.reserveitemservice"}) // org.egovframe.cloud.common package 포함하기 위해
|
||||
@EnableDiscoveryClient
|
||||
@EnableReactiveFeignClients
|
||||
@SpringBootApplication
|
||||
public class ReserveItemServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TLSv1/v1.1 No longer works after upgrade, "No appropriate protocol" error
|
||||
String property = Security.getProperty("jdk.tls.disabledAlgorithms").replace(", TLSv1", "").replace(", TLSv1.1", "");
|
||||
Security.setProperty("jdk.tls.disabledAlgorithms", property);
|
||||
|
||||
//blocking 코드 감지
|
||||
BlockHound.builder()
|
||||
/**
|
||||
* mysql r2dbc 에서 호출되는 FileInputStream.readBytes() 가 블로킹코드인데 이를 허용해주도록 한다.
|
||||
* 해당 코드가 어디서 호출되는지 알지 못하는 상태에서 FileInputStream.readBytes() 자체를 허용해주는 것은 좋지 않다.
|
||||
* 누군가 무분별하게 사용하게 되면 검출해 낼 수 없어 시스템의 위험요소로 남게 된다.
|
||||
* r2dbc를 사용하기 위해 FileInputStream.readBytes()를 호출하는 부분만 허용하고 나머지는 여전히 검출대상으로 남기도록 한다.
|
||||
*/
|
||||
.allowBlockingCallsInside("dev.miku.r2dbc.mysql.client.ReactorNettyClient", "init")
|
||||
.install();
|
||||
|
||||
SpringApplication.run(ReserveItemServiceApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package org.egovframe.cloud.reserveitemservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
import reactivefeign.spring.config.EnableReactiveFeignClients;
|
||||
//import reactor.blockhound.BlockHound;
|
||||
|
||||
import java.security.Security;
|
||||
|
||||
@ComponentScan({"org.egovframe.cloud.common", "org.egovframe.cloud.reactive", "org.egovframe.cloud.reserveitemservice"}) // org.egovframe.cloud.common package 포함하기 위해
|
||||
@EnableDiscoveryClient
|
||||
@EnableReactiveFeignClients
|
||||
@SpringBootApplication
|
||||
public class ReserveItemServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TLSv1/v1.1 No longer works after upgrade, "No appropriate protocol" error
|
||||
String property = Security.getProperty("jdk.tls.disabledAlgorithms").replace(", TLSv1", "").replace(", TLSv1.1", "");
|
||||
Security.setProperty("jdk.tls.disabledAlgorithms", property);
|
||||
|
||||
//blocking 코드 감지
|
||||
// BlockHound.builder()
|
||||
// /**
|
||||
// * mysql r2dbc 에서 호출되는 FileInputStream.readBytes() 가 블로킹코드인데 이를 허용해주도록 한다.
|
||||
// * 해당 코드가 어디서 호출되는지 알지 못하는 상태에서 FileInputStream.readBytes() 자체를 허용해주는 것은 좋지 않다.
|
||||
// * 누군가 무분별하게 사용하게 되면 검출해 낼 수 없어 시스템의 위험요소로 남게 된다.
|
||||
// * r2dbc를 사용하기 위해 FileInputStream.readBytes()를 호출하는 부분만 허용하고 나머지는 여전히 검출대상으로 남기도록 한다.
|
||||
// */
|
||||
// .allowBlockingCallsInside("dev.miku.r2dbc.mysql.client.ReactorNettyClient", "init")
|
||||
// .install();
|
||||
|
||||
SpringApplication.run(ReserveItemServiceApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemRes
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemSaveRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemUpdateRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.service.reserveItem.ReserveItemService;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -55,6 +56,21 @@ public class ReserveItemApiController {
|
||||
|
||||
private final ReserveItemService reserveItemService;
|
||||
|
||||
private final Environment env;
|
||||
|
||||
/**
|
||||
* 서비스 상태 확인
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/actuator/health-info")
|
||||
public String status() {
|
||||
return String.format("GET Reserve Item Service on" +
|
||||
"\n local.server.port :" + env.getProperty("local.server.port")
|
||||
+ "\n egov.message :" + env.getProperty("egov.message")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 목록 조회
|
||||
*
|
||||
@@ -97,7 +113,6 @@ public class ReserveItemApiController {
|
||||
@GetMapping("/api/v1/reserve-items/{reserveItemId}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public Mono<ReserveItemResponseDto> findById(@PathVariable Long reserveItemId) {
|
||||
System.out.println("findById : " + reserveItemId);
|
||||
return reserveItemService.findById(reserveItemId);
|
||||
}
|
||||
|
||||
@@ -148,7 +163,7 @@ public class ReserveItemApiController {
|
||||
@GetMapping("/api/v1/reserve-items/relations/{reserveItemId}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public Mono<ReserveItemRelationResponseDto> findByIdWithRelations(@PathVariable Long reserveItemId) {
|
||||
return reserveItemService.findByIdWithRelations(reserveItemId).log();
|
||||
return reserveItemService.findByIdWithRelations(reserveItemId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +176,6 @@ public class ReserveItemApiController {
|
||||
@PutMapping("/api/v1/reserve-items/{reserveItemId}/inventories")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public Mono<Boolean> updateInventory(@PathVariable Long reserveItemId, @RequestBody Integer reserveQty) {
|
||||
System.out.println("update inventories : " + reserveItemId+" : " + reserveQty);
|
||||
return reserveItemService.updateInventory(reserveItemId, reserveQty);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,49 +45,18 @@ public class ReserveItemListResponseDto {
|
||||
private Boolean isPossible; //예약 가능 여부
|
||||
|
||||
@Builder
|
||||
public ReserveItemListResponseDto(ReserveItem reserveItem) {
|
||||
this.reserveItemId = reserveItem.getReserveItemId();
|
||||
this.reserveItemName = reserveItem.getReserveItemName();
|
||||
this.locationId = reserveItem.getLocationId();
|
||||
this.locationName = reserveItem.getLocation().getLocationName();
|
||||
this.categoryId = reserveItem.getCategoryId();
|
||||
this.categoryName = reserveItem.getCategoryName();
|
||||
this.totalQty = reserveItem.getTotalQty();
|
||||
this.inventoryQty = reserveItem.getInventoryQty();
|
||||
this.isUse = reserveItem.getIsUse();
|
||||
this.createDate = reserveItem.getCreateDate();
|
||||
this.isPossible = isReservationPossible(reserveItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* 예약 가능 여부 체크
|
||||
*
|
||||
* @param reserveItem
|
||||
* @return
|
||||
*/
|
||||
private boolean isReservationPossible(ReserveItem reserveItem) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (!reserveItem.getIsUse()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reserveItem.getInventoryQty() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reserveItem.getIsPeriod()) {
|
||||
if (reserveItem.getRequestStartDate().isBefore(now) && reserveItem.getRequestEndDate().isAfter(now)) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (reserveItem.getOperationStartDate().isBefore(now) && reserveItem.getOperationEndDate().isAfter(now)) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public ReserveItemListResponseDto(ReserveItem entity) {
|
||||
this.reserveItemId = entity.getReserveItemId();
|
||||
this.reserveItemName = entity.getReserveItemName();
|
||||
this.locationId = entity.getLocationId();
|
||||
this.locationName = entity.getLocation().getLocationName();
|
||||
this.categoryId = entity.getCategoryId();
|
||||
this.categoryName = entity.getCategoryName();
|
||||
this.totalQty = entity.getTotalQty();
|
||||
this.inventoryQty = entity.getInventoryQty();
|
||||
this.isUse = entity.getIsUse();
|
||||
this.createDate = entity.getCreateDate();
|
||||
this.isPossible = entity.isReservationPossible();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,38 +36,7 @@ public class ReserveItemMainResponseDto {
|
||||
this.endDate = entity.getRequestEndDate();
|
||||
}
|
||||
}
|
||||
this.isPossible = isReservationPossible(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 예약 가능 여부 체크
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
private boolean isReservationPossible(ReserveItem entity) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (!entity.getIsUse()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.getInventoryQty() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.getIsPeriod()) {
|
||||
if (entity.getRequestStartDate().isBefore(now) && entity.getRequestEndDate().isAfter(now)) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (entity.getOperationStartDate().isBefore(now) && entity.getOperationEndDate().isAfter(now)) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.isPossible = entity.isReservationPossible();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public class ReserveItemRelationResponseDto {
|
||||
private String managerDept; //담당자 소속
|
||||
private String managerName; //담당자 이름
|
||||
private String managerContact; //담당자 연락처
|
||||
private Boolean isPossible; //예약 가능 여부
|
||||
|
||||
@Builder
|
||||
public ReserveItemRelationResponseDto(ReserveItem entity) {
|
||||
@@ -103,8 +104,9 @@ public class ReserveItemRelationResponseDto {
|
||||
this.managerDept = entity.getManagerDept();
|
||||
this.managerName = entity.getManagerName();
|
||||
this.managerContact = entity.getManagerContact();
|
||||
|
||||
this.isPossible = entity.isReservationPossible();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.egovframe.cloud.reserveitemservice.api.reserveItem.dto;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@@ -92,6 +93,43 @@ public class ReserveItemSaveRequestDto {
|
||||
@Size(max = 50)
|
||||
private String managerContact; //담당자 연락처
|
||||
|
||||
@Builder
|
||||
public ReserveItemSaveRequestDto(String reserveItemName, Long locationId, String categoryId, Integer totalQty,
|
||||
Integer inventoryQty, LocalDateTime operationStartDate, LocalDateTime operationEndDate,
|
||||
String reserveMethodId, String reserveMeansId, LocalDateTime requestStartDate,
|
||||
LocalDateTime requestEndDate, Boolean isPeriod, Integer periodMaxCount, String externalUrl,
|
||||
String selectionMeansId, Boolean isPaid, BigDecimal usageCost, Boolean isUse, String purpose,
|
||||
String address, String targetId, String excluded, String homepage, String contact, String managerDept,
|
||||
String managerName, String managerContact) {
|
||||
this.reserveItemName = reserveItemName;
|
||||
this.locationId = locationId;
|
||||
this.categoryId = categoryId;
|
||||
this.totalQty = totalQty;
|
||||
this.inventoryQty = inventoryQty;
|
||||
this.operationStartDate = operationStartDate;
|
||||
this.operationEndDate = operationEndDate;
|
||||
this.reserveMethodId = reserveMethodId;
|
||||
this.reserveMeansId = reserveMeansId;
|
||||
this.requestStartDate = requestStartDate;
|
||||
this.requestEndDate = requestEndDate;
|
||||
this.isPeriod = isPeriod;
|
||||
this.periodMaxCount = periodMaxCount;
|
||||
this.externalUrl = externalUrl;
|
||||
this.selectionMeansId = selectionMeansId;
|
||||
this.isPaid = isPaid;
|
||||
this.usageCost = usageCost;
|
||||
this.isUse = isUse;
|
||||
this.purpose = purpose;
|
||||
this.address = address;
|
||||
this.targetId = targetId;
|
||||
this.excluded = excluded;
|
||||
this.homepage = homepage;
|
||||
this.contact = contact;
|
||||
this.managerDept = managerDept;
|
||||
this.managerName = managerName;
|
||||
this.managerContact = managerContact;
|
||||
}
|
||||
|
||||
public ReserveItem toEntity() {
|
||||
return ReserveItem.builder()
|
||||
.reserveItemName(this.reserveItemName)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.egovframe.cloud.reserveitemservice.api.reserveItem.dto;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@@ -61,7 +62,6 @@ public class ReserveItemUpdateRequestDto {
|
||||
private String externalUrl; //외부링크
|
||||
@NotBlank
|
||||
private String selectionMeansId; //선별 방법 - 공통코드 reserve-selection
|
||||
@NotNull
|
||||
private Boolean isPaid; // 유/무료 - false: 무료, true: 유료
|
||||
private BigDecimal usageCost; //이용 요금
|
||||
private Boolean isUse; //사용여부
|
||||
@@ -83,6 +83,43 @@ public class ReserveItemUpdateRequestDto {
|
||||
@Size(max = 50)
|
||||
private String managerContact; //담당자 연락처
|
||||
|
||||
@Builder
|
||||
public ReserveItemUpdateRequestDto(String reserveItemName, Long locationId, String categoryId,
|
||||
Integer totalQty, Integer inventoryQty, LocalDateTime operationStartDate, LocalDateTime operationEndDate,
|
||||
String reserveMethodId, String reserveMeansId, LocalDateTime requestStartDate,
|
||||
LocalDateTime requestEndDate, Boolean isPeriod, Integer periodMaxCount, String externalUrl,
|
||||
String selectionMeansId, Boolean isPaid, BigDecimal usageCost, Boolean isUse, String purpose,
|
||||
String address, String targetId, String excluded, String homepage, String contact, String managerDept,
|
||||
String managerName, String managerContact) {
|
||||
this.reserveItemName = reserveItemName;
|
||||
this.locationId = locationId;
|
||||
this.categoryId = categoryId;
|
||||
this.totalQty = totalQty;
|
||||
this.inventoryQty = inventoryQty;
|
||||
this.operationStartDate = operationStartDate;
|
||||
this.operationEndDate = operationEndDate;
|
||||
this.reserveMethodId = reserveMethodId;
|
||||
this.reserveMeansId = reserveMeansId;
|
||||
this.requestStartDate = requestStartDate;
|
||||
this.requestEndDate = requestEndDate;
|
||||
this.isPeriod = isPeriod;
|
||||
this.periodMaxCount = periodMaxCount;
|
||||
this.externalUrl = externalUrl;
|
||||
this.selectionMeansId = selectionMeansId;
|
||||
this.isPaid = isPaid;
|
||||
this.usageCost = usageCost;
|
||||
this.isUse = isUse;
|
||||
this.purpose = purpose;
|
||||
this.address = address;
|
||||
this.targetId = targetId;
|
||||
this.excluded = excluded;
|
||||
this.homepage = homepage;
|
||||
this.contact = contact;
|
||||
this.managerDept = managerDept;
|
||||
this.managerName = managerName;
|
||||
this.managerContact = managerContact;
|
||||
}
|
||||
|
||||
public ReserveItem toEntity() {
|
||||
return ReserveItem.builder()
|
||||
.reserveItemName(this.reserveItemName)
|
||||
|
||||
@@ -278,7 +278,6 @@ public class ReserveItem extends BaseEntity {
|
||||
* @return
|
||||
*/
|
||||
public ReserveItem update(ReserveItemUpdateRequestDto updateRequestDto) {
|
||||
System.out.println("============ ?? : " + updateRequestDto.toString());
|
||||
this.reserveItemName = updateRequestDto.getReserveItemName();
|
||||
this.locationId = updateRequestDto.getLocationId();
|
||||
this.categoryId = updateRequestDto.getCategoryId();
|
||||
@@ -332,10 +331,46 @@ public class ReserveItem extends BaseEntity {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 생성일 세팅
|
||||
*
|
||||
* @param createDate
|
||||
* @return
|
||||
*/
|
||||
public ReserveItem setCreateDate(LocalDateTime createDate) {
|
||||
this.createDate = createDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 예약 가능 여부 체크
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean isReservationPossible() {
|
||||
if (!this.getIsUse()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.getInventoryQty() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (this.getReserveMethodId().equals("internet") && this.getReserveMeansId().equals("realtime")) {
|
||||
if (this.getRequestStartDate().isBefore(now) && this.getRequestEndDate().isAfter(now)) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.getOperationStartDate().isBefore(now) && this.getOperationEndDate().isAfter(now)) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,9 +33,6 @@ public interface ReserveItemRepositoryCustom {
|
||||
Flux<ReserveItem> search(ReserveItemRequestDto requestDto, Pageable pageable);
|
||||
Mono<Long> searchCount(ReserveItemRequestDto requestDto, Pageable pageable);
|
||||
|
||||
Flux<ReserveItem> searchForUser(String categoryId, ReserveItemRequestDto requestDto, Pageable pageable);
|
||||
Mono<Long> searchCountForUser(String categoryId, ReserveItemRequestDto requestDto, Pageable pageable);
|
||||
|
||||
Mono<ReserveItem> findWithRelation(Long reserveItemId);
|
||||
|
||||
Flux<ReserveItem> findLatestByCategory(Integer count, String categoryId);
|
||||
|
||||
@@ -77,42 +77,6 @@ public class ReserveItemRepositoryImpl implements ReserveItemRepositoryCustom{
|
||||
.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<ReserveItem> searchForUser(String categoryId, ReserveItemRequestDto requestDto, Pageable pageable) {
|
||||
Criteria where = Criteria.from(whereQuery(requestDto));
|
||||
|
||||
if (!"all".equals(categoryId)) {
|
||||
where = where.and(where("category_id").is(categoryId));
|
||||
}
|
||||
|
||||
Query query = Query.query(where("use_at").isTrue().and(where))
|
||||
.sort(Sort.by(Sort.Direction.DESC, "create_date"))
|
||||
.with(pageable);
|
||||
|
||||
return entityTemplate.select(ReserveItem.class)
|
||||
.matching(query)
|
||||
.all()
|
||||
.flatMap(this::loadRelations)
|
||||
.switchIfEmpty(Flux.empty());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<Long> searchCountForUser(String categoryId, ReserveItemRequestDto requestDto, Pageable pageable) {
|
||||
Criteria where = Criteria.from(whereQuery(requestDto));
|
||||
|
||||
if (!"all".equals(categoryId)) {
|
||||
where = where.and(where("category_id").is(categoryId));
|
||||
}
|
||||
|
||||
Query query = Query.query(where("use_at").isTrue().and(where))
|
||||
.sort(Sort.by(Sort.Direction.DESC, "create_date"))
|
||||
.with(pageable);
|
||||
return entityTemplate.select(ReserveItem.class)
|
||||
.matching(query)
|
||||
.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* relation 걸린 table 정보도 같이 조회
|
||||
* 공통코드, 지역
|
||||
@@ -258,11 +222,11 @@ public class ReserveItemRepositoryImpl implements ReserveItemRepositoryCustom{
|
||||
}
|
||||
}
|
||||
|
||||
if (requestDto.getLocationId() != null) {
|
||||
if (requestDto.getLocationId() != null && !"null".equals(requestDto.getLocationId()) && !"undefined".equals(requestDto.getLocationId())) {
|
||||
whereCriteria.add(where("location_id").in(requestDto.getLocationId()));
|
||||
}
|
||||
|
||||
if (requestDto.getCategoryId() != null ) {
|
||||
if (requestDto.getCategoryId() != null && !"null".equals(requestDto.getCategoryId()) && !"undefined".equals(requestDto.getCategoryId())) {
|
||||
whereCriteria.add(where("category_id").in(requestDto.getCategoryId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public class LocationService extends ReactiveAbstractService {
|
||||
.switchIfEmpty(monoResponseStatusEntityNotFoundException(locationId))
|
||||
.flatMap(locationRepository::delete)
|
||||
.onErrorResume(DataIntegrityViolationException.class,
|
||||
throwable -> Mono.error(new BusinessMessageException("참조하는 데이터가 있어 삭제할 수 없습니다.")));
|
||||
throwable -> Mono.error(new BusinessMessageException(getMessage("err.db.constraint.delete"))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.egovframe.cloud.reserveitemservice.service.reserveItem;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -79,7 +80,7 @@ public class ReserveItemService extends ReactiveAbstractService {
|
||||
* @return
|
||||
*/
|
||||
private Mono<ReserveItemListResponseDto> convertReserveItemListResponseDto(ReserveItem reserveItem) {
|
||||
return Mono.just(ReserveItemListResponseDto.builder().reserveItem(reserveItem).build());
|
||||
return Mono.just(ReserveItemListResponseDto.builder().entity(reserveItem).build());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,10 +109,13 @@ public class ReserveItemService extends ReactiveAbstractService {
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public Mono<Page<ReserveItemListResponseDto>> searchForUser(String categoryId, ReserveItemRequestDto requestDto, Pageable pageable) {
|
||||
return reserveItemRepository.searchForUser(categoryId, requestDto, pageable)
|
||||
if (!"all".equals(categoryId)) {
|
||||
requestDto.setCategoryId(categoryId);
|
||||
}
|
||||
return reserveItemRepository.search(requestDto, pageable)
|
||||
.flatMap(this::convertReserveItemListResponseDto)
|
||||
.collectList()
|
||||
.zipWith(reserveItemRepository.searchCountForUser(categoryId, requestDto, pageable))
|
||||
.zipWith(reserveItemRepository.searchCount(requestDto, pageable))
|
||||
.flatMap(tuple -> Mono.just(new PageImpl<>(tuple.getT1(), pageable, tuple.getT2())));
|
||||
}
|
||||
|
||||
@@ -200,22 +204,26 @@ public class ReserveItemService extends ReactiveAbstractService {
|
||||
.switchIfEmpty(monoResponseStatusEntityNotFoundException(reserveItemId))
|
||||
.flatMap(reserveItem -> {
|
||||
if (!Category.EDUCATION.isEquals(reserveItem.getCategoryId())) {
|
||||
return Mono.error(new BusinessMessageException("저장할 수 없습니다."));
|
||||
//해당 예약은 수정할 수 없습니다.
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.reserve_not_update")));
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (!(now.isAfter(reserveItem.getRequestStartDate()) && now.isBefore(reserveItem.getRequestEndDate()))) {
|
||||
return Mono.error(new BusinessMessageException("예약 가능 일자가 아닙니다."));
|
||||
//해당 날짜에는 예약할 수 없습니다.
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.reserve_date")));
|
||||
}
|
||||
|
||||
int qty = reserveItem.getInventoryQty() - reserveQty;
|
||||
if (qty < 0) {
|
||||
return Mono.error(new BusinessMessageException("재고가 없습니다."));
|
||||
//해당 날짜에 예약할 수 있는 재고수량이 없습니다.
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.reserve_count")));
|
||||
}
|
||||
|
||||
return Mono.just(reserveItem.updateInventoryQty(qty));
|
||||
})
|
||||
.flatMap(reserveItemRepository::save)
|
||||
.delayElement(Duration.ofSeconds(5))
|
||||
.publishOn(Schedulers.boundedElastic())
|
||||
.doOnNext(reserveItem -> {
|
||||
log.info("reserve item inventory updated success");
|
||||
|
||||
@@ -2,9 +2,12 @@ package org.egovframe.cloud.reserveitemservice.validator;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.egovframe.cloud.common.util.MessageUtil;
|
||||
import org.egovframe.cloud.reserveitemservice.validator.annotation.ReserveItemSaveValid;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -30,6 +33,11 @@ import java.time.LocalDateTime;
|
||||
@Slf4j
|
||||
public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItemSaveValid, Object> {
|
||||
|
||||
@Resource(
|
||||
name = "messageUtil"
|
||||
)
|
||||
protected MessageUtil messageUtil;
|
||||
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
@@ -54,7 +62,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
LocalDateTime operationEndDate = (LocalDateTime) getFieldValue(value, "operationEndDate");
|
||||
if (operationStartDate.isAfter(operationEndDate)) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("시작일이 종료일 보다 큽니다.")
|
||||
//시작일, 종료일, {0}이 {1}보다 늦습니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("valid.to_be_slow.format", new Object[]{messageUtil.getMessage("common.start_date"), messageUtil.getMessage("common.end_date")}))
|
||||
.addPropertyNode("operationStartDate")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
@@ -66,7 +75,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
// 예약 구분 필수
|
||||
if (isNull(value, "reserveMeansId")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("인터넷 예약인 경우 예약 구분은 필수입니다.")
|
||||
//인터넷 예약 구분 값은 필수 입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.reserve_means")+ messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("reserveMeansId")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
@@ -77,24 +87,28 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
// 예약 신청 기간 필수
|
||||
if (isNull(value, "requestStartDate")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("인터넷 예약인 경우 예약 신청 시작 기간은 필수입니다.")
|
||||
.addPropertyNode("requestStartDate")
|
||||
.addConstraintViolation();
|
||||
// 예약 신청 시작일 값은 필수 입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.request")+" "+messageUtil.getMessage("common.start_datetime") + messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("requestStartDate")
|
||||
.addConstraintViolation();
|
||||
|
||||
fieldValid = false;
|
||||
} else if (isNull(value, "requestEndDate")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("인터넷 예약인 경우 예약 신청 종료 기간은 필수입니다.")
|
||||
.addPropertyNode("requestEndDate")
|
||||
.addConstraintViolation();
|
||||
// 예약 신청 종료일 값은 필수 입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.request")+" "+messageUtil.getMessage("common.end_datetime") + messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("requestEndDate")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
}else {
|
||||
LocalDateTime requestStartDate = (LocalDateTime) getFieldValue(value, "requestStartDate");
|
||||
LocalDateTime requestEndDate = (LocalDateTime) getFieldValue(value, "requestEndDate");
|
||||
if (requestStartDate.isAfter(requestEndDate)) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("시작일이 종료일 보다 큽니다.")
|
||||
.addPropertyNode("requestStartDate")
|
||||
.addConstraintViolation();
|
||||
//시작일, 종료일, {0}이 {1}보다 늦습니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("valid.to_be_slow.format", new Object[]{messageUtil.getMessage("common.start_date"), messageUtil.getMessage("common.end_date")}))
|
||||
.addPropertyNode("requestStartDate")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
}
|
||||
}
|
||||
@@ -102,7 +116,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
//기간 지정 필수
|
||||
if (isNull(value, "isPeriod")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("인터넷 예약인 경우 기간 지정 여부는 필수입니다.")
|
||||
//기간 지정 가능 여부 값은 필수 입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.period_possible")+ messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("requestEndDate")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
@@ -111,7 +126,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
// 기간 지정 가능인 경우 최대 얘약일 수 필수
|
||||
if (isPeriod && isNull(value, "periodMaxCount")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("기간 지정이 가능인 경우 최대 예약 일수는 필수입니다.")
|
||||
//최대 예약 가능 일수 값은 필수 입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.max_period_days")+ messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("periodMaxCount")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
@@ -121,7 +137,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
//예약 구분이 외부 링크인 경우 외부 링크 url 필수
|
||||
if (isNull(value, "externalUrl")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("예약 구분이 외부링크인 경우 외부링크 url 값은 필수입니다.")
|
||||
//외부링크 URL 값은 필수 입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.external_url")+ messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("externalUrl")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
@@ -132,7 +149,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
//예약 방법인 '전화'인 경우 contact 필수
|
||||
if (isNull(value, "contact")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("전화예약인 경우 문의처는 필수입니다.")
|
||||
//문의처 값은 필수입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.contact")+ messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("contact")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
@@ -141,7 +159,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
//예약 방법인 '방문'인 경우 주소 필수
|
||||
if (isNull(value, "address")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("방문예약인 경우 주소는 필수입니다.")
|
||||
//주소 값은 필수 입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("common.address")+ messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("address")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
@@ -152,7 +171,8 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
Boolean isPaid = Boolean.valueOf(String.valueOf(getFieldValue(value, "isPaid")));
|
||||
if (isPaid && isNull(value, "usageCost")) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate("유료인 경우 이용 요금은 필수입니다.")
|
||||
//이용요금 값은 필수입니다.
|
||||
context.buildConstraintViolationWithTemplate(messageUtil.getMessage("reserve_item.usage_fee")+ messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("usageCost")
|
||||
.addConstraintViolation();
|
||||
fieldValid = false;
|
||||
|
||||
@@ -1,144 +1,183 @@
|
||||
package org.egovframe.cloud.reserveitemservice.api.location;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationSaveRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationUpdateRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.Location;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.LocationRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItem;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItemRepository;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@EnableConfigurationProperties
|
||||
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
|
||||
@ActiveProfiles("test")
|
||||
@Import({R2dbcConfig.class})
|
||||
class LocationApiControllerTest {
|
||||
public class LocationApiControllerTest {
|
||||
|
||||
@MockBean
|
||||
private LocationRepository locationRepository;
|
||||
@Autowired
|
||||
private LocationRepository locationRepository;
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webTestClient;
|
||||
@Autowired
|
||||
private ReserveItemRepository reserveItemRepository;
|
||||
|
||||
private final static String API_URL = "/api/v1/locations";
|
||||
@Autowired
|
||||
WebTestClient webTestClient;
|
||||
|
||||
private Location location = Location.builder()
|
||||
.locationId(1L)
|
||||
.locationName("location")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build();
|
||||
private static final String API_URL = "/api/v1/locations";
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
BDDMockito.when(locationRepository.findById(ArgumentMatchers.anyLong()))
|
||||
.thenReturn(Mono.just(location));
|
||||
//조회조건 있는 경우
|
||||
BDDMockito.when(locationRepository.findAllByLocationNameContainingOrderBySortSeq(
|
||||
ArgumentMatchers.anyString(), ArgumentMatchers.any(Pageable.class)))
|
||||
.thenReturn(Flux.just(location));
|
||||
BDDMockito.when(locationRepository.countAllByLocationNameContaining(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Mono.just(1L));
|
||||
//조회조건 없는 경우
|
||||
BDDMockito.when(locationRepository.findAllByOrderBySortSeq(ArgumentMatchers.any(Pageable.class)))
|
||||
.thenReturn(Flux.just(location));
|
||||
BDDMockito.when(locationRepository.count()).thenReturn(Mono.just(1L));
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
reserveItemRepository.deleteAll().block();
|
||||
locationRepository.deleteAll().block();
|
||||
}
|
||||
|
||||
BDDMockito.when(locationRepository.save(ArgumentMatchers.any(Location.class)))
|
||||
.thenReturn(Mono.just(location));
|
||||
@Test
|
||||
public void 한건조회_성공() throws Exception {
|
||||
|
||||
}
|
||||
Location location1 = locationRepository.save(Location.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()).block();
|
||||
assertNotNull(location1);
|
||||
|
||||
@Test
|
||||
public void 한건조회_성공() throws Exception {
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"/{locationId}", location.getLocationId())
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.locationName").isEqualTo(location.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 조회조건있는경우_페이지목록조회_성공() throws Exception {
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"?keywordType=locationName&keyword=location&page=0&size=3")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].locationName").isEqualTo(location.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 조회조건없는경우_페이지목록조회_성공() throws Exception {
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"?page=0&size=3")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].locationName").isEqualTo(location.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건저장_성공() throws Exception {
|
||||
webTestClient.post()
|
||||
.uri(API_URL)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(LocationSaveRequestDto.builder()
|
||||
.locationName(location.getLocationName())
|
||||
.isUse(location.getIsUse())
|
||||
.sortSeq(location.getSortSeq())
|
||||
.build()))
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectBody().jsonPath("$.locationName").isEqualTo(location.getLocationName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건수정_성공() throws Exception {
|
||||
webTestClient.put()
|
||||
.uri(API_URL+"/{locationId}", location.getLocationId())
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(LocationUpdateRequestDto.builder()
|
||||
.locationName("updateLocation")
|
||||
.isUse(location.getIsUse())
|
||||
.sortSeq(location.getSortSeq())
|
||||
.build()))
|
||||
.exchange()
|
||||
.expectStatus().isNoContent();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건삭제_참조데이터존재_삭제실패() throws Exception {
|
||||
BDDMockito.when(locationRepository.delete(ArgumentMatchers.any(Location.class)))
|
||||
.thenReturn(Mono.error(new DataIntegrityViolationException("integrity test")));
|
||||
webTestClient.delete()
|
||||
.uri(API_URL+"/{locationId}", 1L)
|
||||
.exchange()
|
||||
.expectStatus().isBadRequest();
|
||||
|
||||
}
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"/{locationId}", location1.getLocationId())
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.locationName").isEqualTo(location1.getLocationName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Test
|
||||
public void 조회조건있는경우_페이지목록조회_성공() throws Exception {
|
||||
|
||||
Location location1 = locationRepository.save(Location.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()).block();
|
||||
assertNotNull(location1);
|
||||
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"?keywordType=locationName&keyword=location&page=0&size=3")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].locationName").isEqualTo(location1.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 조회조건없는경우_페이지목록조회_성공() throws Exception {
|
||||
Location location1 = locationRepository.save(Location.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()).block();
|
||||
assertNotNull(location1);
|
||||
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"?page=0&size=3")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].locationName").isEqualTo(location1.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건저장_성공() throws Exception {
|
||||
webTestClient.post()
|
||||
.uri(API_URL)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(LocationSaveRequestDto.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()))
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectBody().jsonPath("$.locationName").isEqualTo("location1");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건수정_성공() throws Exception {
|
||||
Location location1 = locationRepository.save(Location.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()).block();
|
||||
assertNotNull(location1);
|
||||
|
||||
webTestClient.put()
|
||||
.uri(API_URL+"/{locationId}", location1.getLocationId())
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(LocationUpdateRequestDto.builder()
|
||||
.locationName("updateLocation")
|
||||
.isUse(location1.getIsUse())
|
||||
.sortSeq(location1.getSortSeq())
|
||||
.build()))
|
||||
.exchange()
|
||||
.expectStatus().isNoContent();
|
||||
|
||||
Location updatedLocation = locationRepository.findById(location1.getLocationId()).block();
|
||||
assertNotNull(updatedLocation);
|
||||
assertEquals(updatedLocation.getLocationName(), "updateLocation");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건삭제_참조데이터존재_삭제실패() throws Exception {
|
||||
Location location1 = locationRepository.save(Location.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()).block();
|
||||
assertNotNull(location1);
|
||||
|
||||
reserveItemRepository.save(ReserveItem.builder()
|
||||
.locationId(location1.getLocationId())
|
||||
.categoryId("test")
|
||||
.build()).block();
|
||||
|
||||
webTestClient.delete()
|
||||
.uri(API_URL+"/{locationId}", location1.getLocationId())
|
||||
.exchange()
|
||||
.expectStatus().isBadRequest();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건삭제_성공() throws Exception {
|
||||
Location location1 = locationRepository.save(Location.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()).block();
|
||||
assertNotNull(location1);
|
||||
|
||||
webTestClient.delete()
|
||||
.uri(API_URL+"/{locationId}", location1.getLocationId())
|
||||
.exchange()
|
||||
.expectStatus().isNoContent();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
package org.egovframe.cloud.reserveitemservice.api.reserveItem;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.egovframe.cloud.common.exception.dto.ErrorCode;
|
||||
import org.egovframe.cloud.common.exception.dto.ErrorResponse;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemMainResponseDto;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemResponseDto;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemSaveRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemUpdateRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.code.Code;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.Location;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.LocationRepository;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItem;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItemRepository;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.BDDMockito;
|
||||
@@ -17,7 +33,10 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@@ -29,136 +48,243 @@ import reactor.core.publisher.Mono;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@EnableConfigurationProperties
|
||||
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
|
||||
@ActiveProfiles(profiles = "test")
|
||||
@ActiveProfiles("test")
|
||||
@Import({R2dbcConfig.class})
|
||||
class ReserveItemApiControllerTest {
|
||||
|
||||
@Autowired
|
||||
private LocationRepository locationRepository;
|
||||
|
||||
@MockBean
|
||||
ReserveItemRepository reserveItemRepository;
|
||||
@Autowired
|
||||
private ReserveItemRepository reserveItemRepository;
|
||||
|
||||
@Autowired
|
||||
private R2dbcEntityTemplate entityTemplate;
|
||||
|
||||
@Autowired
|
||||
WebTestClient webTestClient;
|
||||
|
||||
private final static String API_URL = "/api/v1/reserve-items";
|
||||
|
||||
Code category = null;
|
||||
Location location = null;
|
||||
ReserveItem reserveItem = ReserveItem.builder().build();
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
entityTemplate.delete(Code.class).all().block();
|
||||
reserveItemRepository.deleteAll().block();
|
||||
locationRepository.deleteAll().block();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
category = Code.builder().codeName("category").codeId("category").parentCodeId("reserve-category").build();
|
||||
entityTemplate.insert(Code.class)
|
||||
.using(category).block();
|
||||
location = locationRepository.save(Location.builder()
|
||||
.locationName("location1")
|
||||
.isUse(true)
|
||||
.sortSeq(1)
|
||||
.build()).block();
|
||||
assertNotNull(location);
|
||||
reserveItem = ReserveItem.builder()
|
||||
.categoryId(category.getCodeId())
|
||||
.locationId(location.getLocationId())
|
||||
.reserveItemName("test")
|
||||
.isUse(Boolean.TRUE)
|
||||
.operationStartDate(LocalDateTime.of(2021, 10, 1, 1, 1))
|
||||
.operationEndDate(LocalDateTime.of(2021, 10, 31, 23, 59))
|
||||
.reserveMethodId("internet")
|
||||
.reserveMeansId("realtime")
|
||||
.requestStartDate(LocalDateTime.of(2021, 10, 1, 1, 1))
|
||||
.requestEndDate(LocalDateTime.of(2021, 10, 31, 23, 59))
|
||||
.totalQty(100)
|
||||
.inventoryQty(100)
|
||||
.isPeriod(Boolean.FALSE)
|
||||
.selectionMeansId("evaluate")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void 사용자별_검색_목록_조회_성공() throws Exception {
|
||||
LocalDateTime startDate = LocalDateTime.of(2021, 1, 28, 1,1);
|
||||
LocalDateTime endDate = LocalDateTime.of(2021, 12, 6, 1,1);
|
||||
public void 사용자목록조회_성공() throws Exception {
|
||||
|
||||
Location location = Location.builder()
|
||||
.locationId(1L)
|
||||
.locationName("location")
|
||||
.sortSeq(1)
|
||||
.isUse(true)
|
||||
.build();
|
||||
ReserveItem reserveItem = ReserveItem.builder()
|
||||
.reserveItemId(1L)
|
||||
.location(location)
|
||||
.locationId(location.getLocationId())
|
||||
.reserveItemName("test")
|
||||
.categoryId("education")
|
||||
.categoryName("교육")
|
||||
.totalQty(100)
|
||||
.inventoryQty(80)
|
||||
.operationEndDate(endDate)
|
||||
.operationStartDate(startDate)
|
||||
.isPeriod(false)
|
||||
.isUse(true)
|
||||
.build();
|
||||
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
|
||||
assertNotNull(saved);
|
||||
|
||||
BDDMockito.when(reserveItemRepository.searchForUser(ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.any(ReserveItemRequestDto.class), ArgumentMatchers.any(Pageable.class)))
|
||||
.thenReturn(Flux.just(reserveItem));
|
||||
webTestClient.method(HttpMethod.GET)
|
||||
.uri("/api/v1/"+category.getCodeId()+"/reserve-items"+"?page=0&size=3&isUse=true")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].reserveItemName").isEqualTo(reserveItem.getReserveItemName());
|
||||
}
|
||||
|
||||
BDDMockito.when(reserveItemRepository.searchCountForUser(ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.any(ReserveItemRequestDto.class), ArgumentMatchers.any(Pageable.class)))
|
||||
.thenReturn(Mono.just(1L));
|
||||
@Test
|
||||
public void 관리자목록조회_성공() throws Exception {
|
||||
|
||||
webTestClient.get()
|
||||
.uri("/api/v1/{categoryId}/reserve-items?keywordType=locationName&keyword=location&page=0&size=3", "education")
|
||||
.exchange()
|
||||
.expectStatus().isOk();
|
||||
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
|
||||
assertNotNull(saved);
|
||||
|
||||
webTestClient.method(HttpMethod.GET)
|
||||
.uri(API_URL+"?page=0&size=3&isUse=false")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].reserveItemName").isEqualTo(reserveItem.getReserveItemName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건조회_성공() throws Exception {
|
||||
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
|
||||
assertNotNull(saved);
|
||||
|
||||
ReserveItemResponseDto responseBody = webTestClient.get()
|
||||
.uri(API_URL+"/{reserveItemId}", saved.getReserveItemId())
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody(ReserveItemResponseDto.class)
|
||||
.returnResult().getResponseBody();
|
||||
|
||||
assertThat(responseBody.getCategoryId()).isEqualTo(category.getCodeId());
|
||||
assertThat(responseBody.getReserveItemName()).isEqualTo(saved.getReserveItemName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void main_예약물품조회_성공() throws Exception {
|
||||
BDDMockito.when(reserveItemRepository.findCodeDetail(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Flux.fromIterable(Arrays.asList(Code.builder().codeId("education").codeName("교육").build(),
|
||||
Code.builder().codeId("equipment").codeName("장비").build(),
|
||||
Code.builder().codeId("space").codeName("장소").build())));
|
||||
public void 사용자_포털_메인_예약목록_조회_성공() throws Exception {
|
||||
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
|
||||
assertNotNull(saved);
|
||||
|
||||
LocalDateTime startDate = LocalDateTime.of(2021, 1, 28, 1,1);
|
||||
LocalDateTime endDate = LocalDateTime.of(2021, 12, 6, 1,1);
|
||||
|
||||
Location location = Location.builder()
|
||||
.locationId(1L)
|
||||
.locationName("location")
|
||||
.sortSeq(1)
|
||||
.isUse(true)
|
||||
.build();
|
||||
ReserveItem reserveItem1 = ReserveItem.builder()
|
||||
.reserveItemId(1L)
|
||||
.location(location)
|
||||
.locationId(location.getLocationId())
|
||||
.reserveItemName("test")
|
||||
.categoryId("education")
|
||||
.categoryName("교육")
|
||||
.totalQty(100)
|
||||
.inventoryQty(80)
|
||||
.operationEndDate(endDate)
|
||||
.operationStartDate(startDate)
|
||||
.reserveMethodId("visit")
|
||||
.isPeriod(false)
|
||||
.isUse(true)
|
||||
.build();
|
||||
ReserveItem reserveItem2 = ReserveItem.builder()
|
||||
.reserveItemId(1L)
|
||||
.location(location)
|
||||
.locationId(location.getLocationId())
|
||||
.reserveItemName("test")
|
||||
.categoryId("education")
|
||||
.categoryName("장비")
|
||||
.totalQty(100)
|
||||
.inventoryQty(80)
|
||||
.operationEndDate(endDate)
|
||||
.operationStartDate(startDate)
|
||||
.reserveMethodId("visit")
|
||||
.isPeriod(false)
|
||||
.isUse(true)
|
||||
.build();
|
||||
|
||||
ReserveItem reserveItem3 = ReserveItem.builder()
|
||||
.reserveItemId(1L)
|
||||
.location(location)
|
||||
.locationId(location.getLocationId())
|
||||
.reserveItemName("test")
|
||||
.categoryId("education")
|
||||
.categoryName("공간")
|
||||
.totalQty(100)
|
||||
.inventoryQty(80)
|
||||
.operationEndDate(endDate)
|
||||
.operationStartDate(startDate)
|
||||
.reserveMethodId("visit")
|
||||
.isPeriod(false)
|
||||
.isUse(true)
|
||||
.build();
|
||||
reserveItem1.setCreateDate(LocalDateTime.now());
|
||||
reserveItem2.setCreateDate(LocalDateTime.now());
|
||||
reserveItem3.setCreateDate(LocalDateTime.now());
|
||||
|
||||
BDDMockito.when(reserveItemRepository.findLatestByCategory(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Flux.fromIterable(Arrays.asList(reserveItem1, reserveItem2, reserveItem3)));
|
||||
|
||||
|
||||
webTestClient.get()
|
||||
.uri("/api/v1/reserve-items/latest/3")
|
||||
Map<String, Collection<ReserveItemMainResponseDto>> responseBody = webTestClient.get()
|
||||
.uri(API_URL+"/latest/3")
|
||||
.exchange()
|
||||
.expectStatus().isOk();
|
||||
.expectStatus().isOk()
|
||||
.expectBody(new ParameterizedTypeReference<Map<String, Collection<ReserveItemMainResponseDto>>>() {
|
||||
})
|
||||
.returnResult().getResponseBody();
|
||||
|
||||
assertThat(responseBody.keySet().size()).isEqualTo(1);
|
||||
assertThat(responseBody.keySet().contains(category.getCodeId())).isTrue();
|
||||
Collection<ReserveItemMainResponseDto> reserveItemMainResponseDtos = responseBody.get(category.getCodeId());
|
||||
reserveItemMainResponseDtos.stream().forEach(reserveItemMainResponseDto -> {
|
||||
assertThat(reserveItemMainResponseDto.getReserveItemName().equals(saved.getReserveItemName()));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건_등록_성공() throws Exception {
|
||||
ReserveItemSaveRequestDto requestDto = ReserveItemSaveRequestDto.builder()
|
||||
.reserveItemName(reserveItem.getReserveItemName())
|
||||
.categoryId(reserveItem.getCategoryId())
|
||||
.locationId(reserveItem.getLocationId())
|
||||
.inventoryQty(reserveItem.getInventoryQty())
|
||||
.totalQty(reserveItem.getTotalQty())
|
||||
.operationStartDate(reserveItem.getOperationStartDate())
|
||||
.operationEndDate(reserveItem.getOperationEndDate())
|
||||
.reserveMethodId(reserveItem.getReserveMethodId())
|
||||
.reserveMeansId(reserveItem.getReserveMeansId())
|
||||
.isUse(reserveItem.getIsUse())
|
||||
.requestStartDate(reserveItem.getRequestStartDate())
|
||||
.requestEndDate(reserveItem.getRequestEndDate())
|
||||
.isPeriod(reserveItem.getIsPeriod())
|
||||
.selectionMeansId(reserveItem.getSelectionMeansId())
|
||||
.build();
|
||||
|
||||
ReserveItemResponseDto responseBody = webTestClient.post()
|
||||
.uri(API_URL)
|
||||
.bodyValue(requestDto)
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectBody(ReserveItemResponseDto.class)
|
||||
.returnResult().getResponseBody();
|
||||
|
||||
System.out.println(responseBody);
|
||||
assertThat(responseBody.getReserveItemName()).isEqualTo(requestDto.getReserveItemName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건_수정_성공() throws Exception {
|
||||
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
|
||||
assertNotNull(saved);
|
||||
|
||||
ReserveItemUpdateRequestDto requestDto = ReserveItemUpdateRequestDto.builder()
|
||||
.reserveItemName("update")
|
||||
.categoryId(reserveItem.getCategoryId())
|
||||
.locationId(reserveItem.getLocationId())
|
||||
.inventoryQty(reserveItem.getInventoryQty())
|
||||
.totalQty(reserveItem.getTotalQty())
|
||||
.operationStartDate(reserveItem.getOperationStartDate())
|
||||
.operationEndDate(reserveItem.getOperationEndDate())
|
||||
.reserveMethodId(reserveItem.getReserveMethodId())
|
||||
.reserveMeansId(reserveItem.getReserveMeansId())
|
||||
.isUse(reserveItem.getIsUse())
|
||||
.requestStartDate(reserveItem.getRequestStartDate())
|
||||
.requestEndDate(reserveItem.getRequestEndDate())
|
||||
.isPeriod(reserveItem.getIsPeriod())
|
||||
.selectionMeansId(reserveItem.getSelectionMeansId())
|
||||
.build();
|
||||
|
||||
webTestClient.put()
|
||||
.uri(API_URL+"/"+saved.getReserveItemId())
|
||||
.bodyValue(requestDto)
|
||||
.exchange()
|
||||
.expectStatus().isNoContent();
|
||||
|
||||
ReserveItem findbyid = reserveItemRepository.findById(saved.getReserveItemId()).block();
|
||||
assertThat(findbyid.getReserveItemName()).isEqualTo("update");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 사용여부_false_수정_성공() throws Exception {
|
||||
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
|
||||
assertNotNull(saved);
|
||||
|
||||
webTestClient.put()
|
||||
.uri(API_URL+"/"+saved.getReserveItemId()+"/false")
|
||||
.exchange()
|
||||
.expectStatus().isNoContent();
|
||||
|
||||
ReserveItem findbyid = reserveItemRepository.findById(saved.getReserveItemId()).block();
|
||||
assertThat(findbyid.getIsUse()).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건_저장_validation_실패() throws Exception {
|
||||
ReserveItemSaveRequestDto requestDto = ReserveItemSaveRequestDto.builder()
|
||||
.reserveItemName(reserveItem.getReserveItemName())
|
||||
.categoryId(reserveItem.getCategoryId())
|
||||
.locationId(reserveItem.getLocationId())
|
||||
.inventoryQty(reserveItem.getInventoryQty())
|
||||
.totalQty(reserveItem.getTotalQty())
|
||||
.operationStartDate(reserveItem.getOperationStartDate())
|
||||
.operationEndDate(reserveItem.getOperationEndDate())
|
||||
.reserveMethodId(reserveItem.getReserveMethodId())
|
||||
.reserveMeansId(reserveItem.getReserveMeansId())
|
||||
.isUse(reserveItem.getIsUse())
|
||||
.isPeriod(reserveItem.getIsPeriod())
|
||||
.selectionMeansId(reserveItem.getSelectionMeansId())
|
||||
.build();
|
||||
|
||||
ErrorResponse responseBody = webTestClient.post()
|
||||
.uri(API_URL)
|
||||
.bodyValue(requestDto)
|
||||
.exchange()
|
||||
.expectStatus().isBadRequest()
|
||||
.expectBody(ErrorResponse.class)
|
||||
.returnResult().getResponseBody();
|
||||
|
||||
assertThat(responseBody.getCode()).isEqualTo(ErrorCode.INVALID_INPUT_VALUE.getCode());
|
||||
assertThat(responseBody.getErrors().size()).isEqualTo(1);
|
||||
responseBody.getErrors().stream().forEach(fieldError -> {
|
||||
assertThat(fieldError.getField()).isEqualTo("requestStartDate");
|
||||
System.out.println(fieldError.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class R2dbcConfig{
|
||||
@Bean
|
||||
public H2ConnectionFactory connectionFactory() {
|
||||
return new H2ConnectionFactory(H2ConnectionConfiguration.builder()
|
||||
.tcp("localhost", "~/querydsl")
|
||||
.inMemory("testdb")
|
||||
.property(H2ConnectionOption.DB_CLOSE_DELAY, "-1")
|
||||
.username("sa")
|
||||
.build());
|
||||
|
||||
@@ -2,20 +2,6 @@ spring:
|
||||
application:
|
||||
name: reserve-item-service
|
||||
|
||||
datasource:
|
||||
url: jdbc:h2:mem:testdb;MODE=MYSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
|
||||
username: sa
|
||||
password:
|
||||
driver-class-name: org.h2.Driver
|
||||
jpa:
|
||||
hibernate:
|
||||
generate-ddl: true
|
||||
ddl-auto: create-drop
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
default_batch_fetch_size: 1000
|
||||
show-sql: true
|
||||
h2:
|
||||
console:
|
||||
enabled: true
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
CREATE TABLE IF NOT EXISTS location(
|
||||
location_id BIGINT AUTO_INCREMENT,
|
||||
location_name VARCHAR(200),
|
||||
use_at tinyint(1) default 1 null,
|
||||
sort_seq smallint(3) null,
|
||||
create_date DATE null,
|
||||
modified_date DATE null,
|
||||
created_by VARCHAR(255) null,
|
||||
last_modified_by VARCHAR(255) null,
|
||||
CONSTRAINT PERSON_PK PRIMARY KEY (location_id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS `code` (
|
||||
`code_id` varchar(20) NOT NULL COMMENT '코드 id',
|
||||
`code_name` varchar(500) NOT NULL COMMENT '코드 명',
|
||||
`parent_code_id` varchar(20) DEFAULT NULL COMMENT '부모 코드 id',
|
||||
use_at BOOLEAN NULL DEFAULT TRUE COMMENT '사용 여부',
|
||||
PRIMARY KEY (`code_id`)
|
||||
) ;
|
||||
|
||||
-- location Table Create SQL
|
||||
CREATE TABLE IF NOT EXISTS location
|
||||
(
|
||||
location_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '지역 id',
|
||||
location_name VARCHAR(200) NULL COMMENT '지역 이름',
|
||||
sort_seq SMALLINT(3) NULL COMMENT '정렬 순서',
|
||||
use_at BOOLEAN NULL DEFAULT TRUE COMMENT '사용 여부',
|
||||
created_by VARCHAR(255) NULL COMMENT '생성자',
|
||||
create_date DATETIME NULL COMMENT '생성일',
|
||||
last_modified_by VARCHAR(255) NULL COMMENT '수정자',
|
||||
modified_date DATETIME NULL COMMENT '수정일',
|
||||
PRIMARY KEY (location_id)
|
||||
) ;
|
||||
|
||||
|
||||
|
||||
-- reserve_item Table Create SQL
|
||||
@@ -18,20 +29,21 @@ CREATE TABLE IF NOT EXISTS reserve_item
|
||||
reserve_item_name VARCHAR(200) NULL COMMENT '예약 물품 이름',
|
||||
location_id BIGINT NULL COMMENT '지역 id',
|
||||
category_id VARCHAR(20) NULL COMMENT '예약유형 - 공통코드 reserve-category',
|
||||
capacity_count MEDIUMINT(5) NULL COMMENT '재고/수용인원 수',
|
||||
total_qty BIGINT(18) NULL COMMENT '총 재고/수용인원 수',
|
||||
inventory_qty BIGINT(18) NULL COMMENT '현재 남은 재고/수용인원 수',
|
||||
operation_start_date DATETIME NULL COMMENT '운영 시작 일',
|
||||
operation_end_date DATETIME NULL COMMENT '운영 종료 일',
|
||||
reserve_method_id VARCHAR(20) NULL COMMENT '예약 방법 - 공통코드 reserve-method',
|
||||
reserve_means_id VARCHAR(20) NULL COMMENT '예약 구분 (인터넷 예약 시) - 공통코드 reserve-means',
|
||||
request_start_date DATETIME NULL COMMENT '예약 신청 시작 일시',
|
||||
request_end_date DATETIME NULL COMMENT '예약 신청 종료 일시',
|
||||
period_at TINYINT(1) NULL DEFAULT 0 COMMENT '기간 지정 가능 여부 - true: 지정 가능, false: 지정 불가',
|
||||
period_at BOOLEAN NULL DEFAULT FALSE COMMENT '기간 지정 가능 여부 - true: 지정 가능, false: 지정 불가',
|
||||
period_max_count SMALLINT(3) NULL COMMENT '최대 예약 가능 일 수',
|
||||
external_url VARCHAR(500) NULL COMMENT '외부링크',
|
||||
selection_means_id VARCHAR(20) NULL COMMENT '선별 방법 - 공통코드 reserve-selection-means',
|
||||
free_at TINYINT(1) NULL DEFAULT 1 COMMENT '유/무료 - true: 무료, false: 유료',
|
||||
paid_at BOOLEAN NULL DEFAULT FALSE COMMENT '유/무료 - false: 무료, true: 유료',
|
||||
usage_cost DECIMAL(18, 0) NULL COMMENT '이용 요금',
|
||||
use_at TINYINT(1) NULL DEFAULT 1 COMMENT '사용 여부',
|
||||
use_at BOOLEAN NULL DEFAULT TRUE COMMENT '사용 여부',
|
||||
purpose_content VARCHAR(4000) NULL COMMENT '용도',
|
||||
item_addr VARCHAR(500) NULL COMMENT '주소',
|
||||
target_id VARCHAR(20) NULL COMMENT '이용 대상 - 공통코드 reserve-target',
|
||||
@@ -45,5 +57,10 @@ CREATE TABLE IF NOT EXISTS reserve_item
|
||||
created_by VARCHAR(255) NULL COMMENT '생성자',
|
||||
modified_date DATETIME NULL COMMENT '수정일',
|
||||
last_modified_by VARCHAR(255) NULL COMMENT '수정자',
|
||||
PRIMARY KEY (reserve_item_id)
|
||||
);
|
||||
PRIMARY KEY (reserve_item_id),
|
||||
CONSTRAINT FK_reserve_item_location_id FOREIGN KEY (location_id)
|
||||
REFERENCES location (location_id) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user