Skip to content

Commit

Permalink
Merge pull request #75 from hershyYJ/feature/#74
Browse files Browse the repository at this point in the history
[feature/#74] Add seller image when retrieving products
  • Loading branch information
hershyYJ authored Nov 26, 2024
2 parents 677b307 + 3821d37 commit 0ebfed2
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 33 deletions.
26 changes: 13 additions & 13 deletions src/main/java/com/api/jaebichuri/admin/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.api.jaebichuri.screening.entity.AuctionScreening;
import com.api.jaebichuri.screening.enums.AuctionScreeningStatus;
import com.api.jaebichuri.screening.repository.ScreeningRepository;
import com.api.jaebichuri.shipping.entity.Shipment;
import com.api.jaebichuri.shipping.entity.Shipping;
import com.api.jaebichuri.shipping.enums.ShippingStatus;
import com.api.jaebichuri.shipping.repository.ShippingRepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -70,7 +70,7 @@ public String updateShipmentStatus(Long auctionId, ShippingStatus newStatus, Str

handleStatusSpecificUpdates(auction, newStatus, shippingCompany, trackingNumber);

return "Shipment status updated successfully.";
return "shipping status updated successfully.";
}

private void moveToAuction(AuctionScreening screening) {
Expand All @@ -86,37 +86,37 @@ private void moveToAuction(AuctionScreening screening) {
auctionRepository.save(auction);
}

private Shipment findOrCreateShipment(Auction auction, ShippingStatus newStatus) {
private Shipping findOrCreateShipment(Auction auction, ShippingStatus newStatus) {
return shippingRepository.findByAuction(auction)
.orElseGet(() -> {
if (newStatus == ShippingStatus.PAYMENT_CONFIRMED) {
Shipment newShipment = Shipment.builder()
Shipping newshipping = Shipping.builder()
.auction(auction)
.shippingStatus(newStatus)
.build();

shippingRepository.save(newShipment);
return newShipment;
shippingRepository.save(newshipping);
return newshipping;
} else {
throw new CustomException(ErrorStatus._SHIPPING_NOT_FOUND);
}
});
}

private void handleStatusSpecificUpdates(Auction auction, ShippingStatus newStatus, String shippingCompany, String trackingNumber) {
Shipment shipment = findOrCreateShipment(auction, newStatus);
Shipping shipping = findOrCreateShipment(auction, newStatus);

shipment.updateShippingStatus(newStatus);
shipping.updateShippingStatus(newStatus);

if (newStatus == ShippingStatus.SHIPPING) {
shipment.updateShippingCompany(shippingCompany);
shipment.updateTrackingNumber(trackingNumber);
shipment.updateShippingDate(LocalDateTime.now());
shipping.updateShippingCompany(shippingCompany);
shipping.updateTrackingNumber(trackingNumber);
shipping.updateShippingDate(LocalDateTime.now());
} else if (newStatus == ShippingStatus.DELIVERED) {
shipment.updateDeliveryDate(LocalDateTime.now());
shipping.updateDeliveryDate(LocalDateTime.now());
}

shippingRepository.save(shipment);
shippingRepository.save(shipping);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class EndedProductDetailsDto {
@Schema(description = "경매 등록자 닉네임", example = "에코마켓")
private String sellerNickname;

@Schema(description = "경매 등록자 프로필 이미지 URL", example = "http://example.com/profile.jpg")
private String sellerProfileImage;

@Schema(description = "상품 사진 URL 목록")
private List<String> images;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class OngoingProductDetailsDto {
@Schema(description = "경매 등록자 닉네임", example = "에코마켓")
private String sellerNickname;

@Schema(description = "경매 등록자 프로필 이미지 URL", example = "http://example.com/profile.jpg")
private String sellerProfileImage;

@Schema(description = "경매 마감 시간", example = "")
private LocalDateTime endTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class UpcomingProductDetailsDto {
@Schema(description = "경매 등록자 닉네임", example = "에코마켓")
private String sellerNickname;

@Schema(description = "경매 등록자 프로필 이미지 URL", example = "http://example.com/profile.jpg")
private String sellerProfileImage;

@Schema(description = "상품 사진 URL 목록")
private List<String> images;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public interface ProductMapper {
@Mapping(source = "product.productName", target = "productName")
@Mapping(source = "product.productDescription", target = "productDescription")
@Mapping(source = "seller.nickname", target = "sellerNickname")
@Mapping(source = "seller.kakaoProfileImage", target = "sellerProfileImage")
@Mapping(target = "images", expression = "java(filterRepresentativeImages(auction.getProduct().getImages()))")
UpcomingProductDetailsDto auctionToUpcomingAuctionProductDto(Auction auction);

@Mapping(source = "product.id", target = "productId")
@Mapping(source = "product.productName", target = "productName")
@Mapping(target = "productDescription", source = "product.productDescription")
@Mapping(source = "seller.nickname", target = "sellerNickname")
@Mapping(source = "seller.kakaoProfileImage", target = "sellerProfileImage")
@Mapping(source = "product.images", target = "images")
EndedProductDetailsDto toEndedProductDetailsDto(Auction auction);

Expand All @@ -41,6 +43,7 @@ public interface ProductMapper {
@Mapping(source = "auction.product.productName", target = "productName")
@Mapping(source = "auction.product.productDescription", target = "productDescription")
@Mapping(source = "sellerNickname", target = "sellerNickname")
@Mapping(source = "auction.seller.kakaoProfileImage", target = "sellerProfileImage")
@Mapping(source = "auction.endTime", target = "endTime")
@Mapping(source = "auction.numOfBidders", target = "numOfBidders")
@Mapping(source = "top3BidDatePrice", target = "top3BidDatePrice")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.api.jaebichuri.global.response.ApiResponse;
import com.api.jaebichuri.member.entity.Member;
import com.api.jaebichuri.shipping.dto.ShipmentDetailsDto;
import com.api.jaebichuri.shipping.dto.ShippingDetailsDto;
import com.api.jaebichuri.shipping.dto.ShippingStatusCountDto;
import com.api.jaebichuri.shipping.service.ShippingService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -50,13 +50,13 @@ public ResponseEntity<ApiResponse<ShippingStatusCountDto>> getShippingStatusCoun
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "COMMON200",
description = "배송 중인 물품 정보 조회 결과",
content = @Content(schema = @Schema(implementation = ShipmentDetailsDto.class))
content = @Content(schema = @Schema(implementation = ShippingDetailsDto.class))
)
}
)
@GetMapping("/details")
public ResponseEntity<ApiResponse<List<ShipmentDetailsDto>>> getShipmentsDetails(@AuthenticationPrincipal Member member) {
return ResponseEntity.ok(ApiResponse.onSuccess(shippingService.getShipmentsDetails(member)));
public ResponseEntity<ApiResponse<List<ShippingDetailsDto>>> getShippingDetails(@AuthenticationPrincipal Member member) {
return ResponseEntity.ok(ApiResponse.onSuccess(shippingService.getShippingDetails(member)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Getter
@Setter
@Schema(description = "배송 중인 물품 조회에 대한 정보 DTO")
public class ShipmentDetailsDto {
public class ShippingDetailsDto {

@Schema(description = "배송 식별자 ID", example = "1")
private Long shippingId;
Expand All @@ -26,6 +26,12 @@ public class ShipmentDetailsDto {
@Schema(description = "배송 상태", example = "SHIPPING")
private ShippingStatus shippingStatus;

@Schema(description = "택배사", example = "우체국 택배")
private String shippingCompany;

@Schema(description = "송장 번호", example = "12356515")
private String trackingNumber;

@Schema(description = "최종 낙찰가", example = "50000")
private Long finalBidPrice;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Shipment {
public class Shipping {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.api.jaebichuri.shipping.mapper;

import com.api.jaebichuri.product.entity.AuctionProductImage;
import com.api.jaebichuri.shipping.dto.ShipmentDetailsDto;
import com.api.jaebichuri.shipping.entity.Shipment;
import com.api.jaebichuri.shipping.dto.ShippingDetailsDto;
import com.api.jaebichuri.shipping.entity.Shipping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
Expand All @@ -18,10 +18,10 @@ public interface ShippingMapper {
@Mapping(source = "auction.product.productDescription", target = "productDescription")
@Mapping(source = "auction.auctionCategory", target = "auctionCategory")
@Mapping(source = "auction.finalBidPrice", target = "finalBidPrice")
@Mapping(target = "imageUrl", expression = "java(getRepresentativeImageUrl(shipment.getAuction().getProduct().getImages()))")
ShipmentDetailsDto toShipmentDetailsDto(Shipment shipment);
@Mapping(target = "imageUrl", expression = "java(getRepresentativeImageUrl(shipping.getAuction().getProduct().getImages()))")
ShippingDetailsDto toShippingDetailsDto(Shipping shipping);

List<ShipmentDetailsDto> toShipmentDetailsDtoList(List<Shipment> shipments);
List<ShippingDetailsDto> toShippingDetailsDtoList(List<Shipping> shippings);

default String getRepresentativeImageUrl(List<AuctionProductImage> images) {
return images.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.api.jaebichuri.auction.entity.Auction;
import com.api.jaebichuri.member.entity.Member;
import com.api.jaebichuri.shipping.entity.Shipment;
import com.api.jaebichuri.shipping.entity.Shipping;
import com.api.jaebichuri.shipping.enums.ShippingStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -11,12 +11,12 @@
import java.util.Optional;

@Repository
public interface ShippingRepository extends JpaRepository<Shipment, Long> {
public interface ShippingRepository extends JpaRepository<Shipping, Long> {

Optional<Shipment> findByAuction(Auction auction);
Optional<Shipping> findByAuction(Auction auction);

int countByShippingStatusAndAuction_Seller(ShippingStatus shippingStatus, Member member);

List<Shipment> findByAuction_Seller(Member member);
List<Shipping> findByAuction_Seller(Member member);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.api.jaebichuri.shipping.service;

import com.api.jaebichuri.member.entity.Member;
import com.api.jaebichuri.shipping.dto.ShipmentDetailsDto;
import com.api.jaebichuri.shipping.dto.ShippingDetailsDto;
import com.api.jaebichuri.shipping.dto.ShippingStatusCountDto;
import com.api.jaebichuri.shipping.entity.Shipment;
import com.api.jaebichuri.shipping.entity.Shipping;
import com.api.jaebichuri.shipping.enums.ShippingStatus;
import com.api.jaebichuri.shipping.mapper.ShippingMapper;
import com.api.jaebichuri.shipping.repository.ShippingRepository;
Expand Down Expand Up @@ -31,10 +31,10 @@ public ShippingStatusCountDto getShippingStatusCount(Member member) {
}

@Transactional(readOnly = true)
public List<ShipmentDetailsDto> getShipmentsDetails(Member member) {
List<Shipment> shipments = shippingRepository.findByAuction_Seller(member);
public List<ShippingDetailsDto> getShippingDetails(Member member) {
List<Shipping> shipping = shippingRepository.findByAuction_Seller(member);

return shippingMapper.toShipmentDetailsDtoList(shipments);
return shippingMapper.toShippingDetailsDtoList(shipping);
}

}

0 comments on commit 0ebfed2

Please sign in to comment.