Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(VIST-CPC-811): send email on visit request #589

Merged
merged 11 commits into from
Oct 23, 2023
Merged
50 changes: 21 additions & 29 deletions api-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,31 @@ repositories {


dependencies {


implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'

implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.yaml:snakeyaml:2.2'

implementation 'org.webjars:bootstrap:5.1.0' // https://mvnrepository.com/artifact/org.webjars/bootstrap
implementation 'org.webjars:jquery:3.6.0' // https://mvnrepository.com/artifact/org.webjars/jquery
implementation 'org.webjars:angularjs:2.0.0-alpha.22' // https://mvnrepository.com/artifact/org.webjars/angularjs

implementation 'org.webjars.bower:angular-ui-router:1.0.28' // https://mvnrepository.com/artifact/org.webjars.bower/angular-ui-router
implementation 'org.webjars:webjars-locator-core:0.47' // https://mvnrepository.com/artifact/org.webjars/webjars-locator-core
implementation 'ro.isdc.wro4j:wro4j-core:1.10.1' // https://mvnrepository.com/artifact/ro.isdc.wro4j/wro4j-core
implementation 'com.github.houbie:lesscss-gradle-plugin:1.0.3-less-1.7.0' // https://mvnrepository.com/artifact/com.github.houbie/lesscss-gradle-plugin
implementation 'com.github.houbie:lesscss-gradle-plugin:1.0.3-less-1.7.0' // https://mvnrepository.com/artifact/com.github.houbie/lesscss-gradle-plugin
implementation 'org.jolokia:jolokia-core:1.7.0' // https://mvnrepository.com/artifact/org.jolokia/jolokia-core
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' //for serializing and deserializing java.time.LocalDateTime

runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2', 'io.jsonwebtoken:jjwt-jackson:0.11.2'

implementation 'org.webjars:bootstrap:5.1.0', // https://mvnrepository.com/artifact/org.webjars/bootstrap
'org.springframework.boot:spring-boot-starter-webflux',
'org.springframework.boot:spring-boot-starter-actuator',
'org.springframework.boot:spring-boot-starter-validation',
'io.jsonwebtoken:jjwt-api:0.11.2',
'org.webjars:jquery:3.7.1', // https://mvnrepository.com/artifact/org.webjars/jquery
'org.webjars:angularjs:2.0.0-alpha.22', // https://mvnrepository.com/artifact/org.webjars/angularjs
'org.webjars.bower:angular-ui-router:1.0.28', // https://mvnrepository.com/artifact/org.webjars.bower/angular-ui-router
'org.webjars:webjars-locator-core:0.47', // https://mvnrepository.com/artifact/org.webjars/webjars-locator-core
'ro.isdc.wro4j:wro4j-core:1.10.1', // https://mvnrepository.com/artifact/ro.isdc.wro4j/wro4j-core
'com.github.houbie:lesscss-gradle-plugin:1.0.3-less-1.7.0', // https://mvnrepository.com/artifact/com.github.houbie/lesscss-gradle-plugin
'org.jolokia:jolokia-core:1.7.0', // https://mvnrepository.com/artifact/org.jolokia/jolokia-core
'io.springfox:springfox-boot-starter:3.0.0',
'com.fasterxml.jackson.datatype:jackson-datatype-jsr310', //for serializing and deserializing java.time.LocalDateTime
'org.yaml:snakeyaml:2.2'

testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'com.squareup.okhttp3:okhttp:4.11.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.11.0'


testImplementation 'com.squareup.okhttp3:okhttp:4.11.0',
'com.squareup.okhttp3:mockwebserver:4.11.0',
'io.projectreactor:reactor-test'
}

jacoco {
Expand Down Expand Up @@ -89,4 +81,4 @@ test {
testLogging {
events "passed", "skipped", "failed"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.petclinic.bffapigateway.dtos.Visits.*;
swafit marked this conversation as resolved.
Show resolved Hide resolved
import com.petclinic.bffapigateway.dtos.Visits.Status;
import com.petclinic.bffapigateway.dtos.Visits.VisitRequestDTO;
import com.petclinic.bffapigateway.dtos.Visits.VisitResponseDTO;
import com.petclinic.bffapigateway.exceptions.BadRequestException;
import com.petclinic.bffapigateway.exceptions.DuplicateTimeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
Expand All @@ -20,14 +21,12 @@
import java.io.IOException;
/**
* @author Maciej Szarlinski
* Copied from https://github.com/spring-petclinic/spring-petclinic-microservices

Check warning on line 24 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/VisitsServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Link specified as plain text

Link specified as plain text
*/

@Component
@Slf4j
public class VisitsServiceClient {
private final WebClient webClient;

@Autowired
public VisitsServiceClient(
@Value("${app.visits-service-new.host}") String visitsServiceHost,
Expand Down Expand Up @@ -125,7 +124,6 @@
else {
return Mono.error(new BadRequestException(message));
}

} catch (IOException e) {
// Handle parsing error
return Mono.error(new BadRequestException("Bad Request"));
Expand All @@ -150,7 +148,7 @@
.bodyToMono(Void.class);
}

/*

Check notice on line 151 in api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/VisitsServiceClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (17 lines)
public Flux<VisitDetails> getPreviousVisitsForPet(final String petId) {
return webClient
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ public class VisitRequestDTO {
private LocalDateTime visitDate;
private String description;
private String petId;
private String ownerId;
private String jwtToken;//used to get the userDetails from the Auth-Service when sending visit emails
private String practitionerId;
private Status status;

public VisitRequestDTO(LocalDateTime now, String description, String petId, String practitionerId) {
public VisitRequestDTO(LocalDateTime now, String description, String petId, String ownerId, String jwtToken, String practitionerId) {
this.visitDate = now;
this.description = description;
this.petId = petId;
this.ownerId = ownerId;
this.jwtToken = jwtToken;
this.practitionerId = practitionerId;
this.status = Status.UPCOMING;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
import reactor.core.publisher.Mono;

import java.util.Map;
import java.util.List;
import java.util.Optional;

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

Check warning on line 37 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Link specified as plain text

Link specified as plain text
* Modified to remove circuitbreaker
*/

Expand Down Expand Up @@ -159,7 +158,7 @@
.defaultIfEmpty(ResponseEntity.badRequest().build());
}

/*@GetMapping(value = "owners/{ownerId}/pets")

Check notice on line 161 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (4 lines)
public Flux<PetResponseDTO> getAllPetsFromOwnerId(@PathVariable String ownerId){
return customersServiceClient.getAllPets(ownerId);
}*/
Expand Down Expand Up @@ -262,8 +261,9 @@
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) {
// visit.setPetId(petId);
Mono<ResponseEntity<VisitResponseDTO>> addVisit(@RequestBody VisitRequestDTO visit, @PathVariable String ownerId, /*@PathVariable String petId,*/ @CookieValue("Bearer") String auth) {
visit.setOwnerId(ownerId);
visit.setJwtToken(auth);
return visitsServiceClient.createVisitForPet(visit).map(ResponseEntity.status(HttpStatus.CREATED)::body)
.defaultIfEmpty(ResponseEntity.badRequest().build());
}
Expand All @@ -284,7 +284,7 @@
.defaultIfEmpty(ResponseEntity.notFound().build());
}
// @PutMapping(value = "owners/*/pets/{petId}/visits/{visitId}", consumes = "application/json", produces = "application/json")
/*

Check notice on line 287 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (33 lines)
Mono<ResponseEntity<VisitDetails>> updateVisit(@RequestBody VisitDetails visit, @PathVariable String petId, @PathVariable String visitId) {
visit.setPetId(petId);
visit.setVisitId(visitId);
Expand Down Expand Up @@ -327,7 +327,7 @@
.defaultIfEmpty(ResponseEntity.badRequest().build());
}

// @PutMapping(value = "owners/*/pets/{petId}/visits/{visitId}", consumes = "application/json", produces = "application/json")

Check notice on line 330 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (7 lines)
// Mono<ResponseEntity<VisitDetails>> updateVisit(@RequestBody VisitDetails visit, @PathVariable String petId, @PathVariable String visitId) {
// visit.setPetId(petId);
// visit.setVisitId(visitId);
Expand All @@ -336,7 +336,7 @@
// }
/* End of Visit Methods */

/**

Check warning on line 339 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Dangling Javadoc comment

Dangling Javadoc comment
* End of Visit Methods
**/

Expand Down Expand Up @@ -500,7 +500,7 @@

@IsUserSpecific(idToMatch = {"vetId"})
@GetMapping("/vets/vetBillId/{vetId}")
public Mono<ResponseEntity<VetResponseDTO>> getVetByVetBillId(@PathVariable String vetBillId) {

Check warning on line 503 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatch in @PathVariable declarations and usages

Cannot resolve path variable 'vetBillId' in request mapping

Check notice on line 503 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatch in @PathVariable declarations and usages

Path variable 'vetId' is not consumed
return vetsServiceClient.getVetByVetBillId(VetsEntityDtoUtil.verifyId(vetBillId))
.map(ResponseEntity::ok)
.defaultIfEmpty(ResponseEntity.notFound().build());
Expand Down Expand Up @@ -539,10 +539,10 @@
.defaultIfEmpty(ResponseEntity.notFound().build());
}

/**

Check warning on line 542 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Dangling Javadoc comment

Dangling Javadoc comment
* End of Vet Methods
**/
//

Check notice on line 545 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (16 lines)
// @DeleteMapping(value = "users/{userId}")
// public Mono<UserDetails> deleteUser(@RequestHeader(AUTHORIZATION) String auth, final @PathVariable long userId) {
// return authServiceClient.deleteUser(auth, userId);
Expand Down Expand Up @@ -632,7 +632,7 @@
}


// @PostMapping(value = "owners",

Check notice on line 635 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (6 lines)
// consumes = "application/json",
// produces = "application/json")
// public Mono<OwnerResponseDTO> createOwner(@RequestBody OwnerResponseDTO model){
Expand All @@ -646,12 +646,12 @@
.defaultIfEmpty(ResponseEntity.badRequest().build());
}

/*@GetMapping(value = "owners/photo/{ownerId}")

Check notice on line 649 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (4 lines)
public Mono<PhotoDetails> getOwnerPhoto(@PathVariable int ownerId) {
return customersServiceClient.getOwnerPhoto(ownerId);
}*/

// @PostMapping(value = "owners/{ownerId}/pet/photo/{petId}")

Check notice on line 654 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (19 lines)
// public Mono<String> setPetPhoto(@PathVariable String ownerId, @RequestBody PhotoDetails photoDetails, @PathVariable String petId) {
// return customersServiceClient.setPetPhoto(ownerId, photoDetails, petId);
// }
Expand All @@ -675,7 +675,7 @@



/*

Check notice on line 678 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Commented out code

Commented out code (9 lines)

// Endpoint to update an owner
@PutMapping("owners/{ownerId}")
Expand Down Expand Up @@ -716,7 +716,7 @@
.defaultIfEmpty(ResponseEntity.notFound().build());
}

/**

Check warning on line 719 in api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Dangling Javadoc comment

Dangling Javadoc comment
* End of Owner Methods
**/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void createVisitForPet_Valid() throws JsonProcessingException {
LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
"Test Visit",
"1",
"f470653d-05c5-4c45-b7a0-7d70f003d2ac",
"testJwtToken",
"2"
);

Expand Down Expand Up @@ -178,6 +180,8 @@ void createVisitForPet_Valid() throws JsonProcessingException {

// Assert
StepVerifier.create(resultMono)
.expectNext()
.expectNext()
.expectNextMatches(visitResponse -> Objects.equals(visitResponse.getVisitId(), visitResponseDTO.getVisitId()))
.verifyComplete();

Expand All @@ -191,6 +195,8 @@ void createVisitForPet_DuplicateTime_ThrowsDuplicateTimeException() throws JsonP
LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
"Test Visit",
"1",
"f470653d-05c5-4c45-b7a0-7d70f003d2ac",
"testJwtToken",
"2"
);

Expand Down Expand Up @@ -218,6 +224,8 @@ void createVisitForPet_NotFound_ThrowsNotFoundException() throws JsonProcessingE
LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
"Test Visit",
"1",
"f470653d-05c5-4c45-b7a0-7d70f003d2ac",
"testJwtToken",
"2"
);

