-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
521 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
db/src/main/java/db/domain/shipping/ShippingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
db/src/main/java/db/domain/shipping/enums/ShippingStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
18 changes: 18 additions & 0 deletions
18
warehouse/src/main/java/warehouse/common/error/ShippingErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
2 changes: 1 addition & 1 deletion
2
warehouse/src/main/java/warehouse/common/exception/Goods/InvalidGoodsStatusException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
warehouse/src/main/java/warehouse/common/exception/ShippingExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
warehouse/src/main/java/warehouse/common/exception/shipping/ShippingNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.