Azure deployment setup #297
@@ -10,7 +10,9 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -24,12 +26,14 @@ public class DropdownController {
|
||||
private final StoreRepository storeRepository;
|
||||
private final SupplierRepository supplierRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final AdoptionRepository adoptionRepository;
|
||||
|
||||
public DropdownController(PetRepository petRepository,
|
||||
ServiceRepository serviceRepository, ProductRepository productRepository,
|
||||
CategoryRepository categoryRepository, StoreRepository storeRepository,
|
||||
SupplierRepository supplierRepository,
|
||||
UserRepository userRepository) {
|
||||
UserRepository userRepository,
|
||||
AdoptionRepository adoptionRepository) {
|
||||
this.petRepository = petRepository;
|
||||
this.serviceRepository = serviceRepository;
|
||||
this.productRepository = productRepository;
|
||||
@@ -37,6 +41,7 @@ public class DropdownController {
|
||||
this.storeRepository = storeRepository;
|
||||
this.supplierRepository = supplierRepository;
|
||||
this.userRepository = userRepository;
|
||||
this.adoptionRepository = adoptionRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/pets")
|
||||
@@ -71,8 +76,19 @@ public class DropdownController {
|
||||
@GetMapping("/appointment-customers")
|
||||
@PreAuthorize("hasAnyRole('STAFF', 'ADMIN')")
|
||||
public ResponseEntity<List<DropdownOption>> getAppointmentCustomers() {
|
||||
Set<Long> ownersWithPets = petRepository.findAll().stream()
|
||||
.filter(p -> p.getOwner() != null)
|
||||
.map(p -> p.getOwner().getId())
|
||||
.collect(Collectors.toSet());
|
||||
Set<Long> customersWithAdoptions = adoptionRepository.findAll().stream()
|
||||
.filter(a -> "Completed".equalsIgnoreCase(a.getAdoptionStatus()))
|
||||
.map(a -> a.getCustomer().getId())
|
||||
.collect(Collectors.toSet());
|
||||
Set<Long> customersWithPets = new HashSet<>(ownersWithPets);
|
||||
customersWithPets.addAll(customersWithAdoptions);
|
||||
return ResponseEntity.ok(
|
||||
userRepository.findByRoleAndActiveTrue(User.Role.CUSTOMER).stream()
|
||||
.filter(u -> customersWithPets.contains(u.getId()))
|
||||
.map(u -> new DropdownOption(u.getId(), u.getFirstName() + " " + u.getLastName()))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
@@ -156,11 +172,16 @@ public class DropdownController {
|
||||
@GetMapping("/customers/{customerId}/pets")
|
||||
@PreAuthorize("hasAnyRole('STAFF', 'ADMIN')")
|
||||
public ResponseEntity<List<DropdownOption>> getCustomerPets(@PathVariable Long customerId) {
|
||||
return ResponseEntity.ok(
|
||||
petRepository.findAllByOwner_IdOrderByPetNameAsc(customerId).stream()
|
||||
Set<Long> seen = new HashSet<>();
|
||||
List<DropdownOption> pets = new java.util.ArrayList<>();
|
||||
petRepository.findAllByOwner_IdOrderByPetNameAsc(customerId).stream()
|
||||
.map(p -> new DropdownOption(p.getPetId(), p.getPetName()))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
.forEach(o -> { if (seen.add(o.getId())) pets.add(o); });
|
||||
adoptionRepository.findByCustomer_IdAndAdoptionStatusIgnoreCase(customerId, "Completed").stream()
|
||||
.map(a -> new DropdownOption(a.getPet().getPetId(), a.getPet().getPetName()))
|
||||
.forEach(o -> { if (seen.add(o.getId())) pets.add(o); });
|
||||
pets.sort(java.util.Comparator.comparing(DropdownOption::getLabel, String.CASE_INSENSITIVE_ORDER));
|
||||
return ResponseEntity.ok(pets);
|
||||
}
|
||||
|
||||
@GetMapping("/suppliers")
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
@@ -37,4 +38,6 @@ public interface AdoptionRepository extends JpaRepository<Adoption, Long> {
|
||||
boolean existsByPet_IdAndAdoptionStatusIgnoreCaseAndAdoptionIdNot(Long petId, String adoptionStatus, Long adoptionId);
|
||||
|
||||
boolean existsByPet_IdAndAdoptionStatusIgnoreCase(Long petId, String adoptionStatus);
|
||||
|
||||
List<Adoption> findByCustomer_IdAndAdoptionStatusIgnoreCase(Long customerId, String adoptionStatus);
|
||||
}
|
||||
|
||||
@@ -241,16 +241,16 @@ public class AppointmentController {
|
||||
return new AppointmentDTO(
|
||||
response.getAppointmentId().intValue(),
|
||||
response.getCustomerId() != null ? response.getCustomerId().intValue() : 0,
|
||||
response.getCustomerName(),
|
||||
response.getCustomerName() != null ? response.getCustomerName() : "",
|
||||
response.getPetId() != null ? response.getPetId().intValue() : 0,
|
||||
response.getPetName(),
|
||||
response.getPetName() != null ? response.getPetName() : "",
|
||||
response.getServiceId() != null ? response.getServiceId().intValue() : 0,
|
||||
response.getServiceName(),
|
||||
response.getServiceName() != null ? response.getServiceName() : "",
|
||||
response.getEmployeeId() != null ? response.getEmployeeId().intValue() : 0,
|
||||
response.getEmployeeName(),
|
||||
response.getAppointmentDate().toString(),
|
||||
response.getAppointmentTime().toString(),
|
||||
response.getAppointmentStatus()
|
||||
response.getEmployeeName() != null ? response.getEmployeeName() : "",
|
||||
response.getAppointmentDate() != null ? response.getAppointmentDate().toString() : "",
|
||||
response.getAppointmentTime() != null ? response.getAppointmentTime().toString() : "",
|
||||
response.getAppointmentStatus() != null ? response.getAppointmentStatus() : ""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,12 @@ public class ChatController {
|
||||
});
|
||||
|
||||
realtimeClient.setConversationListener(conversation -> Platform.runLater(() -> upsertConversation(conversation)));
|
||||
realtimeClient.setMessageListener(message -> Platform.runLater(() -> appendMessageIfSelected(message)));
|
||||
realtimeClient.setMessageListener(message -> Platform.runLater(() -> {
|
||||
Long myId = UserSession.getInstance().getUserId();
|
||||
if (message.getSenderId() == null || !message.getSenderId().equals(myId)) {
|
||||
appendMessageIfSelected(message);
|
||||
}
|
||||
}));
|
||||
realtimeClient.setStatusListener(status -> Platform.runLater(() -> lblChatStatus.setText(status)));
|
||||
realtimeClient.subscribeToConversations();
|
||||
|
||||
@@ -208,9 +213,7 @@ public class ChatController {
|
||||
MessageResponse response = ChatApi.getInstance().sendMessage(conversationId, new MessageRequest(content));
|
||||
Platform.runLater(() -> {
|
||||
btnSend.setDisable(false);
|
||||
if (!realtimeClient.isConnected()) {
|
||||
appendMessageIfSelected(response);
|
||||
}
|
||||
appendMessageIfSelected(response);
|
||||
if (selectedConversation != null && selectedConversation.getId().equals(conversationId)) {
|
||||
lblChatStatus.setText("Message sent");
|
||||
}
|
||||
|
||||
@@ -327,12 +327,12 @@ public class PetController {
|
||||
private Pet mapToPet(PetResponse response) {
|
||||
Pet pet = new Pet(
|
||||
response.getPetId().intValue(),
|
||||
response.getPetName(),
|
||||
response.getPetSpecies(),
|
||||
response.getPetBreed(),
|
||||
response.getPetName() != null ? response.getPetName() : "",
|
||||
response.getPetSpecies() != null ? response.getPetSpecies() : "",
|
||||
response.getPetBreed() != null ? response.getPetBreed() : "",
|
||||
response.getPetAge() != null ? response.getPetAge() : 0,
|
||||
response.getPetStatus(),
|
||||
response.getPetPrice().doubleValue(),
|
||||
response.getPetStatus() != null ? response.getPetStatus() : "",
|
||||
response.getPetPrice() != null ? response.getPetPrice().doubleValue() : 0.0,
|
||||
response.getImageUrl()
|
||||
);
|
||||
pet.setCustomerName(response.getCustomerName());
|
||||
|
||||
Reference in New Issue
Block a user