Skip to content

Commit

Permalink
Fix paging in history
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Apr 6, 2024
1 parent 3def95a commit 802979c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/org/nzbhydra/historystats/HistoryWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.security.access.annotation.Secured;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -38,7 +39,7 @@ public Page<SearchEntityTO> searchHistory(@RequestBody HistoryRequest requestDat
final List<SearchEntityTO> searchEntityTOS = page.getContent().stream()
.map(x -> Jackson.JSON_MAPPER.convertValue(x, SearchEntityTO.class))
.toList();
return new PageImpl<>(searchEntityTOS);
return new PageImpl<>(searchEntityTOS, Pageable.ofSize(page.getTotalPages()), page.getTotalElements());
}

@Secured({"ROLE_STATS"})
Expand All @@ -65,7 +66,7 @@ public Page<FileDownloadEntityTO> downloadHistory(@RequestBody HistoryRequest re
.stream()
.map(x -> Jackson.JSON_MAPPER.convertValue(x, FileDownloadEntityTO.class))
.toList();
return new PageImpl<>(downloadEntityTOS);
return new PageImpl<>(downloadEntityTOS, Pageable.ofSize(page.getTotalPages()), page.getTotalElements());
}

@Secured({"ROLE_STATS"})
Expand All @@ -77,7 +78,7 @@ public Page<NotificationEntityTO> notificationHistory(@RequestBody HistoryReques
.stream()
.map(x -> Jackson.JSON_MAPPER.convertValue(x, NotificationEntityTO.class))
.toList();
return new PageImpl<>(tos);
return new PageImpl<>(tos, Pageable.ofSize(page.getTotalPages()), page.getTotalElements());
}

}
31 changes: 13 additions & 18 deletions core/src/main/java/org/nzbhydra/web/WebConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
Expand All @@ -26,15 +25,11 @@
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.resource.ResourceUrlProvider;

import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -88,19 +83,19 @@ protected void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseTrailingSlashMatch(true);
}

@Override
protected void addCorsMappings(CorsRegistry registry) {
//registry.addMapping("/**").allowedOrigins("http://127.0.0.1:5076", "https://127.0.0.1:9091");
//Later: Check when actually calling from other host, seems to work on server
}

@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping(ContentNegotiationManager mvcContentNegotiationManager,
FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) {
RequestMappingHandlerMapping handler = super.requestMappingHandlerMapping(mvcContentNegotiationManager, mvcConversionService, mvcResourceUrlProvider);
handler.setOrder(1);
return handler;
}
// @Override
// protected void addCorsMappings(CorsRegistry registry) {
// //registry.addMapping("/**").allowedOrigins("http://127.0.0.1:5076", "https://127.0.0.1:9091");
// //Later: Check when actually calling from other host, seems to work on server
// }
//
// @Bean
// public RequestMappingHandlerMapping requestMappingHandlerMapping(ContentNegotiationManager mvcContentNegotiationManager,
// FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) {
// RequestMappingHandlerMapping handler = super.requestMappingHandlerMapping(mvcContentNegotiationManager, mvcConversionService, mvcResourceUrlProvider);
// handler.setOrder(1);
// return handler;
// }

@Bean
public FilterRegistrationBean filterRegistrationBean() {
Expand Down

0 comments on commit 802979c

Please sign in to comment.