Skip to content

Commit

Permalink
Merge branch 'main' into feat/VETS-CPC-935_Display_Image_Next_to_Vet_…
Browse files Browse the repository at this point in the history
…Profile_Picture_Based_on_Average_Rating_of_Vet
  • Loading branch information
liu-cal authored Oct 9, 2023
2 parents ab01ab8 + 5d0f254 commit cabae24
Show file tree
Hide file tree
Showing 39 changed files with 675 additions and 722 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Mono<PetResponseDTO> getPet(final String ownerId, final String petId) {

public Flux<PetResponseDTO> getPetsByOwnerId(final String ownerId) {
return webClientBuilder.build().get()
.uri(customersServiceUrl + "/owners/" + ownerId + "/pets")
.uri(customersServiceUrl + "/pet/owner/" + ownerId + "/pets")
.retrieve()
.bodyToFlux(PetResponseDTO.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;
import org.webjars.NotFoundException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.net.URI;
import java.util.List;

import static java.rmi.server.LogStream.log;
import static java.util.stream.Collectors.joining;

/**
* @author Maciej Szarlinski
* Copied from https://github.com/spring-petclinic/spring-petclinic-microservices
Expand All @@ -33,7 +25,6 @@
@Component
@Slf4j
public class VisitsServiceClient {

private final WebClient webClient;

@Autowired
Expand All @@ -42,104 +33,53 @@ public VisitsServiceClient(
@Value("${app.visits-service-new.port}") String visitsServicePort
) {
this.webClient = WebClient.builder()
.baseUrl("http://" + visitsServiceHost + ":" + visitsServicePort)
.baseUrl("http://" + visitsServiceHost + ":" + visitsServicePort + "/visits")
.build();
}

public Flux<VisitResponseDTO> getAllVisits(){
return this.webClient
.get()
.uri("/visits")
.uri("")
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, error -> {
// HttpStatusCode statusCode = error.statusCode();
return Mono.error(new IllegalArgumentException("Something went wrong and got a 400 error"));
})
.onStatus(HttpStatusCode::is4xxClientError, error -> Mono.error(new IllegalArgumentException("Something went wrong and we got a 400 error")))
.onStatus(HttpStatusCode::is5xxServerError, error -> Mono.error(new IllegalArgumentException("Something went wrong and we got a 500 error")))
.bodyToFlux(VisitResponseDTO.class);
}

public Flux<VisitResponseDTO> getVisitsForStatus(final String status){
return webClient
.get()
.uri("/visits/status/{status}", status)
.uri("/status/{status}", status)
.retrieve()
.bodyToFlux(VisitResponseDTO.class);
}

public Mono<Visits> getVisitsForPets(final List<Integer> petIds) {
return this.webClient
.get()
.uri("/pets/visits?petId={petId}", joinIds(petIds))
.retrieve()
.bodyToMono(Visits.class);
}

public Flux<VisitDetails> getVisitsForPet(final String petId){
public Flux<VisitResponseDTO> getVisitsForPet(final String petId){
return webClient
.get()
.uri("/visits/pets/{petId}", petId)
.uri("/pets/{petId}", petId)
.retrieve()
.bodyToFlux(VisitDetails.class);
}

public Flux<VisitDetails> getPreviousVisitsForPet(final String petId) {
return webClient
.get()
.uri("/visits/previous/{petId}", petId)
.retrieve()
.bodyToFlux(VisitDetails.class);
.bodyToFlux(VisitResponseDTO.class);
}

public Flux<VisitDetails> getVisitForPractitioner(final int practitionerId){
public Flux<VisitResponseDTO> getVisitByPractitionerId(final String practitionerId){
return webClient
.get()
.uri("visits/vets/{practitionerId}", practitionerId)
.uri("/practitioner/{practitionerId}", practitionerId)
.retrieve()
.bodyToFlux(VisitDetails.class);
}

/*
public Flux<VisitDetails> getVisitsByPractitionerIdAndMonth(final int practitionerId, final String startDate, final String endDate) {
return webClient
.get()
.uri("/visits/calendar/{practitionerId}?dates={startDate},{endDate}", practitionerId, startDate, endDate)
.retrieve()
.bodyToFlux(VisitDetails.class);
.bodyToFlux(VisitResponseDTO.class);
}
*/

public Flux<VisitDetails> getScheduledVisitsForPet(final String petId) {
return webClient
.get()
.uri("/visits/scheduled/{petId}", petId)
.retrieve()
.bodyToFlux(VisitDetails.class);
}

public Mono<VisitResponseDTO> getVisitByVisitId(String visitId) {
return webClient
.get()
.uri("/visit/{visitId}", visitId)
.uri("/{visitId}", visitId)
.retrieve()
.bodyToMono(VisitResponseDTO.class);
}

public Mono<VisitDetails> updateVisitForPet(VisitDetails visit) {
URI uri = UriComponentsBuilder
.fromPath("/owners/*/pets/{petId}/visits/{visitId}")
.buildAndExpand(visit.getPetId(), visit.getVisitId())
.toUri();

return webClient
.put()
.uri(uri)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(visit), VisitDetails.class)
.retrieve()
.onStatus(HttpStatusCode::isError, response -> Mono.error(new BadRequestException("Failed to update visit")))
.bodyToMono(VisitDetails.class);
}


public Mono<VisitResponseDTO> updateStatusForVisitByVisitId(String visitId, String status) {
Expand All @@ -151,61 +91,51 @@ public Mono<VisitResponseDTO> updateStatusForVisitByVisitId(String visitId, Stri
};

return webClient
.put()
.uri("/visits/"+ visitId +"/status/" + newStatus)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToMono(VisitResponseDTO.class);
.put()
.uri("/"+ visitId +"/status/" + newStatus)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToMono(VisitResponseDTO.class);
}

/* public Mono<VisitDetails> createVisitForPet(VisitDetails visit) {
return webClient
.post()
.uri("/visits")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(visit), VisitDetails.class)
.retrieve()
.bodyToMono(VisitDetails.class);

}*/
public Mono<VisitResponseDTO> createVisitForPet(VisitRequestDTO visit) {
return webClient
public Mono<VisitResponseDTO> createVisitForPet(VisitRequestDTO visit) {
return webClient
.post()
.uri("/visits")
.uri("")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(visit), VisitRequestDTO.class)
.retrieve()
.onStatus(response -> response.is4xxClientError(), response -> {
.onStatus(HttpStatusCode::is4xxClientError, response -> {
HttpStatusCode httpStatus = response.statusCode();
return response.bodyToMono(String.class)
.flatMap(errorMessage -> {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode errorNode = objectMapper.readTree(errorMessage);
String message = errorNode.get("message").asText();

if (httpStatus == HttpStatus.NOT_FOUND) {
return Mono.error(new NotFoundException(message));
} else {
return Mono.error(new BadRequestException(message));
}
} catch (IOException e) {
// Handle parsing error
return Mono.error(new BadRequestException("Bad Request"));
.flatMap(errorMessage -> {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode errorNode = objectMapper.readTree(errorMessage);
String message = errorNode.get("message").asText();

if (httpStatus == HttpStatus.NOT_FOUND) {
return Mono.error(new NotFoundException(message));
} else {
return Mono.error(new BadRequestException(message));
}
});
} catch (IOException e) {
// Handle parsing error
return Mono.error(new BadRequestException("Bad Request"));
}
});
})
.bodyToMono(VisitResponseDTO.class);
}
}

public Mono<Void> deleteVisitByVisitId(String visitId){
return webClient
.delete()
.uri("/visits/{visitId}", visitId)
.uri("/{visitId}", visitId)
.retrieve()
.bodyToMono(Void.class);
}

public Mono<Void> deleteAllCancelledVisits(){
return webClient
.delete()
Expand All @@ -214,12 +144,70 @@ public Mono<Void> deleteAllCancelledVisits(){
.bodyToMono(Void.class);
}

/*
public Flux<VisitDetails> getPreviousVisitsForPet(final String petId) {
return webClient
.get()
.uri("/visits/previous/{petId}", petId)
.retrieve()
.bodyToFlux(VisitDetails.class);
}
public Flux<VisitDetails> getScheduledVisitsForPet(final String petId) {
return webClient
.get()
.uri("/visits/scheduled/{petId}", petId)
.retrieve()
.bodyToFlux(VisitDetails.class);
}
*/
// public Mono<VisitDetails> updateVisitForPet(VisitDetails visit) {
// URI uri = UriComponentsBuilder
// .fromPath("/owners/*/pets/{petId}/visits/{visitId}")
// .buildAndExpand(visit.getPetId(), visit.getVisitId())
// .toUri();
/*
return webClient
.put()
.uri(uri)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(visit), VisitDetails.class)
.retrieve()
.onStatus(HttpStatusCode::isError, response -> Mono.error(new BadRequestException("Failed to update visit")))
.bodyToMono(VisitDetails.class);
}
private String joinIds(List<Integer> petIds) {
return petIds.stream().map(Object::toString).collect(joining(","));
}
public Mono<Visits> getVisitsForPets(final List<Integer> petIds) {
return this.webClient
.get()
.uri("/pets/visits?petId={petId}", joinIds(petIds))
.retrieve()
.bodyToMono(Visits.class);
}
public Flux<VisitDetails> getVisitsByPractitionerIdAndMonth(final int practitionerId, final String startDate, final String endDate) {
return webClient
.get()
.uri("/visits/calendar/{practitionerId}?dates={startDate},{endDate}", practitionerId, startDate, endDate)
.retrieve()
.bodyToFlux(VisitDetails.class);
}
return webClient
.post()
.uri("/visits")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(visit), VisitDetails.class)
.retrieve()
.bodyToMono(VisitDetails.class);
}*/
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public class ProductRequestDTO {
private String productDescription;
private Double productPrice;
private Integer productQuantity;
private Double productSalePrice;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class ProductResponseDTO {
private String productDescription;
private Double productPrice;
private Integer productQuantity;
private Double productSalePrice;

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.petclinic.bffapigateway.dtos.Visits;

/*
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;

/**
* @author Maciej Szarlinski
* Copied from https://github.com/spring-petclinic/spring-petclinic-microservices
*/
/*
@author Maciej Szarlinski
Copied from https://github.com/spring-petclinic/spring-petclinic-microservices
*/

/*
@Data
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -34,3 +34,4 @@ public class VisitDetails {
private Status status = null;
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
@Builder
public class VisitResponseDTO {
private String visitId;
/* private int year;
private int month;
private int day;*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime visitDate;
private String description;
private String petId;
private String practitionerId;
/* private int petId;
private int practitionerId;*/
private Status status;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.petclinic.bffapigateway.dtos.Visits;

/*
import lombok.Value;

import java.util.ArrayList;
import java.util.List;

/**
*/
/*
* @author Maciej Szarlinski
* Copied from https://github.com/spring-petclinic/spring-petclinic-microservices
*/

/*
@Value
public class Visits {

private List<VisitDetails> items = new ArrayList<>();

}

*/
Loading

0 comments on commit cabae24

Please sign in to comment.