Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyuung committed Jul 24, 2024
2 parents 80e28b4 + f2bc64f commit 113d1eb
Show file tree
Hide file tree
Showing 22 changed files with 521 additions and 19 deletions.
2 changes: 2 additions & 0 deletions db/src/main/java/db/domain/goods/GoodsEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ public class GoodsEntity extends BaseEntity {
@Column(length = 50, nullable = false, columnDefinition = "VARCHAR(50)")
private GoodsStatus status;

private Long shippingId;

}
3 changes: 1 addition & 2 deletions db/src/main/java/db/domain/goods/GoodsRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public interface GoodsRepository extends JpaRepository<GoodsEntity,Long> {

List<GoodsEntity> findAllByTakeBackIdOrderByIdDesc(Long takeBackId);

//TODO 출고 시스템 완료 후 구현 예정
//List<GoodsEntity> findAllByShippingIdOrderByIdDesc(Long takeBackId);
List<GoodsEntity> findAllByShippingIdOrderByIdDesc(Long takeBackId);

}
40 changes: 40 additions & 0 deletions db/src/main/java/db/domain/shipping/ShippingEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package db.domain.shipping;

import db.common.BaseEntity;
import db.domain.shipping.enums.ShippingStatus;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "shipping")
@SuperBuilder
public class ShippingEntity extends BaseEntity {

private LocalDateTime deliveryDate;

@Column(nullable = false, length = 200)
private String deliveryAddress;

@Enumerated(EnumType.STRING)
@Column(length = 50, nullable = false, columnDefinition = "VARCHAR(50)")
private ShippingStatus status;

@Column(nullable = false)
private Long userId;

private Long deliveryMan;

}
13 changes: 13 additions & 0 deletions db/src/main/java/db/domain/shipping/ShippingRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package db.domain.shipping;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ShippingRepository extends JpaRepository<ShippingEntity, Long> {

List<ShippingEntity> findAllByUserIdOrderByIdDesc(Long userId);

Optional<ShippingEntity> findFirstById(Long shippingId);

}
22 changes: 22 additions & 0 deletions db/src/main/java/db/domain/shipping/enums/ShippingStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package db.domain.shipping.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ShippingStatus {

PENDING(1,"출고 대기 중","출고 대기 중 입니다."),
REGISTERED(2,"출고 접수 완료", "출고 일정이 확정되었습니다."),
DELIVERY(3,"출고 중","물건을 안전하게 출고 중입니다."),
SHIPPED(4,"출고 완료", "물건이 지정된 장소에 도착하였습니다."),
CLOSE(5, "CLOSE", "요청이 닫힌 상태입니다.")
;

private final int current;
private final String status;
private final String description;

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package warehouse.common.error;

import global.errorcode.ErrorCodeIfs;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ShippingErrorCode implements ErrorCodeIfs {

SHIPPING_REQUEST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1500, "출고 요청서가 존재하지 않습니다.")
;

private final Integer httpCode;
private final Integer errorCode;
private final String description;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package warehouse.common.exception.goods;
package warehouse.common.exception.Goods;

import global.errorcode.ErrorCodeIfs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import warehouse.common.error.GoodsErrorCode;
import warehouse.common.exception.goods.InvalidGoodsStatusException;
import warehouse.common.exception.Goods.InvalidGoodsStatusException;
import warehouse.common.exception.goods.GoodsNotFoundException;

@Slf4j
Expand All @@ -24,8 +24,7 @@ public ResponseEntity<Api<Object>> imageException(GoodsNotFoundException e) {
}

@ExceptionHandler(value = InvalidGoodsStatusException.class)
public ResponseEntity<Api<Object>> InvalidGoodsStatus(
warehouse.common.exception.goods.InvalidGoodsStatusException e) {
public ResponseEntity<Api<Object>> InvalidGoodsStatus(InvalidGoodsStatusException e) {
log.info("", e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(Api.ERROR(GoodsErrorCode.INVALID_GOODS_STATUS));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package warehouse.common.exception;

import global.api.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import warehouse.common.error.ShippingErrorCode;
import warehouse.common.exception.shipping.ShippingNotFoundException;

@Slf4j
@RestControllerAdvice
public class ShippingExceptionHandler {

@ExceptionHandler(value = ShippingNotFoundException.class)
public ResponseEntity<Api<Object>> shippingNotFoundException(ShippingNotFoundException e) {
log.info("", e);
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(Api.ERROR(ShippingErrorCode.SHIPPING_REQUEST_NOT_FOUND));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package warehouse.common.exception.shipping;

import global.errorcode.ErrorCodeIfs;

public class ShippingNotFoundException extends RuntimeException {

private final ErrorCodeIfs errorCodeIfs;
private final String description;

public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs) {
super(errorCodeIfs.getDescription());
this.errorCodeIfs = errorCodeIfs;
this.description = errorCodeIfs.getDescription();
}

public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) {
this.errorCodeIfs = errorCodeIfs;
this.description = errorDescription;
}

public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) {
super(throwable);
this.errorCodeIfs = errorCodeIfs;
this.description = errorCodeIfs.getDescription();
}

public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable,
String errorDescription) {
super(throwable);
this.errorCodeIfs = errorCodeIfs;
this.description = errorDescription;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ public class GoodsBusiness {
private final ImageService imageService;
private final ImageConverter imageConverter;

public List<List<GoodsResponse>> getGoodsList(GetGoodsStrategy strategy,Long requestId) {
public List<GoodsResponse> getGoodsList(GetGoodsStrategy strategy,Long requestId) {

List<GoodsEntity> goodsList = findGoodsListById(strategy,requestId);

return getGoodsResponsesBy(goodsList);
}

public List<List<GoodsResponse>> getGoodsList(GoodsStatus status) {
public List<GoodsResponse> getGoodsList(GoodsStatus status) {

List<GoodsEntity> goodsList = goodsService.findAllByGoodsStatusWithThrow(status);

return getGoodsResponsesBy(goodsList);
}

private List<List<GoodsResponse>> getGoodsResponsesBy(List<GoodsEntity> goodsList) {
private List<GoodsResponse> getGoodsResponsesBy(List<GoodsEntity> goodsList) {

List<List<GoodsResponse>> goodsResponse = new ArrayList<>();
List<GoodsResponse> goodsResponse = new ArrayList<>();

goodsList.forEach(goodsEntity -> {

Expand All @@ -63,7 +63,7 @@ private List<List<GoodsResponse>> getGoodsResponsesBy(List<GoodsEntity> goodsLis
ImageListResponse imageListResponse = imageConverter.toImageListResponse(basicList,
faultList);

goodsResponse.add(goodsConverter.toResponseListBy(goodsList, imageListResponse));
goodsResponse.add(goodsConverter.toResponse(goodsEntity, imageListResponse));

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class GoodsController {
private final GoodsBusiness goodsBusiness;

@GetMapping("/{strategy}/{requestId}")
public Api<List<List<GoodsResponse>>> receiving(@PathVariable GetGoodsStrategy strategy, @PathVariable Long requestId) {
List<List<GoodsResponse>> response = goodsBusiness.getGoodsList(strategy,requestId);
public Api<List<GoodsResponse>> receiving(@PathVariable GetGoodsStrategy strategy, @PathVariable Long requestId) {
List<GoodsResponse> response = goodsBusiness.getGoodsList(strategy,requestId);
return Api.OK(response);
}

@GetMapping()
public Api<List<List<GoodsResponse>>> getGoodsByStatus(@RequestParam GoodsStatus status) {
List<List<GoodsResponse>> response = goodsBusiness.getGoodsList(status);
public Api<List<GoodsResponse>> getGoodsByStatus(@RequestParam GoodsStatus status) {
List<GoodsResponse> response = goodsBusiness.getGoodsList(status);
return Api.OK(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import warehouse.common.error.GoodsErrorCode;
import warehouse.common.exception.Goods.InvalidGoodsStatusException;
import warehouse.common.exception.goods.GoodsNotFoundException;
import warehouse.common.exception.goods.InvalidGoodsStatusException;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -133,8 +133,7 @@ public List<GoodsEntity> findAllByTakeBackIdWithThrow(Long takeBackId) {
return goodsEntityList;
}

//TODO 출고 시스템 완료 후 구현 예정
/*public List<GoodsEntity> findAllByShippingIdWithThrow(Long shippingId) {
public List<GoodsEntity> findAllByShippingIdWithThrow(Long shippingId) {

List<GoodsEntity> goodsEntityList = goodsRepository.findAllByShippingIdOrderByIdDesc(
shippingId);
Expand All @@ -143,6 +142,13 @@ public List<GoodsEntity> findAllByTakeBackIdWithThrow(Long takeBackId) {
throw new GoodsNotFoundException(GoodsErrorCode.GOODS_NOT_FOUND);
}
return goodsEntityList;
}*/
}

public void setShippingId(List<GoodsEntity> goodsEntityList, Long shippingId) {
goodsEntityList.forEach(goodsEntity -> {
goodsEntity.setShippingId(shippingId);
goodsRepository.save(goodsEntity);
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package warehouse.domain.shipping.business;

import db.domain.goods.GoodsEntity;
import db.domain.goods.enums.GoodsStatus;
import db.domain.image.ImageEntity;
import db.domain.image.enums.ImageKind;
import db.domain.shipping.ShippingEntity;
import global.annotation.Business;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import warehouse.domain.goods.controller.model.GoodsResponse;
import warehouse.domain.goods.converter.GoodsConverter;
import warehouse.domain.goods.service.GoodsService;
import warehouse.domain.image.controller.model.ImageListResponse;
import warehouse.domain.image.converter.ImageConverter;
import warehouse.domain.image.service.ImageService;
import warehouse.domain.shipping.controller.model.request.ShippingRequest;
import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse;
import warehouse.domain.shipping.controller.model.response.ShippingListResponse;
import warehouse.domain.shipping.controller.model.response.MessageResponse;
import warehouse.domain.shipping.controller.model.response.ShippingResponse;
import warehouse.domain.shipping.converter.ShippingConverter;
import warehouse.domain.shipping.service.ShippingService;
import warehouse.domain.users.service.UsersService;

@Business
@RequiredArgsConstructor
public class ShippingBusiness {

private final UsersService usersService;
private final GoodsService goodsService;
private final ShippingService shippingService;
private final ImageService imageService;
private final ShippingConverter shippingConverter;
private final GoodsConverter goodsConverter;
private final ImageConverter imageConverter;


public MessageResponse shippingRequest(ShippingRequest request, String email) {

// 상품이 STORAGE 인지 확인
goodsService.checkStoredGoodsAndStatusWithThrowBy(request.getGoodsIdList(),
GoodsStatus.STORAGE);

Long userId = usersService.getUserWithThrow(email).getId();

ShippingEntity shippingEntity = shippingConverter.toEntity(request);

ShippingEntity savedShippingEntity = shippingService.shippingRequest(shippingEntity, userId);

// GoodsStatus 를 SHIPPING_ING 으로 변경
goodsService.setGoodsStatusBy(request.getGoodsIdList(), GoodsStatus.SHIPPING_ING);

List<GoodsEntity> goodsEntityList = goodsService.getGoodsListBy(request.getGoodsIdList());

// goods 컬럼에 shipping_id 부여
goodsService.setShippingId(goodsEntityList, savedShippingEntity.getId());

return shippingConverter.toMessageResponse("출고 신청이 완료되었습니다.");

}


public ShippingListResponse getShippingList(String email) {

Long userId = usersService.getUserWithThrow(email).getId();

List<ShippingEntity> shippingEntityList = shippingService.getShippingList(userId);

return shippingConverter.toResponseList(shippingEntityList);

}

public ShippingDetailResponse getShippingDetail(Long shippingId) {

ShippingEntity shippingEntity = shippingService.getShippingDetail(shippingId);

ShippingResponse shippingResponse = shippingConverter.toResponse(shippingEntity);

List<Long> goodsIdList = goodsService.findAllByShippingIdWithThrow(shippingId).stream()
.map(entity -> entity.getId()).collect(Collectors.toList());

List<GoodsEntity> goodsEntityList = goodsService.getGoodsListBy(goodsIdList);

List<GoodsResponse> goodsResponse = goodsEntityList.stream()
.map(entity -> getGoodsResponse(entity)).collect(Collectors.toList());

return shippingConverter.toResponse(shippingResponse, goodsResponse);

}


private GoodsResponse getGoodsResponse(GoodsEntity goodsEntity) {
List<ImageEntity> basicImageEntityList = imageService.getImageUrlListBy(goodsEntity.getId(),
ImageKind.BASIC);
List<ImageEntity> faultImageEntityList = imageService.getImageUrlListBy(goodsEntity.getId(),
ImageKind.FAULT);
ImageListResponse imageListResponse = imageConverter.toImageListResponse(
basicImageEntityList, faultImageEntityList);
return goodsConverter.toResponse(goodsEntity, imageListResponse);
}


}
Loading

0 comments on commit 113d1eb

Please sign in to comment.