-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
963 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...mplate-adapter/src/main/java/fr/ouestfrance/querydsl/postgrest/ParametrizedTypeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fr.ouestfrance.querydsl.postgrest; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.commons.lang3.reflect.TypeUtils; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Type Utilities | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class ParametrizedTypeUtils { | ||
|
||
/** | ||
* Create parametrized type of List of T | ||
* | ||
* @param clazz class of T | ||
* @param <T> type of parametrized list | ||
* @return parametrized type | ||
*/ | ||
public static <T> ParameterizedTypeReference<List<T>> listRef(Class<T> clazz) { | ||
return ParameterizedTypeReference.forType(TypeUtils.parameterize(List.class, clazz)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...t-resttemplate-adapter/src/main/java/fr/ouestfrance/querydsl/postgrest/ResponseUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fr.ouestfrance.querydsl.postgrest; | ||
|
||
import fr.ouestfrance.querydsl.postgrest.model.BulkResponse; | ||
import fr.ouestfrance.querydsl.postgrest.model.Range; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Utility class that helps to transform response | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class ResponseUtils { | ||
|
||
/** | ||
* Transform a ResponseEntity of list to bulkResponse | ||
* | ||
* @param response response entity | ||
* @param <T> Type of response | ||
* @return BulkResponse | ||
*/ | ||
public static <T> BulkResponse<T> toBulkResponse(ResponseEntity<List<T>> response) { | ||
return Optional.ofNullable(response) | ||
.map(x -> { | ||
Optional<Range> count = getCount(x.getHeaders()); | ||
return new BulkResponse<>(x.getBody(), count.map(Range::getCount).orElse(0L), count.map(Range::getTotalElements).orElse(0L)); | ||
}) | ||
.orElse(new BulkResponse<>(List.of(), 0L, 0L)); | ||
} | ||
|
||
/** | ||
* Extract Range headers | ||
* | ||
* @param headers headers where Content-Range is | ||
* @return range object | ||
*/ | ||
public static Optional<Range> getCount(HttpHeaders headers) { | ||
return Optional.ofNullable(headers.get("Content-Range")) | ||
.flatMap(x -> x.stream().findFirst()) | ||
.map(Range::of); | ||
} | ||
} |
Oops, something went wrong.