Skip to content

Commit

Permalink
Merge pull request #128 from Orange-Co/feature/item
Browse files Browse the repository at this point in the history
Feature/item
  • Loading branch information
Kang1221 authored Nov 5, 2024
2 parents 3fac9a6 + 45dbc7a commit e24a77c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion DDANZI_Server_yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.orange.ddanzi.dto.payment;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,6 +11,8 @@
@NoArgsConstructor
@AllArgsConstructor
public class PortOneTokenRequestDto {
@JsonProperty("imp_key")
private String imp_key;
@JsonProperty("imp_secret")
private String imp_secret;
}
16 changes: 14 additions & 2 deletions src/main/java/co/orange/ddanzi/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;


@Slf4j
Expand All @@ -54,6 +56,7 @@ public class ItemService {
private final GcsService gcsService;
private final TermService termService;
private final AddressService addressService;
private final ProductService productService;
private final PaymentService paymentService;
private final PaymentRepository paymentRepository;
private final HistoryService historyService;
Expand Down Expand Up @@ -87,8 +90,12 @@ public ApiResponse<?> saveItem(SaveItemRequestDto requestDto){

product.updateStock(product.getStock() + 1);
log.info("상품의 재고 수량 업데이트 -> {}개", product.getStock());
if(product.getClosestDueDate()==null || dueDate.isBefore(product.getClosestDueDate()))

if(product.getClosestDueDate()==null || dueDate.isBefore(product.getClosestDueDate())) {
product.updateClosestDueDate(dueDate);
log.info("가장 가까운 마감일을 수정 -> {}", dueDate);

}

SaveItemResponseDto responseDto = SaveItemResponseDto.builder()
.itemId(newItem.getId())
Expand Down Expand Up @@ -167,9 +174,14 @@ public ApiResponse<?> deleteItem(String itemId){
}
log.info("제품을 삭제합니다.");
item.updateStatus(ItemStatus.DELETED);
log.info("재고를 감소시킵니다.");

Product product = item.getProduct();
product.updateStock(product.getStock() - 1);
log.info("재고를 감소시킴 -> {}개", product.getClosestDueDate());

productService.updateClosestDueDate(product);

log.info("가장 가까운 마감일을 수정합 -> {}", product.getClosestDueDate());

return ApiResponse.onSuccess(Success.DELETE_ITEM_SUCCESS, true);
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/co/orange/ddanzi/service/MyPageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public class MyPageService {
private final HomeService homeService;
private final InterestProductRepository interestProductRepository;

@Autowired
OrderService orderService;
@Autowired
ItemService itemService;
private final OrderService orderService;
private final ItemService itemService;

@Transactional
public ApiResponse<?> getMyPage(){
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/co/orange/ddanzi/service/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class PaymentService {
private final OrderService orderService;
private final HistoryService historyService;
private final FcmService fcmService;
private final ProductService productService;

@Value("${ddanzi.portone.access-key}")
private String accessKey;
Expand Down Expand Up @@ -132,6 +133,8 @@ else if(payment.getPayStatus().equals(PayStatus.PAID)){
log.info("Payment is paid!!");
item.updateStatus(ItemStatus.CLOSED);
product.updateStock(product.getStock() - 1);
productService.updateClosestDueDate(product);
log.info("가장 가까운 마감일을 수정합 -> {}", product.getClosestDueDate());
fcmService.sendMessageToAdmins("⚠️관리자 알림: 구매실행", "결제가 실행되었습니다. orderId:" + order.getId());
}

Expand Down Expand Up @@ -173,20 +176,14 @@ public String getPortOneAccessToken(){
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");

Map<String, String> requestBody = new HashMap<>();
requestBody.put("imp_key", accessKey);
requestBody.put("imp_secret", accessSecret);

HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
PortOneTokenRequestDto requestDto = PortOneTokenRequestDto.builder()
.imp_key(accessKey)
.imp_secret(accessSecret)
.build();

try {
log.info("Request Body: {}", new ObjectMapper().writeValueAsString(requestBody));
} catch (JsonProcessingException e) {
log.error("JSON 직렬화 오류: {}", e.getMessage());
}
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<PortOneTokenResponseDto> response = restTemplate.postForEntity(url, entity, PortOneTokenResponseDto.class);
ResponseEntity<PortOneTokenResponseDto> response = restTemplate.postForEntity(url, new HttpEntity<>(requestDto, headers), PortOneTokenResponseDto.class);
log.info("포트원 Access key Get 성공");
return response.getBody().getResponse().getAccess_token();
} catch (HttpClientErrorException e) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/co/orange/ddanzi/service/ProductService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package co.orange.ddanzi.service;

import co.orange.ddanzi.common.error.Error;
import co.orange.ddanzi.common.exception.DiscountNotFoundException;
import co.orange.ddanzi.common.exception.ProductNotFoundException;
import co.orange.ddanzi.domain.product.Discount;
import co.orange.ddanzi.domain.product.Item;
import co.orange.ddanzi.domain.product.Product;
import co.orange.ddanzi.domain.user.Account;
import co.orange.ddanzi.domain.user.Address;
import co.orange.ddanzi.domain.user.User;
import co.orange.ddanzi.common.response.ApiResponse;
import co.orange.ddanzi.common.response.Success;
Expand All @@ -25,6 +24,7 @@
import org.springframework.web.client.RestTemplate;

import java.util.Map;
import java.util.Optional;


@Slf4j
Expand All @@ -33,6 +33,7 @@
public class ProductService {
private final AuthUtils authUtils;
private final ProductRepository productRepository;
private final ItemRepository itemRepository;
private final DiscountRepository discountRepository;
private final AccountRepository accountRepository;

Expand Down Expand Up @@ -90,6 +91,13 @@ public String getMostSimilarProductId(ProductRequestDto requestDto){
}
}

public void updateClosestDueDate(Product product){
Optional<Item> item = itemRepository.findNearestExpiryItem(product);
if(item.isPresent())
product.updateClosestDueDate(item.get().getDueDate());
else
product.updateClosestDueDate(null);
}

/*
@Transactional
Expand Down

0 comments on commit e24a77c

Please sign in to comment.