Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swafit committed Oct 23, 2023
1 parent 76f343c commit d1e61b7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.petclinic.bffapigateway.BFFApiGatewayApplication;
import com.petclinic.bffapigateway.dtos.Visits.*;
import com.petclinic.bffapigateway.exceptions.BadRequestException;
import com.petclinic.bffapigateway.exceptions.DuplicateTimeException;
Expand Down Expand Up @@ -132,6 +133,33 @@ else if (httpStatus == HttpStatus.CONFLICT){
}
});
})
.onStatus(HttpStatusCode::is2xxSuccessful, response -> {
HttpStatusCode httpStatus = response.statusCode();
if (httpStatus == HttpStatus.CREATED) {

return null;
// return response.bodyToMono(VisitResponseDTO.class);
}
return null;

// 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"));
// }
// });
})
.bodyToMono(VisitResponseDTO.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ public Mono<VisitResponseDTO> getVisitByVisitId(@PathVariable String visitId){
return visitsServiceClient.getVisitByVisitId(visitId);
}
@PostMapping(value = "visit/owners/{ownerId}/pets/{petId}/visits", consumes = "application/json", produces = "application/json")
Mono<ResponseEntity<VisitResponseDTO>> addVisit(@RequestBody VisitRequestDTO visit, @PathVariable String ownerId, @PathVariable String petId) {
Mono<ResponseEntity<VisitResponseDTO>> addVisit(@RequestBody VisitRequestDTO visit, @PathVariable String ownerId, @PathVariable String petId, @CookieValue("Bearer") String auth) {
// visit.setPetId(petId);
Mono<UserDetails> user = getUserById(auth, ownerId);
return visitsServiceClient.createVisitForPet(visit).map(ResponseEntity.status(HttpStatus.CREATED)::body)
.defaultIfEmpty(ResponseEntity.badRequest().build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.petclinic.visits.visitsservicenew.DataLayer.Status;
import com.petclinic.visits.visitsservicenew.DataLayer.VisitRepo;
import com.petclinic.visits.visitsservicenew.DomainClientLayer.PetResponseDTO;
import com.petclinic.visits.visitsservicenew.DomainClientLayer.PetsClient;
import com.petclinic.visits.visitsservicenew.DomainClientLayer.VetDTO;
import com.petclinic.visits.visitsservicenew.DomainClientLayer.VetsClient;
import com.petclinic.visits.visitsservicenew.DomainClientLayer.*;
import com.petclinic.visits.visitsservicenew.Exceptions.BadRequestException;
import com.petclinic.visits.visitsservicenew.Exceptions.DuplicateTimeException;
import com.petclinic.visits.visitsservicenew.Exceptions.NotFoundException;
Expand Down Expand Up @@ -100,10 +97,6 @@ public Mono<VisitResponseDTO> addVisit(Mono<VisitRequestDTO> visitRequestDTOMono
.flatMap(visit -> entityDtoUtil.toVisitResponseDTO(visit));
}





@Override
public Mono<Void> deleteVisit(String visitId) {
return repo.existsByVisitId(visitId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.petclinic.visits.visitsservicenew.DomainClientLayer;


import lombok.NoArgsConstructor;
import org.simplejavamail.api.email.Email;
import org.simplejavamail.api.mailer.Mailer;
import org.simplejavamail.api.mailer.config.TransportStrategy;
import org.simplejavamail.email.EmailBuilder;
import org.simplejavamail.mailer.MailerBuilder;


@NoArgsConstructor
public class SimpleJavaMailClient {
private final Email email = EmailBuilder.startingBlank()
.from("From", "[email protected]")
.to("William", "[email protected]")
.withSubject("Email test with simple java mail")
.withPlainText("Email Body")
.buildEmail();

private final Mailer mailer = MailerBuilder
.withSMTPServer("smtp.gmail.com", 587, "[email protected]", System.getenv("SMTP_PASS")).withTransportStrategy(TransportStrategy.SMTP_TLS)
// .withEmailOverrides(EmailBuilder.startingBlank().from("From", "[email protected]").buildEmailCompletedWithDefaultsAndOverrides())
.buildMailer();


public void sendMail(){
/*Email email*/
mailer.sendMail(email);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VisitServiceImplTest {

@MockBean
private VetsClient vetsClient;

@MockBean private SimpleJavaMailClient simpleJavaMailClient;
@MockBean
private PetsClient petsClient;

Expand Down

0 comments on commit d1e61b7

Please sign in to comment.