Skip to content

Commit

Permalink
Merge branch 'main' into feat/BILL-CPC-933_Implement_Button_To_Calcul…
Browse files Browse the repository at this point in the history
…ate_Bill_With_Tax
  • Loading branch information
HennaCH authored Oct 24, 2023
2 parents 3ba0ad7 + 3395e5e commit 227344a
Show file tree
Hide file tree
Showing 141 changed files with 3,981 additions and 732 deletions.
49 changes: 21 additions & 28 deletions api-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +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 @@ -88,4 +81,4 @@ test {
testLogging {
events "passed", "skipped", "failed"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.List;
import java.util.UUID;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
Expand Down Expand Up @@ -83,6 +87,16 @@ public Flux<UserDetails> getUsers(String jwtToken) {
.retrieve()
.bodyToFlux(UserDetails.class);
}

public Mono<Void> deleteUser(String jwtToken, String userId) {
return webClientBuilder.build()
.delete()
.uri(authServiceUrl + "/users/{userId}", userId)
.cookie("Bearer", jwtToken)
.retrieve()
.bodyToMono(void.class);
}

//FUCK REACTIVE
/*
This shit is beyond cursed, but I do not care. This works, I only spent 6 HOURS OF MY LIFE.
Expand Down Expand Up @@ -123,6 +137,23 @@ public Mono<OwnerResponseDTO> createUser (Mono<Register> model) {

}

public Mono<UserPasswordLessDTO> createInventoryMangerUser(Mono<RegisterInventoryManager> registerInventoryManagerMono){
String uuid = UUID.randomUUID().toString();
return registerInventoryManagerMono.flatMap(registerInventoryManager -> {
registerInventoryManager.setUserId(uuid);
return webClientBuilder.build().post()
.uri(authServiceUrl + "/users")
.body(Mono.just(registerInventoryManager), RegisterInventoryManager.class)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError,
n -> rethrower.rethrow(n,
x -> new GenericHttpException(x.get("message").toString(), BAD_REQUEST))
)
.bodyToMono(UserPasswordLessDTO.class);
});
}


public Mono<VetResponseDTO> createVetUser(Mono<RegisterVet> model){

Expand All @@ -145,6 +176,7 @@ public Mono<VetResponseDTO> createVetUser(Mono<RegisterVet> model){
VetRequestDTO vetDTO = VetRequestDTO.builder()
.specialties(registerVet.getVet().getSpecialties())
.active(registerVet.getVet().isActive())
.photoDefault(registerVet.getVet().isPhotoDefault())
.email(registerVet.getEmail())
.resume(registerVet.getVet().getResume())
.workday(registerVet.getVet().getWorkday())
Expand All @@ -154,7 +186,8 @@ public Mono<VetResponseDTO> createVetUser(Mono<RegisterVet> model){
.lastName(registerVet.getVet().getLastName())
.vetId(uuid)
.build();
return vetsServiceClient.createVet((Mono.just(vetDTO)));
log.debug("In Api, photo default is: " + vetDTO.isPhotoDefault());
return vetsServiceClient.createVet((Mono.just(vetDTO)));
}
);
}).doOnError(throwable -> {
Expand All @@ -177,15 +210,6 @@ public Mono<VetResponseDTO> createVetUser(Mono<RegisterVet> model){
// .bodyToMono(UserDetails.class);
// }
//
// public Mono<UserDetails> deleteUser(String auth, final long userId) {
// return webClientBuilder.build()
// .delete()
// .uri(authServiceUrl + "/users/{userId}", userId)
// .header("Authorization", auth)
// .retrieve()
// .bodyToMono(UserDetails.class);
// }

public Mono<ResponseEntity<UserDetails>> verifyUser(final String token) {

return webClientBuilder.build()
Expand Down Expand Up @@ -225,6 +249,26 @@ public Mono<ResponseEntity<UserPasswordLessDTO>> login(final Mono<Login> login)
}
}

public Mono<ResponseEntity<Void>> logout(ServerHttpRequest request, ServerHttpResponse response) {
log.info("Entered AuthServiceClient logout method");
List<HttpCookie> cookies = request.getCookies().get("Bearer");
if (cookies != null && !cookies.isEmpty()) {
ResponseCookie cookie = ResponseCookie.from("Bearer", "")
.httpOnly(true)
.secure(true)
.path("/api/gateway")
.domain("localhost")
.maxAge(Duration.ofSeconds(0))
.sameSite("Lax").build();
response.addCookie(cookie);
log.info("Logout Success: Account session ended");
return Mono.just(ResponseEntity.noContent().build());
} else {
log.warn("Logout Error: Problem removing account cookies, Session may have expired, redirecting to login page");
return Mono.just(ResponseEntity.status(HttpStatus.UNAUTHORIZED).build());
}
}


public Mono<ResponseEntity<Void>> sendForgottenEmail(Mono<UserEmailRequestDTO> emailRequestDTOMono) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public Mono<BillResponseDTO> updateBill(String billId, Mono<BillRequestDTO> bill
.bodyToMono(BillResponseDTO.class);
}

public Mono<Void> deleteAllBills() {
return webClientBuilder.build()
.delete()
.uri(billServiceUrl)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Void.class);
}

public Mono<Void> deleteBill(final String billId) {
return webClientBuilder.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerRequestDTO;
import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO;
import com.petclinic.bffapigateway.dtos.Pets.PetRequestDTO;
import com.petclinic.bffapigateway.dtos.Pets.PetResponseDTO;
import com.petclinic.bffapigateway.dtos.Pets.PetType;
import com.petclinic.bffapigateway.dtos.Pets.PetTypeResponseDTO;
import com.petclinic.bffapigateway.dtos.Pets.*;
import com.petclinic.bffapigateway.dtos.Vets.PhotoDetails;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -263,4 +260,29 @@ public Flux<PetTypeResponseDTO> getAllPetTypes() {
.retrieve()
.bodyToFlux(PetTypeResponseDTO.class);
}
public Mono<PetTypeResponseDTO> getPetTypeByPetTypeId(String petTypeId) {
return webClientBuilder.build().get()
.uri(customersServiceUrl + "/owners/petTypes/" + petTypeId)
.retrieve()
.bodyToMono(PetTypeResponseDTO.class);
}

public Mono<PetTypeResponseDTO> deletePetType(final String petTypeId) {
return webClientBuilder.build().delete()
.uri(customersServiceUrl +"/owners/petTypes/"+ petTypeId)
.retrieve()
.bodyToMono(PetTypeResponseDTO.class);
}

public Mono<PetTypeResponseDTO> updatePetType(String petTypeId, Mono<PetTypeRequestDTO> petTypeRequestDTO) {
return petTypeRequestDTO.flatMap(requestDTO ->
webClientBuilder.build()
.put()
.uri(customersServiceUrl + "/owners/petTypes/" + petTypeId)
.body(BodyInserters.fromValue(requestDTO))
.retrieve()
.bodyToMono(PetTypeResponseDTO.class)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ public Mono<Resource> getPhotoByVetId(String vetId){
)
.bodyToMono(Resource.class);
}
public Mono<PhotoResponseDTO> getDefaultPhotoByVetId(String vetId){
return webClientBuilder.build()
.get()
.uri(vetsServiceUrl + "/" + vetId + "/default-photo")
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, error->{
HttpStatusCode statusCode = error.statusCode();
if(statusCode.equals(NOT_FOUND))
return Mono.error(new ExistingVetNotFoundException("Photo for vet "+vetId + " not found", NOT_FOUND));
return Mono.error(new IllegalArgumentException("Something went wrong"));
})
.onStatus(HttpStatusCode::is5xxServerError,error->
Mono.error(new IllegalArgumentException("Something went wrong"))
)
.bodyToMono(PhotoResponseDTO.class);
}

public Mono<Resource> addPhotoToVet(String vetId, String photoName, Mono<Resource> image) {
log.debug("VetsServiceClient addPhoto");
Expand Down
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.*;
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 @@ -24,10 +25,8 @@
*/

@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 if (httpStatus == HttpStatus.CONFLICT){
else {
return Mono.error(new BadRequestException(message));
}

} catch (IOException e) {
// Handle parsing error
return Mono.error(new BadRequestException("Bad Request"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.petclinic.bffapigateway.dtos.Auth;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerRequestDTO;
import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO;

Check warning on line 5 in api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Auth/Register.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO;`
import com.petclinic.bffapigateway.utils.Security.Annotations.PasswordStrengthCheck;
Expand All @@ -25,6 +26,7 @@ public class Register {
private String userId;
private String email;
private String username;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private final String defaultRole = Roles.OWNER.toString();
@PasswordStrengthCheck
private String password;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.petclinic.bffapigateway.dtos.Auth;


import com.fasterxml.jackson.annotation.JsonProperty;
import com.petclinic.bffapigateway.utils.Security.Annotations.PasswordStrengthCheck;
import com.petclinic.bffapigateway.utils.Security.Variables.Roles;
import lombok.*;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class RegisterInventoryManager {
private String userId;
private String email;
private String username;
@PasswordStrengthCheck
private String password;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
protected final String defaultRole = Roles.INVENTORY_MANAGER.toString();


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.petclinic.bffapigateway.dtos.Auth;


import com.fasterxml.jackson.annotation.JsonProperty;
import com.petclinic.bffapigateway.dtos.Vets.VetRequestDTO;
import com.petclinic.bffapigateway.utils.Security.Annotations.PasswordStrengthCheck;
import com.petclinic.bffapigateway.utils.Security.Variables.Roles;
Expand All @@ -17,6 +18,7 @@ public class RegisterVet {
private String userId;
private String email;
private String username;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private final String defaultRole = Roles.VET.toString();
@PasswordStrengthCheck
private String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class PetRequestDTO {
private String petTypeId;
//private String photoId;
private String isActive;

private String weight;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PetResponseDTO {
private String petTypeId;
//private String photoId;
private String isActive;

private String weight;

//private final List<VisitDetails> visits = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.petclinic.bffapigateway.dtos.Vets;

import lombok.*;
import org.springframework.core.io.Resource;

Check warning on line 4 in api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Vets/PhotoResponseDTO.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import org.springframework.core.io.Resource;`

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PhotoResponseDTO {
private String vetId;
private String filename;
private String imgType;
private String resourceBase64;
private byte[] resource;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class RatingRequestDTO {
private Double rateScore;
private String rateDescription;
private String rateDate;

private String ownerId;
private PredefinedDescription predefinedDescription;
}
Loading

0 comments on commit 227344a

Please sign in to comment.