Expand Down Expand Up @@ -245,6 +253,8 @@ void createVisitForPet_BadRequest_ThrowsBadRequestException() throws JsonProcess
LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
"Test Visit",
"1",
"f470653d-05c5-4c45-b7a0-7d70f003d2ac",
"testJwtToken",
"2"
);

Expand Down Expand Up @@ -272,6 +282,8 @@ void createVisitForPet_InvalidErrorResponse_ThrowsBadRequestException() throws J
LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
"Test Visit",
"1",
"f470653d-05c5-4c45-b7a0-7d70f003d2ac",
"testJwtToken",
"2"
);

Expand Down Expand Up @@ -322,7 +334,7 @@ void getVisitById() throws Exception {
.visitDate(LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")))
.description("this is a dummy description")
.petId("2")
.petName("YourPetNameHere")
.petName("YourPetNameHere")
.petBirthDate(new Date())
.practitionerId("2")
.vetFirstName("VetFirstNameHere")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@SpringBootTest
Expand All @@ -49,7 +48,7 @@ void setUp(){
.thenReturn(Calls.response(format("Message sent to %s", EMAIL_VALID.getTo())));

when(mockMailCall.sendMail(EMAIL_EMPTY_INVALID))
.thenReturn(Calls.response(Response.error(400, ResponseBody.create(JSON, "Bad request"))));
.thenReturn(Calls.response(Response.error(400, ResponseBody.create("Bad request", JSON))));
}

@Test
Expand Down
40 changes: 20 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ services:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- mongo2

# visits:
# build: visits-service
# hostname: visits
# #mem_limit: 350m
# environment:
# - SPRING_PROFILES_ACTIVE=docker
# depends_on:
# mysql1:
# condition: service_healthy
- mailer-service

inventory-service:
build: inventory-service
Expand All @@ -47,16 +38,6 @@ services:
depends_on:
- mongo-customers

# customers:
# build: customers-service
# hostname: customers
# #mem_limit: 350m
# environment:
# - SPRING_PROFILES_ACTIVE=docker
# depends_on:
# mysql3:
# condition: service_healthy

api-gateway:
build: api-gateway
#mem_limit: 350m
Expand Down Expand Up @@ -101,6 +82,25 @@ services:
env_file:
- mailer.env

# visits:
# build: visits-service
# hostname: visits
# #mem_limit: 350m
# environment:
# - SPRING_PROFILES_ACTIVE=docker
# depends_on:
# mysql1:
# condition: service_healthy

# customers:
# build: customers-service
# hostname: customers
# #mem_limit: 350m
# environment:
# - SPRING_PROFILES_ACTIVE=docker
# depends_on:
# mysql3:
# condition: service_healthy

# mysql1:
# image: mysql:5.7
Expand Down
32 changes: 17 additions & 15 deletions visits-service-new/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ ext {
mapstructVersion = "1.5.5.Final"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive',
'org.springframework.boot:spring-boot-starter-webflux',
'org.yaml:snakeyaml:2.2',
"org.mapstruct:mapstruct:${mapstructVersion}",
'org.simplejavamail:simple-java-mail:8.3.1', 'net.markenwerk:utils-mail-dkim:2.0.1', //Simple Java Mail and DKIM a framework for DKIM signing and verification
'com.squareup.retrofit2:retrofit:2.9.0', 'com.squareup.retrofit2:converter-jackson:2.9.0'

implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok',
"org.mapstruct:mapstruct-processor:${mapstructVersion}"


implementation("org.mapstruct:mapstruct:${mapstructVersion}")
compileOnly "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor 'org.projectlombok:lombok',
"org.mapstruct:mapstruct-processor:${mapstructVersion}"

testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.yaml:snakeyaml:2.2'
testImplementation 'org.yaml:snakeyaml:2.2'
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring30x:4.9.2'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'com.squareup.okhttp3:okhttp:4.11.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.11.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.11.0', 'com.squareup.okhttp3:okhttp:4.11.0',
'org.simplejavamail:simple-java-mail:8.3.1', 'net.markenwerk:utils-mail-dkim:2.0.1', //Simple Java Mail and DKIM a framework for DKIM signing and verification
'org.springframework.boot:spring-boot-starter-test',
'org.yaml:snakeyaml:2.2',
'de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring30x:4.9.2',
'io.projectreactor:reactor-test',
'com.squareup.retrofit2:retrofit-mock:2.9.0'
}

jacoco {
Expand Down
Loading
Loading