Merge pull request #254 from RecentRunner/web-v1

Web v1
This commit was merged in pull request #254.
This commit is contained in:
2026-04-14 07:06:21 -06:00
committed by GitHub
19 changed files with 1432 additions and 113 deletions

View File

@@ -91,4 +91,13 @@ public class CartController {
return ResponseEntity.noContent().build();
}
@PostMapping("/checkout/cancel")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Void> cancelCheckout(@RequestParam Long storeId) {
Long userId = AuthenticationHelper.getAuthenticatedUserId();
cartService.cancelCheckout(userId, storeId);
return ResponseEntity.noContent().build();
}
}

View File

@@ -68,9 +68,10 @@ public class ChatController {
@GetMapping("/conversations")
@PreAuthorize("hasAnyRole('CUSTOMER', 'STAFF', 'ADMIN')")
public ResponseEntity<List<ConversationResponse>> getConversations() {
public ResponseEntity<List<ConversationResponse>> getConversations(
@RequestParam(required = false, defaultValue = "false") boolean mine) {
User user = getCurrentUser();
List<ConversationResponse> conversations = chatService.getConversations(user.getId(), user.getRole());
List<ConversationResponse> conversations = chatService.getConversations(user.getId(), user.getRole(), mine);
return ResponseEntity.ok(conversations);
}

View File

@@ -16,6 +16,7 @@ public class CartResponse {
private String couponCode;
private Boolean pointsApplied;
private Integer availableLoyaltyPoints;
private Boolean checkoutPending;
public CartResponse() {
}
@@ -53,4 +54,7 @@ public class CartResponse {
public Integer getAvailableLoyaltyPoints() { return availableLoyaltyPoints; }
public void setAvailableLoyaltyPoints(Integer availableLoyaltyPoints) { this.availableLoyaltyPoints = availableLoyaltyPoints; }
public Boolean getCheckoutPending() { return checkoutPending; }
public void setCheckoutPending(Boolean checkoutPending) { this.checkoutPending = checkoutPending; }
}

View File

@@ -482,15 +482,21 @@ public class CartService {
List<CartItemResponse> itemResponses = cartItemRepository
.findByCartCartId(cart.getCartId())
.stream()
.map(item -> new CartItemResponse(
item.getCartItemId(),
item.getProduct().getProdId(),
item.getProduct().getProdName(),
item.getProduct().getImageUrl(),
item.getUnitPrice(),
item.getQuantity(),
item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()))
))
.map(item -> {
String rawImageUrl = item.getProduct().getImageUrl();
String imageUrl = (rawImageUrl != null && !rawImageUrl.isBlank())
? "/api/v1/products/" + item.getProduct().getProdId() + "/image"
: null;
return new CartItemResponse(
item.getCartItemId(),
item.getProduct().getProdId(),
item.getProduct().getProdName(),
imageUrl,
item.getUnitPrice(),
item.getQuantity(),
item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()))
);
})
.toList();
CartResponse response = new CartResponse();
@@ -505,7 +511,23 @@ public class CartService {
response.setCouponCode(cart.getCoupon() != null ? cart.getCoupon().getCouponCode() : null);
response.setPointsApplied(cart.getPointsApplied());
response.setAvailableLoyaltyPoints(cart.getUser() != null ? cart.getUser().getLoyaltyPoints() : null);
response.setCheckoutPending(cart.getCheckoutPending());
return response;
}
@Transactional
public void cancelCheckout(Long userId, Long storeId) {
cartRepository.findActiveCartByUserAndStore(userId, storeId, "ACTIVE")
.ifPresent(cart -> {
if (!Boolean.TRUE.equals(cart.getCheckoutPending())) {
return;
}
cart.setCheckoutPending(false);
cart.setCheckoutAmount(null);
cart.setCheckoutStartedAt(null);
cart.setCheckoutPaymentIntentId(null);
cartRepository.save(cart);
});
}
}

View File

@@ -65,10 +65,10 @@ public class ChatService {
return ConversationResponse.fromEntity(conversation, request.getMessage(), userId);
}
public List<ConversationResponse> getConversations(Long userId, User.Role role) {
public List<ConversationResponse> getConversations(Long userId, User.Role role, boolean mine) {
List<Conversation> conversations;
if (role == User.Role.CUSTOMER) {
if (mine || role == User.Role.CUSTOMER) {
conversations = conversationRepository.findByCustomerId(userId);
} else if (role == User.Role.STAFF) {
List<Conversation> assignedToMe = conversationRepository.findByStaffId(userId);