Skip to content

Commit c77c874

Browse files
authored
Merge pull request #33 from 9oormthon-univ/develop
2차 배포
2 parents 26e961f + 4fab8be commit c77c874

19 files changed

+324
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
package com.univ.sohwakhaeng.auth.api.dto;
22

3+
import io.swagger.v3.oas.annotations.media.Schema;
34
import lombok.Builder;
45

56
@Builder
6-
public record TokenDto(String grantType, String accessToken) {}
7+
@Schema(description = "토큰 DTO")
8+
public record TokenDto(
9+
10+
@Schema(description = "토큰의 인증 타입", example = "Bearer")
11+
String grantType,
12+
13+
@Schema(description = "인증을 위한 액세스 토큰", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
14+
String accessToken
15+
) {}

src/main/java/com/univ/sohwakhaeng/cart/api/dto/CartRequestDto.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.univ.sohwakhaeng.item.api.dto.ItemRequestDto;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
57
import java.util.List;
68

9+
@Schema(description = "장바구니 요청 DTO")
710
public record CartRequestDto(
11+
12+
@Schema(description = "기업의 ID", example = "1")
813
@JsonProperty("enterpriseId")
914
Long enterpriseId,
1015

16+
@Schema(description = "장바구니에 담긴 상품 목록", example = """
17+
[
18+
{
19+
"productId": 1,
20+
"quantity": 3
21+
},
22+
{
23+
"productId": 2,
24+
"quantity": 2
25+
}
26+
]
27+
""")
1128
@JsonProperty("items")
1229
List<ItemRequestDto> products
1330
) {
14-
1531
}
16-

src/main/java/com/univ/sohwakhaeng/cart/api/dto/CartResponseDto.java

+40-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,56 @@
44
import com.univ.sohwakhaeng.cart.Cart;
55
import com.univ.sohwakhaeng.enterprise.api.dto.EnterpriseOverviewDto;
66
import com.univ.sohwakhaeng.item.api.dto.ItemRequestDto;
7+
import com.univ.sohwakhaeng.item.api.dto.ItemResponseDto;
8+
import com.univ.sohwakhaeng.product.Product;
79
import java.util.List;
10+
import java.util.function.Function;
811

12+
import io.swagger.v3.oas.annotations.media.Schema;
13+
14+
@Schema(description = "장바구니 응답 DTO")
915
public record CartResponseDto(
16+
17+
@Schema(description = "기업 개요 정보", example = """
18+
{
19+
"enterprise_id": 1,
20+
"enterprise_image_url": "https://example.com/enterprise-image.jpg",
21+
"enterprise_name": "초록믿음강진",
22+
"category": "AGRICULTURAL_PRODUCTS"
23+
}
24+
""")
1025
@JsonProperty("enterprise")
1126
EnterpriseOverviewDto enterpriseOverviewDto,
1227

28+
@Schema(description = "장바구니에 담긴 상품 목록", example = """
29+
[
30+
{
31+
"product_id": 1,
32+
"product_name": "유기농 쌀",
33+
"unit": "1kg",
34+
"imageUrl": "https://example.com/product-image.jpg",
35+
"quantity": 3
36+
},
37+
{
38+
"product_id": 2,
39+
"product_name": "감자",
40+
"unit": "1kg",
41+
"imageUrl": "https://example.com/product-image2.jpg",
42+
"quantity": 2
43+
}
44+
]
45+
""")
1346
@JsonProperty("items")
14-
List<ItemRequestDto> itemRequestDtoList
47+
List<ItemResponseDto> itemRequestDtoList
1548
) {
16-
public static CartResponseDto fromEntity(Cart cart) {
49+
public static CartResponseDto fromEntity(Cart cart, String enterpriseImageUrl, Function<Product, String> getProductImageUrlFunction) {
1750
return new CartResponseDto(
18-
EnterpriseOverviewDto.fromEntity(cart.getEnterprise()),
51+
EnterpriseOverviewDto.fromEntity(cart.getEnterprise(), enterpriseImageUrl),
1952
cart.getItems().stream()
20-
.map(ItemRequestDto::fromEntity)
53+
.map(item -> {
54+
String productImageUrl = getProductImageUrlFunction.apply(item.getProduct());
55+
return ItemResponseDto.fromEntity(item, productImageUrl);
56+
})
2157
.toList()
2258
);
2359
}

src/main/java/com/univ/sohwakhaeng/cart/service/CartService.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
import com.univ.sohwakhaeng.item.Item;
1111
import com.univ.sohwakhaeng.item.api.dto.ItemRequestDto;
1212
import com.univ.sohwakhaeng.item.service.ItemService;
13+
import com.univ.sohwakhaeng.product.Product;
14+
import com.univ.sohwakhaeng.product.service.ProductService;
1315
import com.univ.sohwakhaeng.user.User;
1416
import java.util.List;
17+
import java.util.function.Function;
1518
import java.util.stream.Collectors;
1619
import lombok.RequiredArgsConstructor;
1720
import org.springframework.stereotype.Service;
@@ -24,6 +27,7 @@ public class CartService {
2427
private final CartRepository cartRepository;
2528
private final EnterpriseService enterpriseService;
2629
private final ItemService itemService;
30+
private final ProductService productService;
2731

2832
@Transactional
2933
public Long saveCart(CartRequestDto requestDto, User user) throws EnterpriseNotFoundException {
@@ -40,7 +44,11 @@ public Long saveCart(CartRequestDto requestDto, User user) throws EnterpriseNotF
4044
public List<CartResponseDto> getMyCarts(User user) {
4145
List<Cart> carts = getAllCartByUserId(user.getId());
4246
return carts.stream()
43-
.map(CartResponseDto::fromEntity)
47+
.map(cart -> {
48+
String enterpriseImageUrl = enterpriseService.getEnterpriseImageUrl(cart.getEnterprise().getName());
49+
Function<Product, String> getProductImageUrlFunction = product -> productService.getProductImageUrl(product.getName());
50+
return CartResponseDto.fromEntity(cart, enterpriseImageUrl, getProductImageUrlFunction);
51+
})
4452
.collect(Collectors.toList());
4553
}
4654

src/main/java/com/univ/sohwakhaeng/contract/api/dto/ContractDetailDto.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,52 @@
55

66
import java.util.List;
77

8+
import io.swagger.v3.oas.annotations.media.Schema;
9+
10+
@Schema(description = "계약 상세 정보 DTO")
811
@Builder
912
public record ContractDetailDto(
13+
14+
@Schema(description = "기업 ID", example = "1")
1015
@JsonProperty
1116
long enterpriseId,
17+
18+
@Schema(description = "기업 프로필 이미지 URL", example = "https://example.com/profile-image.jpg")
1219
@JsonProperty
1320
String profileImgUrl,
21+
22+
@Schema(description = "기업 이름", example = "초록믿음강진")
1423
@JsonProperty
1524
String enterpriseName,
25+
26+
@Schema(description = "기업 카테고리", example = "AGRICULTURAL_PRODUCTS")
1627
@JsonProperty
1728
String category,
29+
30+
@Schema(description = "정기 배송 정보", example = "주간 배송 가능")
1831
@JsonProperty
19-
String reqularDelivery,
32+
String regularDelivery,
33+
34+
@Schema(description = "계약 요청 기간", example = "3개월")
2035
@JsonProperty
2136
String requestTerm,
37+
38+
@Schema(description = "계약 제품 목록", example = """
39+
[
40+
{
41+
"productId": 1,
42+
"productName": "유기농 쌀",
43+
"unit": "1kg",
44+
"price": 5000
45+
},
46+
{
47+
"productId": 2,
48+
"productName": "감자",
49+
"unit": "2kg",
50+
"price": 4000
51+
}
52+
]
53+
""")
2254
@JsonProperty
2355
List<ContractProducsResDto> products
2456
) {

src/main/java/com/univ/sohwakhaeng/contract/api/dto/ContractProducsResDto.java

+6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import lombok.Builder;
5+
import io.swagger.v3.oas.annotations.media.Schema;
56

67
@Builder
8+
@Schema(description = "계약 상품 응답 DTO")
79
public record ContractProducsResDto(
10+
11+
@Schema(description = "상품 이름", example = "유기농 쌀")
812
@JsonProperty
913
String name,
14+
15+
@Schema(description = "상품 수량", example = "10")
1016
@JsonProperty
1117
int quantity
1218
) {

src/main/java/com/univ/sohwakhaeng/contract/api/dto/ContractReqDto.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,47 @@
22

33
import java.util.List;
44

5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
7+
@Schema(description = "계약 요청 DTO")
58
public record ContractReqDto(
9+
10+
@Schema(description = "계약할 기업의 ID", example = "1")
611
long enterpriseId,
12+
13+
@Schema(description = "주당 배송 빈도", example = "2")
714
int deliveryWeek,
15+
16+
@Schema(description = "선호하는 배송 요일", example = "Monday")
817
String deliveryDay,
18+
19+
@Schema(description = "배송 수령 방법", example = "Home Delivery")
920
String takeMethod,
21+
22+
@Schema(description = "계약 요청 기간", example = "6개월")
1023
String requestedTerm,
24+
25+
@Schema(description = "계약 총 가격", example = "150000")
1126
long totalPrice,
27+
28+
@Schema(description = "계약에 포함된 제품 목록", example = """
29+
[
30+
{
31+
"productId": 1,
32+
"productName": "유기농 쌀",
33+
"unit": "1kg",
34+
"price": 5000,
35+
"quantity": 10
36+
},
37+
{
38+
"productId": 2,
39+
"productName": "감자",
40+
"unit": "2kg",
41+
"price": 4000,
42+
"quantity": 5
43+
}
44+
]
45+
""")
1246
List<ProductDto> products
1347
) {
14-
}
48+
}

src/main/java/com/univ/sohwakhaeng/contract/api/dto/ContractsInfoDto.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,30 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import lombok.Builder;
55

6+
import io.swagger.v3.oas.annotations.media.Schema;
7+
8+
@Schema(description = "계약 정보 DTO")
69
@Builder
710
public record ContractsInfoDto(
11+
12+
@Schema(description = "계약과 연관된 기업 ID", example = "1")
813
@JsonProperty
914
long enterpriseId,
15+
16+
@Schema(description = "계약 ID", example = "101")
1017
@JsonProperty
1118
long contractId,
19+
20+
@Schema(description = "기업 프로필 이미지 URL", example = "https://example.com/profile-image.jpg")
1221
@JsonProperty
1322
String profileImage,
23+
24+
@Schema(description = "기업 이름", example = "초록믿음강진")
1425
@JsonProperty
1526
String enterpriseName,
27+
28+
@Schema(description = "기업 카테고리", example = "AGRICULTURAL_PRODUCTS")
1629
@JsonProperty
1730
String category
1831
) {
19-
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package com.univ.sohwakhaeng.contract.api.dto;
22

3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
5+
@Schema(description = "제품 DTO")
36
public record ProductDto(
7+
8+
@Schema(description = "제품의 ID", example = "1")
49
long productId,
10+
11+
@Schema(description = "제품 이름", example = "유기농 쌀")
512
String productName,
13+
14+
@Schema(description = "제품 수량", example = "10")
615
int quantity
7-
) {}
16+
) {}

src/main/java/com/univ/sohwakhaeng/contract/service/ContractService.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.univ.sohwakhaeng.contract.domain.repository.ContractRepository;
1313
import com.univ.sohwakhaeng.enterprise.Enterprise;
1414
import com.univ.sohwakhaeng.enterprise.repository.EnterpriseRepository;
15+
import com.univ.sohwakhaeng.enterprise.service.EnterpriseService;
1516
import com.univ.sohwakhaeng.global.common.dto.PagedResponseDto;
1617
import com.univ.sohwakhaeng.product.Product;
1718
import com.univ.sohwakhaeng.product.repository.ProductRepository;
@@ -26,6 +27,7 @@
2627
@RequiredArgsConstructor
2728
public class ContractService {
2829

30+
private final EnterpriseService enterpriseService;
2931
private final ContractRepository contractRepository;
3032
private final ContractProductsRepository contractProductsRepository;
3133
private final EnterpriseRepository enterpriseRepository;
@@ -79,12 +81,14 @@ private Page<Contract> getPagedContractsByUser(Pageable pageable, User user) {
7981
}
8082

8183
private ContractsInfoDto convertToDtoFromContract(Contract contract) {
84+
String enterpriseImageUrl = enterpriseService.getEnterpriseImageUrl(contract.getEnterprise().getName());
85+
8286
return ContractsInfoDto.builder()
8387
.contractId(contract.getId())
8488
.enterpriseId(contract.getEnterprise().getId())
8589
.enterpriseName(contract.getEnterprise().getName())
8690
.category(contract.getEnterprise().getCategory().toString())
87-
.profileImage(contract.getEnterprise().getImageUrl())
91+
.profileImage(enterpriseImageUrl)
8892
.build();
8993
}
9094

@@ -93,11 +97,13 @@ private ContractsInfoDto convertToDtoFromContract(Contract contract) {
9397
public ContractDetailDto getContractDetail(long contractId) {
9498
Contract contract = contractRepository.findById(contractId)
9599
.orElseThrow(() -> new IllegalArgumentException("해당 계약이 존재하지 않습니다."));
100+
101+
String enterpriseImageUrl = enterpriseService.getEnterpriseImageUrl(contract.getEnterprise().getName());
96102
return ContractDetailDto.builder()
97103
.enterpriseId(contract.getEnterprise().getId())
98104
.requestTerm(contract.getRequestedTerm())
99-
.reqularDelivery(contract.getDeliveryWeek() + " " + contract.getDeliveryDay())
100-
.profileImgUrl(contract.getEnterprise().getImageUrl())
105+
.regularDelivery(contract.getDeliveryWeek() + " " + contract.getDeliveryDay())
106+
.profileImgUrl(enterpriseImageUrl)
101107
.enterpriseName(contract.getEnterprise().getName())
102108
.products(contract.getContractProducts().stream().map(this::convertToDtoFromContractProducts).toList())
103109
.category(contract.getEnterprise().getCategory().toString())

src/main/java/com/univ/sohwakhaeng/enterprise/Enterprise.java

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public class Enterprise {
2727
@Column(name = "enterprise_id")
2828
private Long id;
2929

30-
@Column(name = "enterprise_imageUrl")
31-
private String imageUrl;
32-
3330
@Column(name = "enterprise_name")
3431
private String name;
3532

0 commit comments

Comments
 (0)