Skip to content

Commit

Permalink
Revert "Front-end perms and back-end content for exceptions of owners" (
Browse files Browse the repository at this point in the history
#600)

Reverts #597
  • Loading branch information
DylanBrass authored Oct 24, 2023
1 parent 584ab41 commit 9642e30
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;

Check warning on line 8 in api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalExceptionHandler.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import org.springframework.web.bind.MethodArgumentNotValidException;`
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand All @@ -17,8 +16,6 @@
import java.util.HashMap;
import java.util.Map;

import static org.springframework.http.HttpStatus.NOT_FOUND;


/**
* Created by IntelliJ IDEA.
Expand Down Expand Up @@ -132,13 +129,4 @@ public ResponseEntity<HttpErrorInfo> handleForbiddenAccessException(ForbiddenAcc
.body(new HttpErrorInfo(HttpStatus.FORBIDDEN.value(),ex.getMessage()));
}

//I have no idea why but this method kills docker and specifically
//the api gateway as a service crashes on docker if you have this uncommented
// @ExceptionHandler(value = NotFoundException.class)
// public ResponseEntity<HttpErrorInfo> handleNotFoundException(NotFoundException ex) {
// return ResponseEntity.status(NOT_FOUND)
// .body(new HttpErrorInfo(NOT_FOUND.value(),ex.getMessage()));
//
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ else if(exClass.equals(NullPointerException.class)){
}
else if(exClass.equals(ForbiddenAccessException.class)){
status = HttpStatus.FORBIDDEN;

}
else if(exClass.equals(NotFoundException.class)){
status = HttpStatus.NOT_FOUND;
}// Handle any other exception types here
} // Handle any other exception types here
else {
log.error("Exception not handled: {}", exClass.getSimpleName());
status = HttpStatus.UNPROCESSABLE_ENTITY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO;
import com.petclinic.bffapigateway.dtos.Pets.*;
import com.petclinic.bffapigateway.dtos.Vets.PhotoDetails;
import com.petclinic.bffapigateway.exceptions.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

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

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused import

Unused import `import org.springframework.web.bind.annotation.RequestParam;`
Expand Down Expand Up @@ -44,16 +41,6 @@ public Mono<OwnerResponseDTO> getOwner(final String ownerId) {
return webClientBuilder.build().get()
.uri(customersServiceUrl + "/owners/" + ownerId)
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, error->{
HttpStatusCode statusCode = error.statusCode();

if (statusCode.equals(HttpStatus.NOT_FOUND))
return Mono.error(new NotFoundException("Course id not found:" + ownerId));
return Mono.error(new IllegalArgumentException("Something went wrong(owner Client)"));
})
.onStatus(HttpStatusCode::is5xxServerError, error-> {
return Mono.error(new IllegalArgumentException("Something went wrong(owner Client"));
})
.bodyToMono(OwnerResponseDTO.class);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,12 @@ public Mono<ResponseEntity<OwnerResponseDTO>> updateOwner(
}








@SecuredEndpoint(allowedRoles = {Roles.ADMIN})
@DeleteMapping(value = "owners/{ownerId}")
public Mono<ResponseEntity<OwnerResponseDTO>> deleteOwner(@PathVariable String ownerId){
Expand Down
25 changes: 4 additions & 21 deletions api-gateway/src/main/resources/static/scripts/fragments/nav.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
<script>

function purgeUser() {
localStorage.removeItem("username")
localStorage.removeItem("email")
localStorage.removeItem("UUID")
localStorage.removeItem("roles")
}

//access the roles title and make sure it exists
const userRoles = localStorage.getItem('roles')
console.log(userRoles);

function logoutUser() {
logoutUser.$inject = ['$http'];
var $http = angular.injector(['ng']).get('$http');
Expand All @@ -32,7 +20,6 @@
localStorage.removeItem("roles")
window.location.href = '/#!/login';
}); }

</script>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
Expand All @@ -55,22 +42,16 @@
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="nav-link" ui-sref="owners">Owners</a>

<a class="nav-link" ui-sref="ownerDetails({ ownerId: UUID })" ng-if = "roles == 'OWNER'" >Edit Account</a>

<a class="nav-link" ui-sref="ownerDetails({ ownerId: UUID })">Edit Account</a>
<a class="nav-link" ui-sref="petTypes">Pet Types</a>

</div>
</li>
<li class="nav-item" ng-if = "roles !== 'OWNER'">
<li class="nav-item">
<a class="nav-link" ui-sref="bills">Bills</a>
</li>

<li class="nav-item" ng-if = "roles !== 'OWNER'">
<li class="nav-item">
<a class="nav-link" ui-sref="visitList">Visits</a>
</li>

<li class="nav-item">
<a class="nav-link" ui-sref="inventories">Inventory</a>
</li>
Expand All @@ -94,5 +75,7 @@
<a class="nav-link" ui-sref="login">Login</a>
</li>
</ul>


</div>
</nav>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ angular.module('ownerDetails', ['ui.router'])
// params: {ownerId: null, petId: null},
// template: '<owner-details></owner-details>'
// }

}]);


Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ angular.module('vetList')
$http.get('api/gateway/vets/' + vet.vetId + "/ratings/average").then(function (resp) {
console.log(resp.data);
vet.showRating = true;
vet.rating = parseFloat(resp.data).toFixed(1);
vet.rating = parseFloat(resp.data.toFixed(1));
});
}

function getTopThreeVetsWithHighestRating(vet){
$http.get('api/gateway/vets/topVets').then(function (resp) {
console.log(resp.data);
vet.showRating=true;
vet.rating = parseFloat(resp.data).toFixed(1);
vet.rating = parseFloat(resp.data.toFixed(1));

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ <h2>Veterinarians</h2>
</form>


<a ng-if = "roles !== 'OWNER'" ui-sref="vetsNew" style="float: right;margin-bottom: 1%">
<button ng-if = "roles !== 'OWNER'" class="add-vet-button btn btn-success">Add Vet</button>
</a>


<div style="margin-bottom: 1%; margin-top: 1%">
<label for="filterOption">Filter</label>
Expand All @@ -45,7 +41,7 @@ <h2>Veterinarians</h2>
<th class="vet_speciality">Specialties</th>
<th class="getAverageRating">Average Rating</th>
<th class="getCountOfRatings">Number of Ratings</th>
<th ng-if = "roles !== 'OWNER'" >Delete</th>
<th>Delete</th>
</tr>
</thead>

Expand All @@ -60,9 +56,14 @@ <h2>Veterinarians</h2>
<td class="vet_speciality"><span ng-repeat="specialty in vet.specialties">{{specialty.name + ' '}}</span></td>
<td class="vet-rating v{{vet.vetId}} centered-count"><span>{{vet.rating}}</span></td>
<td class="vet-rating v{{vet.vetId}} centered-count"><span>{{vet.count}}</span></td>
<td ng-if = "roles !== 'OWNER'" ><a class="btn btn-danger" href="javascript:void(0)" ng-click="deleteVet(vet.vetId)" >Delete Vet</a></td>
<td><a class="btn btn-danger" href="javascript:void(0)" ng-click="deleteVet(vet.vetId)">Delete Vet</a></td>
</tr>






<div class="modal m{{vet.vetId}} modalOff" ng-repeat="vet in $ctrl.vetList" >
<span class="modal_image"><img ng-if="vet.image != null" src="data:image/png;base64,{{vet.image}}"/><img
ng-if="vet.image == null" src="images/vet_default.jpg"/></span>
Expand Down

0 comments on commit 9642e30

Please sign in to comment.