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: added ability to search consultants and admins by id #667

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/useradminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ paths:
parameters:
- name: query
in: query
description: URL-encoded infix to search for in first name, last name, or email.
description: URL-encoded infix to search for in id first name, last name, or email.
A non-encoded star symbol searches for all.
required: true
schema:
Expand Down
2 changes: 1 addition & 1 deletion api/userservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ paths:
parameters:
- name: query
in: query
description: URL-encoded infix to search for in first name, last name, or email.
description: URL-encoded infix to search for in id, first name, last name, or email.
A non-encoded star symbol searches for all.
required: true
schema:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand All @@ -43,18 +44,21 @@
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ApiResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {

private static final String BAD_REQUEST = "Bad Request: ";
private static final String USER_SERVICE_API_LOG_PLACEHOLDER = "UserService API: {}: {}";

@ExceptionHandler({DataIntegrityViolationException.class})
public ResponseEntity<Object> handleJPAConstraintViolationException(
final org.hibernate.exception.ConstraintViolationException ex, final WebRequest request) {
log.error("Bad Request: ", ex);
log.error(BAD_REQUEST, ex);

return handleExceptionInternal(ex, null, new HttpHeaders(), HttpStatus.CONFLICT, request);
}

@ExceptionHandler({CreateEnquiryMessageException.class})
public ResponseEntity<Object> handleCreateEnquiryMessageException(
final CreateEnquiryMessageException ex, final WebRequest request) {
log.error("Bad Request: ", ex);
log.error(BAD_REQUEST, ex);

return handleExceptionInternal(ex, null, new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}
Expand All @@ -68,7 +72,7 @@ public ResponseEntity<Object> handleCreateEnquiryMessageException(
@ExceptionHandler({BadRequestException.class})
public ResponseEntity<Object> handleCustomBadRequest(
final BadRequestException ex, final WebRequest request) {
log.warn("Bad Request: ", ex);
log.warn(BAD_REQUEST, ex);

return handleExceptionInternal(ex, null, new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}
Expand Down Expand Up @@ -113,7 +117,7 @@ protected ResponseEntity<Object> handleHttpMessageNotReadable(
final HttpHeaders headers,
final HttpStatus status,
final WebRequest request) {
log.warn("UserService API: {}: {}", status.getReasonPhrase(), ex.getStackTrace());
log.warn(USER_SERVICE_API_LOG_PLACEHOLDER, status.getReasonPhrase(), ex.getStackTrace());

return handleExceptionInternal(null, null, headers, status, request);
}
Expand All @@ -130,7 +134,7 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
final HttpHeaders headers,
final HttpStatus status,
final WebRequest request) {
log.warn("UserService API: {}: {}", status.getReasonPhrase(), ex.getStackTrace());
log.warn(USER_SERVICE_API_LOG_PLACEHOLDER, status.getReasonPhrase(), ex);

return handleExceptionInternal(null, null, headers, status, request);
}
Expand Down Expand Up @@ -159,7 +163,7 @@ public ResponseEntity<Object> handleUnauthorized(
@ExceptionHandler({InvalidDataAccessApiUsageException.class})
protected ResponseEntity<Object> handleConflict(
final RuntimeException ex, final WebRequest request) {
log.warn("UserService API: {}: {}", HttpStatus.CONFLICT, ex.getStackTrace());
log.warn(USER_SERVICE_API_LOG_PLACEHOLDER, HttpStatus.CONFLICT, ex.getStackTrace());

return handleExceptionInternal(null, null, new HttpHeaders(), HttpStatus.CONFLICT, request);
}
Expand Down Expand Up @@ -256,4 +260,18 @@ public ResponseEntity<Object> handleInternal(
final NoContentException ex, final WebRequest request) {
return handleExceptionInternal(null, null, new HttpHeaders(), HttpStatus.NO_CONTENT, request);
}

@Override
protected ResponseEntity<Object> handleExceptionInternal(
@Nullable Exception ex,
@Nullable Object body,
HttpHeaders headers,
HttpStatus status,
WebRequest request) {
if (HttpStatus.INTERNAL_SERVER_ERROR.equals(status)) {
request.setAttribute("javax.servlet.error.exception", ex, 0);
}

return new ResponseEntity<>(body, headers, status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public interface AdminRepository extends CrudRepository<Admin, String> {
+ "AND ("
+ " ?1 = '*' "
+ " OR ("
+ " UPPER(a.firstName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " UPPER(a.id) = UPPER(?1)"
+ " OR UPPER(a.firstName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " OR UPPER(a.lastName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " OR UPPER(a.email) LIKE CONCAT('%', UPPER(?1), '%')"
+ " OR CONVERT(a.tenantId,char) LIKE CONCAT('%', UPPER(?1), '%')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public interface ConsultantRepository extends CrudRepository<Consultant, String>
+ "WHERE"
+ " ?1 = '*' "
+ " OR ("
+ " UPPER(c.firstName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " UPPER(c.id) = UPPER(?1)"
+ " OR UPPER(c.firstName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " OR UPPER(c.lastName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " OR UPPER(c.email) LIKE CONCAT('%', UPPER(?1), '%')"
+ " )")
Expand All @@ -52,7 +53,8 @@ public interface ConsultantRepository extends CrudRepository<Consultant, String>
+ " AND ("
+ " ?1 = '*' "
+ " OR ("
+ " UPPER(c.firstName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " UPPER(c.id) = UPPER(?1)"
+ " OR UPPER(c.firstName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " OR UPPER(c.lastName) LIKE CONCAT('%', UPPER(?1), '%')"
+ " OR UPPER(c.email) LIKE CONCAT('%', UPPER(?1), '%')"
+ " )"
Expand Down
Loading