.
This commit is contained in:
@@ -18,6 +18,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import kz.konturai.parser.dto.PageResponse;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/parser/report")
|
||||
public class ReportController {
|
||||
@@ -44,7 +46,8 @@ public class ReportController {
|
||||
}
|
||||
|
||||
@GetMapping("/history")
|
||||
public ResponseEntity<Page<ReportHistory>> history(@RequestParam(name = "page", defaultValue = "0") int page,
|
||||
public ResponseEntity<PageResponse<ReportHistory>> history(
|
||||
@RequestParam(name = "page", defaultValue = "0") int page,
|
||||
@RequestParam(name = "size", defaultValue = "20") int size,
|
||||
@RequestParam(name = "sort", defaultValue = "createdAt,desc") String sort) {
|
||||
String[] parts = sort.split(",");
|
||||
@@ -53,7 +56,14 @@ public class ReportController {
|
||||
: Sort.Direction.DESC;
|
||||
Pageable pageable = PageRequest.of(page, size, Sort.by(dir, sortField));
|
||||
Page<ReportHistory> res = reportHistoryRepository.findAll(pageable);
|
||||
return ResponseEntity.ok(res);
|
||||
PageResponse<ReportHistory> dto = new PageResponse<>(
|
||||
res.getContent(),
|
||||
res.getNumber(),
|
||||
res.getSize(),
|
||||
res.getTotalElements(),
|
||||
res.getTotalPages(),
|
||||
sort);
|
||||
return ResponseEntity.ok(dto);
|
||||
}
|
||||
|
||||
@GetMapping("/history/{id}")
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package kz.konturai.parser.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PageResponse<T> {
|
||||
|
||||
private List<T> content;
|
||||
private int page;
|
||||
private int size;
|
||||
private long totalElements;
|
||||
private int totalPages;
|
||||
private String sort;
|
||||
|
||||
public PageResponse() {
|
||||
}
|
||||
|
||||
public PageResponse(List<T> content, int page, int size, long totalElements, int totalPages, String sort) {
|
||||
this.content = content;
|
||||
this.page = page;
|
||||
this.size = size;
|
||||
this.totalElements = totalElements;
|
||||
this.totalPages = totalPages;
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public List<T> getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(List<T> content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public long getTotalElements() {
|
||||
return totalElements;
|
||||
}
|
||||
|
||||
public void setTotalElements(long totalElements) {
|
||||
this.totalElements = totalElements;
|
||||
}
|
||||
|
||||
public int getTotalPages() {
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
public void setTotalPages(int totalPages) {
|
||||
this.totalPages = totalPages;
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(String sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
}
|
||||
@@ -180,10 +180,14 @@ public class ReportGenerationService {
|
||||
}
|
||||
|
||||
private String getCombinedSummaries(List<MarketItem> items) {
|
||||
return items.stream()
|
||||
String combined = items.stream()
|
||||
.map(i -> i.getAnalytics() != null ? i.getAnalytics().getSummary() : null)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining("\n\n"));
|
||||
if (combined.length() > 8000) {
|
||||
combined = combined.substring(0, 8000);
|
||||
}
|
||||
return combined;
|
||||
}
|
||||
|
||||
private String buildAnnotation(List<MarketItem> items) {
|
||||
|
||||
Reference in New Issue
Block a user