fix compatibility regressions
This commit is contained in:
@@ -4,7 +4,6 @@ import com.petshop.backend.dto.ai.AiChatRequest;
|
|||||||
import com.petshop.backend.dto.ai.AiChatResponse;
|
import com.petshop.backend.dto.ai.AiChatResponse;
|
||||||
import com.petshop.backend.entity.Pet;
|
import com.petshop.backend.entity.Pet;
|
||||||
import com.petshop.backend.entity.User;
|
import com.petshop.backend.entity.User;
|
||||||
import com.petshop.backend.exception.BusinessException;
|
|
||||||
import com.petshop.backend.repository.PetRepository;
|
import com.petshop.backend.repository.PetRepository;
|
||||||
import com.petshop.backend.service.OpenRouterService;
|
import com.petshop.backend.service.OpenRouterService;
|
||||||
import com.petshop.backend.util.AuthenticationHelper;
|
import com.petshop.backend.util.AuthenticationHelper;
|
||||||
@@ -37,7 +36,7 @@ public class AiChatController {
|
|||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
public ResponseEntity<AiChatResponse> sendMessage(@Valid @RequestBody AiChatRequest request) {
|
public ResponseEntity<AiChatResponse> sendMessage(@Valid @RequestBody AiChatRequest request) {
|
||||||
if (request.getMessage() == null || request.getMessage().isBlank()) {
|
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());
|
ContentFilter.validate(request.getMessage());
|
||||||
|
|
||||||
|
|||||||
@@ -279,22 +279,17 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/me/avatar")
|
@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();
|
User user = authHelper.getAuthenticatedUser();
|
||||||
|
|
||||||
ImageValidationUtil.validate(file);
|
ImageValidationUtil.validate(file);
|
||||||
|
|
||||||
try {
|
|
||||||
avatarStorageService.deleteAvatar(user);
|
avatarStorageService.deleteAvatar(user);
|
||||||
String avatarPath = avatarStorageService.storeAvatar(file);
|
String avatarPath = avatarStorageService.storeAvatar(file);
|
||||||
user.setAvatarUrl(avatarPath);
|
user.setAvatarUrl(avatarPath);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
|
|
||||||
return ResponseEntity.ok(new AvatarUploadResponse(avatarStorageService.toOwnerAvatarUrl(user), "Avatar uploaded successfully"));
|
return ResponseEntity.ok(new AvatarUploadResponse(avatarStorageService.toOwnerAvatarUrl(user), "Avatar uploaded successfully"));
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new BusinessException("Failed to upload avatar: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/me/avatar")
|
@GetMapping("/me/avatar")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.petshop.backend.exception;
|
|||||||
|
|
||||||
import com.petshop.backend.service.PetService;
|
import com.petshop.backend.service.PetService;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.IOException;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.data.core.PropertyReferenceException;
|
import org.springframework.data.core.PropertyReferenceException;
|
||||||
import org.springframework.http.HttpStatus;
|
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);
|
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)
|
@ExceptionHandler(Exception.class)
|
||||||
public ResponseEntity<ApiErrorResponse> handleGenericException(Exception ex, HttpServletRequest request) {
|
public ResponseEntity<ApiErrorResponse> handleGenericException(Exception ex, HttpServletRequest request) {
|
||||||
String message = ex.getMessage() == null || ex.getMessage().isBlank()
|
String message = ex.getMessage() == null || ex.getMessage().isBlank()
|
||||||
|
|||||||
@@ -139,11 +139,15 @@ public class CouponService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPercentageType(String discountType) {
|
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) {
|
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) {
|
private CouponResponse mapToResponse(Coupon coupon) {
|
||||||
|
|||||||
Reference in New Issue
Block a user