Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/restaurants")
@RequestMapping("/admin")
@Slf4j(topic = "RestaurantAdminController")
public class RestaurantAdminController {

private final RestaurantManageAdminService restaurantManageAdminService;
private final RestaurantAdminService restaurantAdminService;

// 음식점 상세 조회
@GetMapping("/{restaurantId}")
@GetMapping("/restaurants/{restaurantId}")
public ResponseEntity<RestaurantAdminResponseDto> getRestaurant(
@PathVariable UUID restaurantId) {
log.info("음식점 상세 조회");
Expand All @@ -43,7 +43,7 @@ public ResponseEntity<RestaurantAdminResponseDto> getRestaurant(
}

// 음식점 생성
@PostMapping
@PostMapping("/restaurants")
public ResponseEntity<RestaurantAdminResponseDto> addRestaurant(
@RequestBody RestaurantAdminCreateRequestDto restaurantAdminCreateRequestDto,
@AuthenticationPrincipal UserDetailsImpl userDetails) {
Expand All @@ -55,7 +55,7 @@ public ResponseEntity<RestaurantAdminResponseDto> addRestaurant(
}

// 음식점 정보 수정
@PutMapping("/{restaurantId}")
@PutMapping("/restaurants/{restaurantId}")
public ResponseEntity<RestaurantAdminResponseDto> updateRestaurant(
@RequestBody RestaurantAdminRequestDto restaurantAdminRequestDto,
@PathVariable UUID restaurantId,
Expand All @@ -68,7 +68,7 @@ public ResponseEntity<RestaurantAdminResponseDto> updateRestaurant(
}

// 음식점 삭제
@DeleteMapping("/{restaurantId}")
@DeleteMapping("/restaurants/{restaurantId}")
public ResponseEntity<?> deleteRestaurant(
@PathVariable UUID restaurantId,
@AuthenticationPrincipal UserDetailsImpl userDetails) {
Expand All @@ -78,7 +78,7 @@ public ResponseEntity<?> deleteRestaurant(
return ResponseEntity.status(HttpStatus.OK).body(null);
}

@GetMapping("/search")
@GetMapping("/restaurants/search")
public ResponseEntity<Page<RestaurantAdminResponseDto>> searchRestaurant(
@ModelAttribute RestaurantAdminSearchDto restaurantAdminSearchDto,
@PageableDefault(sort = "name", direction = Sort.Direction.ASC) Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
@RestController
@RequiredArgsConstructor
@Slf4j(topic = "UserAdminService")
@RequestMapping("/admin/users")
@RequestMapping("/admin")
public class UserAdminController {

private final UserAdminService userAdminService;

// 사용자 전체 조회 + 페이징 기능
@GetMapping("/search") // search?page=0&size=2로 요청하면 2개만 조회
@GetMapping("/users/search") // search?page=0&size=2로 요청하면 2개만 조회
public ResponseEntity<Page<UserAdminResponseDto>> searchUsers(
@ModelAttribute UserAdminSearchDto searchDto,
@PageableDefault(sort = "username", direction = Sort.Direction.ASC) Pageable pageable) {
Expand All @@ -40,7 +40,7 @@ public ResponseEntity<Page<UserAdminResponseDto>> searchUsers(
}

// 사용자 상세 조회
@GetMapping("/{userId}")
@GetMapping("/users/{userId}")
public ResponseEntity<UserAdminResponseDto> getUser(
@PathVariable String userId) {
log.info("getUser");
Expand All @@ -51,7 +51,7 @@ public ResponseEntity<UserAdminResponseDto> getUser(
}

// 사용자 등록
@PostMapping
@PostMapping("/users")
public ResponseEntity<UserAdminResponseDto> createUser(
@RequestBody UserCreateRequestDto userCreateRequestDto,
@AuthenticationPrincipal UserDetails userDetails) {
Expand All @@ -64,7 +64,7 @@ public ResponseEntity<UserAdminResponseDto> createUser(
}

// 사용자 수정
@PutMapping("/{userId}")
@PutMapping("/users/{userId}")
public ResponseEntity<UserAdminResponseDto> updateUser(
@PathVariable String userId,
@RequestBody UserUpdateRequestDto userUpdateRequestDto,
Expand All @@ -78,7 +78,7 @@ public ResponseEntity<UserAdminResponseDto> updateUser(
}

// 사용자 삭제
@DeleteMapping("/{userId}")
@DeleteMapping("/users/{userId}")
public ResponseEntity<String> deleteUser(
@PathVariable String userId,
@AuthenticationPrincipal UserDetails userDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/addresses")
@RequestMapping("/api")
@Slf4j(topic = "Address Controller")
public class AddressController {

private final AddressService addressService;

// 배송지 추가
@PostMapping
@PostMapping("/addresses")
public ResponseEntity<AddressResponseDto> createAddress(
@RequestBody AddressRequestDto requestDto,
@AuthenticationPrincipal UserDetailsImpl userDetails) {
Expand All @@ -45,7 +45,7 @@ public ResponseEntity<AddressResponseDto> createAddress(
}

// 배송지 조회
@GetMapping("/search")
@GetMapping("/addresses/search")
public ResponseEntity<Page<AddressResponseDto>> searchMyAddresses(
@ModelAttribute AddressSearchDto searchDto,
@AuthenticationPrincipal UserDetailsImpl userDetails,
Expand All @@ -60,7 +60,7 @@ public ResponseEntity<Page<AddressResponseDto>> searchMyAddresses(


// 개별 배송지 조회
@GetMapping("/{addressId}")
@GetMapping("/addresses/{addressId}")
public ResponseEntity<AddressResponseDto> getAddress(
@PathVariable UUID addressId,
@AuthenticationPrincipal UserDetailsImpl userDetails) {
Expand All @@ -72,7 +72,7 @@ public ResponseEntity<AddressResponseDto> getAddress(
}

// 배송지 수정
@PutMapping("/{addressId}")
@PutMapping("/addresses/{addressId}")
public ResponseEntity<AddressResponseDto> updateAddress(
@PathVariable UUID addressId,
@RequestBody AddressRequestDto requestDto,
Expand All @@ -86,7 +86,7 @@ public ResponseEntity<AddressResponseDto> updateAddress(
}

// 배송지 삭제
@DeleteMapping("/{addressId}")
@DeleteMapping("/addresses/{addressId}")
public ResponseEntity<String> deleteAddress(
@PathVariable UUID addressId,
@AuthenticationPrincipal UserDetailsImpl userDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,7 @@ public ResponseEntity<MenuResponseDto> addMenu(
MenuResponseDto responseDto = menuService.addMenu(restaurantId, requestDto, userDetails);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto);
}

// // restaurant_id 기반 모든 메뉴 조회
// @GetMapping("/menus/{restaurantId}")
// public ResponseEntity<Page<MenuResponseDto>> getRestaurantAllMenus(
// @PathVariable(name = "restaurantId") Restaurant restaurantId,
// @RequestParam(required = false) String name,
// @RequestParam(defaultValue = "createdAt") String sortBy,
// @RequestParam(defaultValue = "0") int page,
// @RequestParam(defaultValue = "10") int size
// ) {
// Page<MenuResponseDto> responseDtoPage = menuService.getAllMenus(restaurantId, name, sortBy,
// page, size);
// return ResponseEntity.status(HttpStatus.OK).body(responseDtoPage);
// }


// restaurant_id 기반 메뉴 검색 및 조회
@GetMapping("/menus/{restaurantId}/search")
public ResponseEntity<Page<MenuResponseDto>> searchMenus(
Expand Down Expand Up @@ -102,7 +88,7 @@ public ResponseEntity<MenuAiResponseDto> aiDescription(
@AuthenticationPrincipal UserDetailsImpl userDetails
) {
log.info("aiDescription");

MenuAiResponseDto responseDto = menuService.aiDescription(menuId, userDetails);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import java.util.UUID;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@Table(name = "p_order")
public class Order extends BaseEntity {
Expand Down Expand Up @@ -73,9 +71,13 @@ public Order(User customer, Restaurant restaurant, Address address,
this.request = request;
}

public void updateTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}

public void updateOrderStatus(User user, OrderStatusEnum status) {
super.update(user.getUsername()); // user -> username으로 변경 예정 (*baseEntity)
this.status = status;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.sparta.spring_deep._delivery.domain.order.orderDetails.OrderDetailsResponseDto;
import com.sparta.spring_deep._delivery.domain.order.orderItem.OrderItem;
import com.sparta.spring_deep._delivery.domain.order.orderItem.OrderItemRepository;
import com.sparta.spring_deep._delivery.domain.payment.Payment.PaymentStatusEnum;
import com.sparta.spring_deep._delivery.domain.payment.PaymentResponseDto;
import com.sparta.spring_deep._delivery.domain.payment.PaymentService;
import com.sparta.spring_deep._delivery.domain.restaurant.Restaurant;
import com.sparta.spring_deep._delivery.domain.restaurant.RestaurantRepository;
import com.sparta.spring_deep._delivery.domain.review.Review;
Expand Down Expand Up @@ -48,6 +51,7 @@ public class OrderService {
private final AddressRepository addressRepository;
private final MenuRepository menuRepository;
private final ReviewRepository reviewRepository;
private final PaymentService paymentService;
private LocalDateTime lastCheckedTime = LocalDateTime.now().minusMinutes(5);


Expand Down Expand Up @@ -90,8 +94,19 @@ public OrderDetailsResponseDto createOrder(OrderDetailsRequestDto requestDto, Us

orderItemList.add(orderItem);
});

order.setTotalPrice(sumPrice.get());
order.updateTotalPrice(sumPrice.get());

// 결제 요청
PaymentResponseDto paymentResponseDto = paymentService.createPayment(user.getUsername(),
order.getId(), sumPrice.get());

if (paymentResponseDto.getPaymentStatus() == PaymentStatusEnum.COMPLETED) {
order.updateOrderStatus(user, OrderStatusEnum.CONFIRMED);

} else if (paymentResponseDto.getPaymentStatus() == PaymentStatusEnum.FAILED) {
order.updateOrderStatus(user, OrderStatusEnum.FAILED);
order.delete(user.getUsername());
}

return new OrderDetailsResponseDto(order, orderItemList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum OrderStatusEnum {
PENDING,
CONFIRMED,
DELIVERED,
FAILED,
CANCELLED
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Digits;
import java.math.BigDecimal;
import java.util.UUID;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@Table(name = "p_payment")
public class Payment extends BaseEntity {

@Id
Expand All @@ -44,7 +44,7 @@ public class Payment extends BaseEntity {
private PaymentMethodEnum paymentMethod;

@Enumerated(EnumType.STRING)
@Column(name = "payment_status", nullable = false, columnDefinition = "p_payment_method_enum")
@Column(name = "status", nullable = false, columnDefinition = "p_payment_method_enum")
@JdbcTypeCode(SqlTypes.NAMED_ENUM)
private PaymentStatusEnum paymentStatus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,54 @@ public class PaymentController {

// 결제 생성
@PostMapping("/payment")
public ResponseEntity<Payment> createPayment(@RequestBody PaymentRequestDto requestDto
public ResponseEntity<PaymentResponseDto> createPayment(
@RequestBody PaymentRequestDto requestDto
, @AuthenticationPrincipal UserDetailsImpl userDetails) {
log.info("createPayment");

Payment payment = paymentService.createPayment(userDetails.getUsername(),
PaymentResponseDto responseDto = paymentService.createPayment(userDetails.getUsername(),
UUID.fromString(requestDto.orderId),
requestDto.amount);
return ResponseEntity.status(HttpStatus.OK).body(payment);
return ResponseEntity.status(HttpStatus.OK).body(responseDto);
}

// 결제 완료 처리
@PutMapping("/payment/complete")
public ResponseEntity<Payment> completePayment(@RequestParam String paymentId) {
public ResponseEntity<PaymentResponseDto> completePayment(@RequestParam String paymentId) {
log.info("completePayment");

Payment payment = paymentService.completePayment(UUID.fromString(paymentId));
return ResponseEntity.status(HttpStatus.OK).body(payment);
PaymentResponseDto responseDto = paymentService.completePayment(UUID.fromString(paymentId));
return ResponseEntity.status(HttpStatus.OK).body(responseDto);
}

// 결제 취소 처리
@PutMapping("/payment/cancel")
public ResponseEntity<Payment> cancelPayment(@RequestParam String paymentId) {
public ResponseEntity<PaymentResponseDto> cancelPayment(@RequestParam String paymentId) {
log.info("cancelPayment");

Payment payment = paymentService.cancelPayment(UUID.fromString(paymentId));
return ResponseEntity.status(HttpStatus.OK).body(payment);
PaymentResponseDto responseDto = paymentService.cancelPayment(UUID.fromString(paymentId));
return ResponseEntity.status(HttpStatus.OK).body(responseDto);
}

// 결제 실패 처리
@PutMapping("/payment/fail")
public ResponseEntity<Payment> failPayment(@RequestParam String paymentId) {
public ResponseEntity<PaymentResponseDto> failPayment(@RequestParam String paymentId) {
log.info("failPayment");

Payment payment = paymentService.failPayment(UUID.fromString(paymentId));
return ResponseEntity.status(HttpStatus.OK).body(payment);
PaymentResponseDto responseDto = paymentService.failPayment(UUID.fromString(paymentId));
return ResponseEntity.status(HttpStatus.OK).body(responseDto);
}

// 결제 조회
@GetMapping("/payment")
public ResponseEntity<Payment> getPayment(@AuthenticationPrincipal UserDetailsImpl userDetails,
public ResponseEntity<PaymentResponseDto> getPayment(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam String paymentId) {
log.info("getPayment");

Payment payment = paymentService.getPayment(userDetails.getUser(),
PaymentResponseDto responseDto = paymentService.getPayment(userDetails.getUser(),
UUID.fromString(paymentId));
return ResponseEntity.status(HttpStatus.OK).body(payment);
return ResponseEntity.status(HttpStatus.OK).body(responseDto);
}

// 결제 내역 삭제
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.sparta.spring_deep._delivery.domain.payment;

import com.sparta.spring_deep._delivery.domain.payment.Payment.PaymentMethodEnum;
import com.sparta.spring_deep._delivery.domain.payment.Payment.PaymentStatusEnum;
import java.math.BigDecimal;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class PaymentResponseDto {

private UUID id;
private UUID orderId;
private BigDecimal amount;
private PaymentMethodEnum paymentMethod;
private PaymentStatusEnum paymentStatus;

public PaymentResponseDto(Payment payment) {
this.id = payment.getId();
this.orderId = payment.getOrder().getId();
this.amount = payment.getAmount();
this.paymentMethod = payment.getPaymentMethod();
this.paymentStatus = payment.getPaymentStatus();
}

}
Loading