fix lazy loading on me, services, refunds

This commit is contained in:
2026-04-06 20:56:14 -06:00
parent f646c18035
commit 386deff6b8
4 changed files with 7 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ import org.springframework.security.authentication.InternalAuthenticationService
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -130,6 +131,7 @@ public class AuthController {
}
}
@Transactional(readOnly = true)
@GetMapping("/me")
public ResponseEntity<UserInfoResponse> getCurrentUser() {
User user = getAuthenticatedUser();

View File

@@ -30,7 +30,7 @@ public class Service {
@Column(nullable = false)
private Integer serviceDuration;
@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "service_species", joinColumns = @JoinColumn(name = "serviceId"))
@Column(name = "species", length = 50)
private Set<String> species = new HashSet<>();

View File

@@ -81,6 +81,7 @@ public class RefundService {
return toResponse(savedRefund);
}
@Transactional(readOnly = true)
public RefundResponse getRefundById(Long id, Long customerId) {
Refund refund = refundRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Refund not found"));
@@ -92,6 +93,7 @@ public class RefundService {
return toResponse(refund);
}
@Transactional(readOnly = true)
public List<RefundResponse> getAllRefunds(Long customerId) {
List<Refund> refunds;

View File

@@ -19,6 +19,7 @@ public class ServiceService {
this.serviceRepository = serviceRepository;
}
@Transactional(readOnly = true)
public Page<ServiceResponse> getAllServices(String query, Pageable pageable) {
Page<com.petshop.backend.entity.Service> services;
if (query != null && !query.trim().isEmpty()) {
@@ -29,6 +30,7 @@ public class ServiceService {
return services.map(this::mapToResponse);
}
@Transactional(readOnly = true)
public ServiceResponse getServiceById(Long id) {
com.petshop.backend.entity.Service service = serviceRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Service not found with id: " + id));