consolidate shared constants
This commit is contained in:
@@ -7,6 +7,7 @@ import com.petshop.backend.entity.*;
|
|||||||
import com.petshop.backend.exception.BusinessException;
|
import com.petshop.backend.exception.BusinessException;
|
||||||
import com.petshop.backend.exception.ResourceNotFoundException;
|
import com.petshop.backend.exception.ResourceNotFoundException;
|
||||||
import com.petshop.backend.repository.*;
|
import com.petshop.backend.repository.*;
|
||||||
|
import com.petshop.backend.util.BusinessConstants;
|
||||||
import com.stripe.Stripe;
|
import com.stripe.Stripe;
|
||||||
import com.stripe.exception.StripeException;
|
import com.stripe.exception.StripeException;
|
||||||
import com.stripe.model.PaymentIntent;
|
import com.stripe.model.PaymentIntent;
|
||||||
@@ -24,7 +25,7 @@ import java.util.List;
|
|||||||
@Service
|
@Service
|
||||||
public class CartService {
|
public class CartService {
|
||||||
|
|
||||||
private static final int LOYALTY_POINTS_PER_DOLLAR = 20;
|
private static final int LOYALTY_POINTS_PER_DOLLAR = BusinessConstants.LOYALTY_POINTS_PER_DOLLAR;
|
||||||
|
|
||||||
private final CartRepository cartRepository;
|
private final CartRepository cartRepository;
|
||||||
private final CartItemRepository cartItemRepository;
|
private final CartItemRepository cartItemRepository;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.petshop.backend.service;
|
package com.petshop.backend.service;
|
||||||
|
|
||||||
import com.petshop.backend.dto.common.BulkDeleteRequest;
|
import com.petshop.backend.dto.common.BulkDeleteRequest;
|
||||||
|
import com.petshop.backend.util.ImageValidationUtil;
|
||||||
import com.petshop.backend.util.StringUtils;
|
import com.petshop.backend.util.StringUtils;
|
||||||
import com.petshop.backend.dto.pet.MyPetRequest;
|
import com.petshop.backend.dto.pet.MyPetRequest;
|
||||||
import com.petshop.backend.dto.pet.MyPetResponse;
|
import com.petshop.backend.dto.pet.MyPetResponse;
|
||||||
@@ -31,7 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PetService {
|
public class PetService {
|
||||||
@@ -284,17 +285,7 @@ public class PetService {
|
|||||||
if (file == null || file.isEmpty()) {
|
if (file == null || file.isEmpty()) {
|
||||||
throw new BusinessException("Please select an image to upload");
|
throw new BusinessException("Please select an image to upload");
|
||||||
}
|
}
|
||||||
if (file.getSize() > 5 * 1024 * 1024) {
|
ImageValidationUtil.validate(file);
|
||||||
throw new BusinessException("Image file size must be less than 5MB");
|
|
||||||
}
|
|
||||||
String contentType = file.getContentType();
|
|
||||||
if (contentType == null) {
|
|
||||||
throw new BusinessException("Only JPG, PNG, and GIF images are allowed");
|
|
||||||
}
|
|
||||||
String normalized = contentType.toLowerCase(Locale.ROOT);
|
|
||||||
if (!normalized.equals("image/jpeg") && !normalized.equals("image/png") && !normalized.equals("image/gif")) {
|
|
||||||
throw new BusinessException("Only JPG, PNG, and GIF images are allowed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pet findOwnedPet(Long ownerUserId, Long petId) {
|
private Pet findOwnedPet(Long ownerUserId, Long petId) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.petshop.backend.service;
|
package com.petshop.backend.service;
|
||||||
|
|
||||||
import com.petshop.backend.dto.common.BulkDeleteRequest;
|
import com.petshop.backend.dto.common.BulkDeleteRequest;
|
||||||
|
import com.petshop.backend.util.ImageValidationUtil;
|
||||||
import com.petshop.backend.util.StringUtils;
|
import com.petshop.backend.util.StringUtils;
|
||||||
import com.petshop.backend.dto.product.ProductRequest;
|
import com.petshop.backend.dto.product.ProductRequest;
|
||||||
import com.petshop.backend.dto.product.ProductResponse;
|
import com.petshop.backend.dto.product.ProductResponse;
|
||||||
@@ -21,7 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ProductService {
|
public class ProductService {
|
||||||
@@ -138,17 +139,7 @@ public class ProductService {
|
|||||||
if (file == null || file.isEmpty()) {
|
if (file == null || file.isEmpty()) {
|
||||||
throw new BusinessException("Please select an image to upload");
|
throw new BusinessException("Please select an image to upload");
|
||||||
}
|
}
|
||||||
if (file.getSize() > 5 * 1024 * 1024) {
|
ImageValidationUtil.validate(file);
|
||||||
throw new BusinessException("Image file size must be less than 5MB");
|
|
||||||
}
|
|
||||||
String contentType = file.getContentType();
|
|
||||||
if (contentType == null) {
|
|
||||||
throw new BusinessException("Only JPG, PNG, and GIF images are allowed");
|
|
||||||
}
|
|
||||||
String normalized = contentType.toLowerCase(Locale.ROOT);
|
|
||||||
if (!normalized.equals("image/jpeg") && !normalized.equals("image/png") && !normalized.equals("image/gif")) {
|
|
||||||
throw new BusinessException("Only JPG, PNG, and GIF images are allowed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteStoredImageIfPresent(String storedImagePath) {
|
private void deleteStoredImageIfPresent(String storedImagePath) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.petshop.backend.exception.ResourceNotFoundException;
|
|||||||
import com.petshop.backend.event.SaleReceiptEvent;
|
import com.petshop.backend.event.SaleReceiptEvent;
|
||||||
import com.petshop.backend.repository.*;
|
import com.petshop.backend.repository.*;
|
||||||
import com.petshop.backend.util.AuthenticationHelper;
|
import com.petshop.backend.util.AuthenticationHelper;
|
||||||
|
import com.petshop.backend.util.BusinessConstants;
|
||||||
import com.petshop.backend.util.StringUtils;
|
import com.petshop.backend.util.StringUtils;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -24,8 +25,8 @@ import java.util.List;
|
|||||||
@Service
|
@Service
|
||||||
public class SaleService {
|
public class SaleService {
|
||||||
|
|
||||||
private static final BigDecimal EMPLOYEE_DISCOUNT_PERCENT = new BigDecimal("0.10");
|
private static final BigDecimal EMPLOYEE_DISCOUNT_PERCENT = BusinessConstants.EMPLOYEE_DISCOUNT_PERCENT;
|
||||||
private static final int LOYALTY_POINTS_PER_DOLLAR = 20;
|
private static final int LOYALTY_POINTS_PER_DOLLAR = BusinessConstants.LOYALTY_POINTS_PER_DOLLAR;
|
||||||
|
|
||||||
private final SaleRepository saleRepository;
|
private final SaleRepository saleRepository;
|
||||||
private final ProductRepository productRepository;
|
private final ProductRepository productRepository;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.petshop.backend.util;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public final class BusinessConstants {
|
||||||
|
|
||||||
|
private BusinessConstants() {}
|
||||||
|
|
||||||
|
public static final int LOYALTY_POINTS_PER_DOLLAR = 20;
|
||||||
|
public static final BigDecimal EMPLOYEE_DISCOUNT_PERCENT = new BigDecimal("0.10");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user