-
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
11 changed files
with
493 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,37 @@ | ||
package db.domain.usedgoods; | ||
|
||
import db.common.BaseEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
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 = "usedgoods") | ||
@SuperBuilder | ||
public class UsedGoodsEntity extends BaseEntity { | ||
|
||
@Column(nullable = false, length = 50,columnDefinition = "VARCHAR(50)") | ||
private String title; | ||
|
||
private int price; | ||
|
||
@Column(nullable = false, length = 1000) | ||
private String description; | ||
|
||
private LocalDateTime postedAt; | ||
|
||
@Column(nullable = false) | ||
private Long userId; | ||
|
||
} | ||
|
7 changes: 7 additions & 0 deletions
7
db/src/main/java/db/domain/usedgoods/UsedGoodsRepository.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,7 @@ | ||
package db.domain.usedgoods; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UsedGoodsRepository extends JpaRepository<UsedGoodsEntity, Long> { | ||
|
||
} |
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
114 changes: 114 additions & 0 deletions
114
warehouse/src/main/java/warehouse/domain/usedgoods/business/UsedGoodsBusiness.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,114 @@ | ||
package warehouse.domain.usedgoods.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.usedgoods.UsedGoodsEntity; | ||
import global.annotation.Business; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
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.usedgoods.controller.model.request.UsedGoodsPostRequest; | ||
import warehouse.domain.usedgoods.controller.model.response.TransformUsedGoodsResponse; | ||
import warehouse.domain.usedgoods.controller.model.response.UsedGoodsPostResponse; | ||
import warehouse.domain.usedgoods.converter.UsedGoodsConverter; | ||
import warehouse.domain.usedgoods.service.UsedGoodsService; | ||
import warehouse.domain.users.service.UsersService; | ||
|
||
@Business | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class UsedGoodsBusiness { | ||
|
||
private final GoodsService goodsService; | ||
private final UsersService usersService; | ||
private final UsedGoodsService usedGoodsService; | ||
private final ImageService imageService; | ||
|
||
private final UsedGoodsConverter usedGoodsConverter; | ||
private final ImageConverter imageConverter; | ||
private final GoodsConverter goodsConverter; | ||
|
||
public TransformUsedGoodsResponse transformUsedGoods(Long goodsId) { | ||
|
||
// GoodsStatus 가 STORAGE 가 아닌 경우 예외 | ||
goodsService.checkStoredGoodsAndStatusWithThrowBy(List.of(goodsId), GoodsStatus.STORAGE); | ||
|
||
// GoodsStatus 를 USED 로 변경 | ||
goodsService.setGoodsStatusBy(List.of(goodsId), GoodsStatus.USED); | ||
|
||
GoodsEntity goodsEntity = goodsService.getGoodsListBy(goodsId); | ||
|
||
return usedGoodsConverter.toResponse(goodsEntity); | ||
} | ||
|
||
public List<TransformUsedGoodsResponse> transformUsedGoods(List<Long> goodsIdList) { | ||
|
||
goodsService.checkStoredGoodsAndStatusWithThrowBy(goodsIdList, GoodsStatus.STORAGE); | ||
|
||
goodsService.setGoodsStatusBy(goodsIdList, GoodsStatus.USED); | ||
|
||
List<GoodsEntity> goodsEntityList = goodsService.getGoodsListBy(goodsIdList); | ||
|
||
return usedGoodsConverter.toResponse(goodsEntityList); | ||
} | ||
|
||
public TransformUsedGoodsResponse cancelUsedGoodsRequest(Long goodsId) { | ||
|
||
goodsService.checkStoredGoodsAndStatusWithThrowBy(goodsId, GoodsStatus.USED); | ||
|
||
goodsService.setGoodsStatusBy(List.of(goodsId), GoodsStatus.STORAGE); | ||
|
||
GoodsEntity goodsEntity = goodsService.getGoodsListBy(goodsId); | ||
|
||
return usedGoodsConverter.toResponse(goodsEntity); | ||
} | ||
|
||
public List<TransformUsedGoodsResponse> cancelUsedGoodsRequest(List<Long> goodsIdList) { | ||
|
||
goodsService.checkStoredGoodsAndStatusWithThrowBy(goodsIdList, GoodsStatus.USED); | ||
|
||
goodsService.setGoodsStatusBy(goodsIdList, GoodsStatus.STORAGE); | ||
|
||
List<GoodsEntity> goodsEntityList = goodsService.getGoodsListBy(goodsIdList); | ||
|
||
return usedGoodsConverter.toResponse(goodsEntityList); | ||
} | ||
|
||
public UsedGoodsPostResponse post(UsedGoodsPostRequest request, String email) { | ||
|
||
goodsService.checkStoredGoodsAndStatusWithThrowBy(request.getGoodsId(), GoodsStatus.USED); | ||
|
||
Long userId = usersService.getUserWithThrow(email).getId(); | ||
|
||
UsedGoodsEntity usedGoodsEntity = usedGoodsConverter.toEntity(request); | ||
|
||
UsedGoodsEntity savedEntity = usedGoodsService.post(usedGoodsEntity, userId); | ||
|
||
GoodsEntity goodsEntity = goodsService.getGoodsListBy(request.getGoodsId()); | ||
|
||
GoodsResponse goodsResponse = getGoodsResponse( | ||
goodsEntity); | ||
|
||
return usedGoodsConverter.toResponse(savedEntity, 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); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
warehouse/src/main/java/warehouse/domain/usedgoods/controller/UsedGoodsApiController.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,63 @@ | ||
package warehouse.domain.usedgoods.controller; | ||
|
||
import global.annotation.ApiValid; | ||
import global.api.Api; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import warehouse.domain.usedgoods.business.UsedGoodsBusiness; | ||
import warehouse.domain.usedgoods.controller.model.request.UsedGoodsPostRequest; | ||
import warehouse.domain.usedgoods.controller.model.response.TransformUsedGoodsResponse; | ||
import warehouse.domain.usedgoods.controller.model.response.UsedGoodsPostResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/usedgoods") | ||
public class UsedGoodsApiController { | ||
|
||
private final UsedGoodsBusiness usedGoodsBusiness; | ||
|
||
@PostMapping("/{goodsId}") | ||
public Api<TransformUsedGoodsResponse> transformUsedGoods(@PathVariable Long goodsId) { | ||
TransformUsedGoodsResponse response = usedGoodsBusiness.transformUsedGoods(goodsId); | ||
return Api.OK(response); | ||
} | ||
|
||
@PostMapping | ||
public Api<List<TransformUsedGoodsResponse>> transformUsedGoods( | ||
@RequestBody Api<List<Long>> goodsIdList | ||
) { | ||
List<TransformUsedGoodsResponse> responses = usedGoodsBusiness.transformUsedGoods( | ||
goodsIdList.getBody()); | ||
return Api.OK(responses); | ||
} | ||
|
||
@PostMapping("/cancel/{goodsId}") | ||
public Api<TransformUsedGoodsResponse> cancelUsedGoodsRequest(@PathVariable Long goodsId) { | ||
TransformUsedGoodsResponse response = usedGoodsBusiness.cancelUsedGoodsRequest(goodsId); | ||
return Api.OK(response); | ||
} | ||
|
||
@PostMapping("/cancel") | ||
public Api<List<TransformUsedGoodsResponse>> cancelUsedGoodsRequest( | ||
@RequestBody Api<List<Long>> goodsIdList) { | ||
List<TransformUsedGoodsResponse> response = usedGoodsBusiness.cancelUsedGoodsRequest( | ||
goodsIdList.getBody()); | ||
return Api.OK(response); | ||
} | ||
|
||
@PostMapping("/post") | ||
public Api<UsedGoodsPostResponse> post(@AuthenticationPrincipal User user, | ||
@RequestBody @ApiValid Api<UsedGoodsPostRequest> request) { | ||
UsedGoodsPostResponse response = usedGoodsBusiness.post( | ||
request.getBody(), user.getUsername()); | ||
return Api.OK(response); | ||
} | ||
|
||
} |
Oops, something went wrong.