fix: 오류 수정
- 예약 물품 조회 시 인터넷 예약만 조회됨 -> 모든 예약물품 조회
This commit is contained in:
@@ -32,6 +32,7 @@ public class ReserveItemRequestDto extends RequestDto {
|
||||
private Long locationId;
|
||||
private String categoryId;
|
||||
private Boolean isUse;
|
||||
private Boolean isPopup;
|
||||
|
||||
public boolean hasLocationId() {
|
||||
return hasId(locationId);
|
||||
@@ -44,4 +45,8 @@ public class ReserveItemRequestDto extends RequestDto {
|
||||
private boolean hasId(Object id) {
|
||||
return Objects.nonNull(id) && !Objects.equals("null", id) && !Objects.equals("undefined", id);
|
||||
}
|
||||
|
||||
public boolean isPopup() {
|
||||
return Boolean.TRUE.equals(isPopup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,12 @@ package org.egovframe.cloud.reserveitemservice.domain.reserveItem;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import lombok.Builder;
|
||||
@@ -11,6 +17,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.egovframe.cloud.reactive.domain.BaseEntity;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemUpdateRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.code.Code;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.Location;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
@@ -271,6 +278,13 @@ public class ReserveItem extends BaseEntity {
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getRelationCodeIds() {
|
||||
return Arrays.asList(categoryId, reserveMethodId, reserveMeansId, selectionMeansId, targetId)
|
||||
.stream()
|
||||
.filter(it -> Objects.nonNull(it))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 예약 물품 정보 업데이트
|
||||
@@ -397,6 +411,28 @@ public class ReserveItem extends BaseEntity {
|
||||
private int calcInventoryQty(int reserveQty) {
|
||||
return inventoryQty - reserveQty;
|
||||
}
|
||||
|
||||
public void setCodeName(List<Code> codes) {
|
||||
codes.stream().filter(it -> it.getParentCodeId().equals("reserve-category"))
|
||||
.findFirst()
|
||||
.ifPresent(it -> setCategoryName(it.getCodeName()));
|
||||
|
||||
codes.stream().filter(it -> it.getParentCodeId().equals("reserve-method"))
|
||||
.findFirst()
|
||||
.ifPresent(it -> setReserveMethodName(it.getCodeName()));
|
||||
|
||||
codes.stream().filter(it -> it.getParentCodeId().equals("reserve-means"))
|
||||
.findFirst()
|
||||
.ifPresent(it -> setReserveMeansName(it.getCodeName()));
|
||||
|
||||
codes.stream().filter(it -> it.getParentCodeId().equals("reserve-selection"))
|
||||
.findFirst()
|
||||
.ifPresent(it -> setSelectionMeansName(it.getCodeName()));
|
||||
|
||||
codes.stream().filter(it -> it.getParentCodeId().equals("reserve-target"))
|
||||
.findFirst()
|
||||
.ifPresent(it -> setTargetName(it.getCodeName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@ import static org.springframework.data.relational.core.query.Criteria.where;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.code.Code;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.Location;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
@@ -98,8 +100,10 @@ public class ReserveItemRepositoryImpl implements ReserveItemRepositoryCustom{
|
||||
*/
|
||||
@Override
|
||||
public Flux<ReserveItem> findLatestByCategory(Integer count, String categoryId) {
|
||||
Query query =Query.query(where("category_id").is(categoryId)
|
||||
.and("use_at").isTrue()).sort(Sort.by(Sort.Order.desc(SORT_COLUMN)));
|
||||
Query query = Query.query(
|
||||
where("category_id").is(categoryId)
|
||||
.and("use_at").isTrue())
|
||||
.sort(Sort.by(Sort.Order.desc(SORT_COLUMN)));
|
||||
|
||||
if (count > 0) {
|
||||
query.limit(count);
|
||||
@@ -152,19 +156,16 @@ public class ReserveItemRepositoryImpl implements ReserveItemRepositoryCustom{
|
||||
* @return
|
||||
*/
|
||||
private Mono<ReserveItem> loadRelationsAll(final ReserveItem reserveItem) {
|
||||
//load common code
|
||||
Mono<ReserveItem> mono = Mono.just(reserveItem)
|
||||
.zipWith(findCodeById(reserveItem.getCategoryId()))
|
||||
.map(tuple -> tuple.getT1().setCategoryName(tuple.getT2().getCodeName()))
|
||||
.zipWith(findCodeById(reserveItem.getReserveMethodId()))
|
||||
.map(tuple -> tuple.getT1().setReserveMethodName(tuple.getT2().getCodeName()))
|
||||
.zipWith(findCodeById(reserveItem.getReserveMeansId()))
|
||||
.map(tuple -> tuple.getT1().setReserveMeansName(tuple.getT2().getCodeName()))
|
||||
.zipWith(findCodeById(reserveItem.getSelectionMeansId()))
|
||||
.map(tuple -> tuple.getT1().setSelectionMeansName(tuple.getT2().getCodeName()))
|
||||
.zipWith(findCodeById(reserveItem.getTargetId()))
|
||||
.map(tuple -> tuple.getT1().setTargetName(tuple.getT2().getCodeName()))
|
||||
.switchIfEmpty(Mono.just(reserveItem));
|
||||
|
||||
Mono<ReserveItem> mono = findCode(reserveItem.getRelationCodeIds())
|
||||
.collectList()
|
||||
.zipWith(Mono.just(reserveItem))
|
||||
.map(tuple -> {
|
||||
ReserveItem item = tuple.getT2();
|
||||
List<Code> codes = tuple.getT1();
|
||||
item.setCodeName(codes);
|
||||
return item;
|
||||
}).switchIfEmpty(Mono.just(reserveItem));
|
||||
|
||||
// load location
|
||||
mono = mono.zipWith(findLocationById(reserveItem.getLocationId()))
|
||||
@@ -194,11 +195,16 @@ public class ReserveItemRepositoryImpl implements ReserveItemRepositoryCustom{
|
||||
* @return
|
||||
*/
|
||||
private Mono<Code> findCodeById(String codeId ) {
|
||||
return entityTemplate.select(Code.class)
|
||||
.matching(Query.query(where("code_id").is(codeId)))
|
||||
.one()
|
||||
if (Objects.isNull(codeId)) {
|
||||
return Mono.empty();
|
||||
}
|
||||
return entityTemplate.selectOne(Query.query(where("code_id").is(codeId)), Code.class)
|
||||
.switchIfEmpty(Mono.empty());
|
||||
}
|
||||
|
||||
private Flux<Code> findCode(List<String> codeIds) {
|
||||
return entityTemplate
|
||||
.select(Query.query(where("code_id").in(codeIds)), Code.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,9 +232,12 @@ public class ReserveItemRepositoryImpl implements ReserveItemRepositoryCustom{
|
||||
whereCriteria.add(where("category_id").in(requestDto.getCategoryId()));
|
||||
}
|
||||
|
||||
// 물품 팝업에서 조회하는 경우 인터넷 예약이 가능한 물품만 조회
|
||||
if (requestDto.getIsUse()) {
|
||||
whereCriteria.add(where("use_at").isTrue());
|
||||
}
|
||||
|
||||
// 물품 팝업에서 조회하는 경우 인터넷 예약이 가능한 물품만 조회
|
||||
if (requestDto.isPopup()) {
|
||||
whereCriteria.add(where("reserve_method_id").is("internet"));
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
return validateInternet(value, context);
|
||||
}
|
||||
|
||||
if ("telephone".equals(reserveMethodId)) {
|
||||
if ("phone".equals(reserveMethodId)) {
|
||||
return validateTelephone(value, context);
|
||||
}
|
||||
|
||||
@@ -171,8 +171,7 @@ public class ReserveItemSaveValidator implements ConstraintValidator<ReserveItem
|
||||
context.disableDefaultConstraintViolation();
|
||||
//문의처 값은 필수입니다.
|
||||
context.buildConstraintViolationWithTemplate(
|
||||
messageUtil.getMessage("reserve_item.contact") + messageUtil
|
||||
.getMessage("valid.required"))
|
||||
messageUtil.getMessage("reserve_item.contact") + messageUtil.getMessage("valid.required"))
|
||||
.addPropertyNode("contact")
|
||||
.addConstraintViolation();
|
||||
return false;
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
package org.egovframe.cloud.reserveitemservice.api.reserveItem;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
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;
|
||||
@@ -26,24 +21,17 @@ import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItemRepo
|
||||
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;
|
||||
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.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;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@EnableConfigurationProperties
|
||||
|
||||
Reference in New Issue
Block a user