io.rocketbase.commons.resource.AppUserResource Maven / Gradle / Ivy
package io.rocketbase.commons.resource;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.rocketbase.commons.adapters.JwtRestTemplate;
import io.rocketbase.commons.dto.PageableResult;
import io.rocketbase.commons.dto.appuser.AppUserCreate;
import io.rocketbase.commons.dto.appuser.AppUserRead;
import io.rocketbase.commons.dto.appuser.AppUserUpdate;
import io.rocketbase.commons.request.PageableRequest;
import lombok.SneakyThrows;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
public class AppUserResource implements BaseRestResource {
public static final String API_USER = "/api/user/";
protected JwtRestTemplate restTemplate;
public AppUserResource(JwtRestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
@SneakyThrows
public PageableResult find(int page, int pagesize) {
ResponseEntity> response = restTemplate.exchange(appendParams(restTemplate.getBaseAuthApiBuilder(),
new PageableRequest(page, pagesize, null))
.path(API_USER)
.toUriString(),
HttpMethod.GET,
new HttpEntity<>(createHeaderWithLanguage()),
createPagedTypeReference());
return response.getBody();
}
@SneakyThrows
public PageableResult find(PageableRequest request) {
ResponseEntity> response = restTemplate.exchange(appendParams(restTemplate.getBaseAuthApiBuilder(), request)
.path(API_USER)
.toUriString(),
HttpMethod.GET,
new HttpEntity<>(createHeaderWithLanguage()),
createPagedTypeReference());
return response.getBody();
}
@SneakyThrows
public AppUserRead create(AppUserCreate create) {
ResponseEntity response = restTemplate.exchange(restTemplate.getBaseAuthApiBuilder()
.path(API_USER)
.toUriString(),
HttpMethod.POST,
new HttpEntity<>(create, createHeaderWithLanguage()),
AppUserRead.class);
return response.getBody();
}
@SneakyThrows
public AppUserRead patch(String id, AppUserUpdate update) {
ResponseEntity response = restTemplate.exchange(restTemplate.getBaseAuthApiBuilder()
.path(API_USER)
.path(id)
.toUriString(),
HttpMethod.PATCH,
new HttpEntity<>(update, createHeaderWithLanguage()),
AppUserRead.class);
return response.getBody();
}
@SneakyThrows
public void delete(String id) {
restTemplate.exchange(restTemplate.getBaseAuthApiBuilder()
.path(API_USER)
.path(id)
.toUriString(),
HttpMethod.DELETE,
new HttpEntity<>(createHeaderWithLanguage()),
AppUserRead.class);
}
protected ParameterizedTypeReference> createPagedTypeReference() {
return new ParameterizedTypeReference>() {
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy