fix lazy loading on me, services, refunds
This commit is contained in:
@@ -25,6 +25,7 @@ import org.springframework.security.authentication.InternalAuthenticationService
|
|||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -130,6 +131,7 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
@GetMapping("/me")
|
@GetMapping("/me")
|
||||||
public ResponseEntity<UserInfoResponse> getCurrentUser() {
|
public ResponseEntity<UserInfoResponse> getCurrentUser() {
|
||||||
User user = getAuthenticatedUser();
|
User user = getAuthenticatedUser();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class Service {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Integer serviceDuration;
|
private Integer serviceDuration;
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
@CollectionTable(name = "service_species", joinColumns = @JoinColumn(name = "serviceId"))
|
@CollectionTable(name = "service_species", joinColumns = @JoinColumn(name = "serviceId"))
|
||||||
@Column(name = "species", length = 50)
|
@Column(name = "species", length = 50)
|
||||||
private Set<String> species = new HashSet<>();
|
private Set<String> species = new HashSet<>();
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ public class RefundService {
|
|||||||
return toResponse(savedRefund);
|
return toResponse(savedRefund);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public RefundResponse getRefundById(Long id, Long customerId) {
|
public RefundResponse getRefundById(Long id, Long customerId) {
|
||||||
Refund refund = refundRepository.findById(id)
|
Refund refund = refundRepository.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Refund not found"));
|
.orElseThrow(() -> new RuntimeException("Refund not found"));
|
||||||
@@ -92,6 +93,7 @@ public class RefundService {
|
|||||||
return toResponse(refund);
|
return toResponse(refund);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public List<RefundResponse> getAllRefunds(Long customerId) {
|
public List<RefundResponse> getAllRefunds(Long customerId) {
|
||||||
List<Refund> refunds;
|
List<Refund> refunds;
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class ServiceService {
|
|||||||
this.serviceRepository = serviceRepository;
|
this.serviceRepository = serviceRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public Page<ServiceResponse> getAllServices(String query, Pageable pageable) {
|
public Page<ServiceResponse> getAllServices(String query, Pageable pageable) {
|
||||||
Page<com.petshop.backend.entity.Service> services;
|
Page<com.petshop.backend.entity.Service> services;
|
||||||
if (query != null && !query.trim().isEmpty()) {
|
if (query != null && !query.trim().isEmpty()) {
|
||||||
@@ -29,6 +30,7 @@ public class ServiceService {
|
|||||||
return services.map(this::mapToResponse);
|
return services.map(this::mapToResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public ServiceResponse getServiceById(Long id) {
|
public ServiceResponse getServiceById(Long id) {
|
||||||
com.petshop.backend.entity.Service service = serviceRepository.findById(id)
|
com.petshop.backend.entity.Service service = serviceRepository.findById(id)
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Service not found with id: " + id));
|
.orElseThrow(() -> new ResourceNotFoundException("Service not found with id: " + id));
|
||||||
|
|||||||
Reference in New Issue
Block a user