fix compatibility regressions

This commit is contained in:
2026-04-17 18:52:00 -06:00
parent e2b9ae6e0c
commit f5430a1940
4 changed files with 19 additions and 15 deletions

View File

@@ -4,7 +4,6 @@ import com.petshop.backend.dto.ai.AiChatRequest;
import com.petshop.backend.dto.ai.AiChatResponse;
import com.petshop.backend.entity.Pet;
import com.petshop.backend.entity.User;
import com.petshop.backend.exception.BusinessException;
import com.petshop.backend.repository.PetRepository;
import com.petshop.backend.service.OpenRouterService;
import com.petshop.backend.util.AuthenticationHelper;
@@ -37,7 +36,7 @@ public class AiChatController {
@PreAuthorize("isAuthenticated()")
public ResponseEntity<AiChatResponse> sendMessage(@Valid @RequestBody AiChatRequest request) {
if (request.getMessage() == null || request.getMessage().isBlank()) {
throw new BusinessException("Message cannot be empty");
return ResponseEntity.badRequest().body(AiChatResponse.fail("Message cannot be empty"));
}
ContentFilter.validate(request.getMessage());

View File

@@ -279,22 +279,17 @@ public class AuthController {
}
@PostMapping("/me/avatar")
public ResponseEntity<AvatarUploadResponse> uploadAvatar(@RequestParam("avatar") MultipartFile file) {
public ResponseEntity<AvatarUploadResponse> uploadAvatar(@RequestParam("avatar") MultipartFile file) throws IOException {
User user = authHelper.getAuthenticatedUser();
ImageValidationUtil.validate(file);
try {
avatarStorageService.deleteAvatar(user);
String avatarPath = avatarStorageService.storeAvatar(file);
user.setAvatarUrl(avatarPath);
userRepository.save(user);
avatarStorageService.deleteAvatar(user);
String avatarPath = avatarStorageService.storeAvatar(file);
user.setAvatarUrl(avatarPath);
userRepository.save(user);
return ResponseEntity.ok(new AvatarUploadResponse(avatarStorageService.toOwnerAvatarUrl(user), "Avatar uploaded successfully"));
} catch (IOException e) {
throw new BusinessException("Failed to upload avatar: " + e.getMessage());
}
return ResponseEntity.ok(new AvatarUploadResponse(avatarStorageService.toOwnerAvatarUrl(user), "Avatar uploaded successfully"));
}
@GetMapping("/me/avatar")

View File

@@ -2,6 +2,7 @@ package com.petshop.backend.exception;
import com.petshop.backend.service.PetService;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.core.PropertyReferenceException;
import org.springframework.http.HttpStatus;
@@ -121,6 +122,11 @@ public class GlobalExceptionHandler {
return buildErrorResponse(HttpStatus.FORBIDDEN, "Access to this pet image is not allowed", ex, request);
}
@ExceptionHandler(IOException.class)
public ResponseEntity<ApiErrorResponse> handleIOException(IOException ex, HttpServletRequest request) {
return buildErrorResponse(HttpStatus.BAD_REQUEST, ex.getMessage(), ex, request);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiErrorResponse> handleGenericException(Exception ex, HttpServletRequest request) {
String message = ex.getMessage() == null || ex.getMessage().isBlank()

View File

@@ -139,11 +139,15 @@ public class CouponService {
}
public static boolean isPercentageType(String discountType) {
return "PERCENTAGE".equalsIgnoreCase(discountType) || "PERCENT".equalsIgnoreCase(discountType);
if (discountType == null) return false;
String type = discountType.trim();
return "PERCENTAGE".equalsIgnoreCase(type) || "PERCENT".equalsIgnoreCase(type);
}
public static boolean isFixedType(String discountType) {
return "FIXED".equalsIgnoreCase(discountType) || "FLAT".equalsIgnoreCase(discountType);
if (discountType == null) return false;
String type = discountType.trim();
return "FIXED".equalsIgnoreCase(type) || "FLAT".equalsIgnoreCase(type);
}
private CouponResponse mapToResponse(Coupon coupon) {