Skip to content

Instantly share code, notes, and snippets.

View Raouf25's full-sized avatar

ABDERRAOUF MAKHLOUF Raouf25

View GitHub Profile
public class ClientUnavailableException extends BackendException {
public ClientUnavailableException(String message) {
super(ErrorEnum.CLIENT_UNAVAILABLE_ERROR, "%s is unavailable", message);
}
}
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
@Getter
@RequiredArgsConstructor
public enum ErrorEnum {
CLIENT_UNAVAILABLE_ERROR("Service unavailable.", HttpStatus.BAD_REQUEST),
RESOURCE_NOT_FOUND("Resource not found.", HttpStatus.NOT_FOUND);
private final String message;
public class ResourceNotFoundException extends BackendException {
public ResourceNotFoundException(Integer id, String message) {
super(ErrorEnum.RESOURCE_NOT_FOUND, "%s id = %s not found", message, id);
}
}
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.List;
@Getter
@Setter
@Slf4j
<dependency>
<groupId>com.pivovarit</groupId>
<artifactId>throwing-function</artifactId>
<version>1.5.0</version>
</dependency>
package com.mak.springbootefficientsearchapi.configuration;
import net.kaczmarzyk.spring.data.jpa.web.SpecificationArgumentResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
<dependency>
<groupId>net.kaczmarzyk</groupId>
<artifactId>specification-arg-resolver</artifactId>
<version>2.1.1</version>
</dependency>
/**
* get element using Criteria.
*
* @param spec *
* @param headers pagination data
* @param sort sort criteria
* @return retrieve elements with pagination
*/
public PagingResponse get(Specification<Car> spec, HttpHeaders headers, Sort sort) {
if (isRequestPaged(headers)) {
@Transactional
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<List<Car>> get(
@And({
@Spec(path = "manufacturer", params = "manufacturer", spec = Like.class),
@Spec(path = "model", params = "model", spec = Like.class),
@Spec(path = "country", params = "country", spec = In.class),
@Spec(path = "type", params = "type", spec = Like.class),
@Spec(path = "createDate", params = "createDate", spec = Equal.class),
package com.mak.springbootefficientsearchapi.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;