Back работает правильно
This commit is contained in:
parent
eeea0d4d3f
commit
1a35063891
@ -1,9 +1,6 @@
|
||||
package com.android.mobileappserver.Report;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/report")
|
||||
@ -14,8 +11,9 @@ public class ReportController {
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
@PostMapping("/createReport")
|
||||
public ReportDTO createReport(@RequestBody ReportCreateDTO reportCreateDTO){
|
||||
return reportService.createReport(reportCreateDTO);
|
||||
@GetMapping("/createReport/{dateFrom}/{dateTo}")
|
||||
public ReportDTO createReport(@PathVariable("dateFrom") Long dateFrom,
|
||||
@PathVariable("dateTo") Long dateTo){
|
||||
return reportService.createReport(dateFrom, dateTo);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
package com.android.mobileappserver.Report;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ReportCreateDTO {
|
||||
private Long dateFrom;
|
||||
private Long dateTo;
|
||||
}
|
@ -3,6 +3,7 @@ package com.android.mobileappserver.Report;
|
||||
import com.android.mobileappserver.Story.StoryModel;
|
||||
import com.android.mobileappserver.Story.StoryService;
|
||||
import com.android.mobileappserver.User.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -10,6 +11,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ReportService {
|
||||
private final UserService userService;
|
||||
private final StoryService storyService;
|
||||
@ -20,8 +22,8 @@ public class ReportService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ReportDTO createReport(ReportCreateDTO reportCreateDTO){
|
||||
List<StoryModel> stories = storyService.getStoriesByDate(reportCreateDTO.getDateFrom(), reportCreateDTO.getDateTo());
|
||||
public ReportDTO createReport(Long dateFrom, Long dateTo){
|
||||
List<StoryModel> stories = storyService.getStoriesByDate(dateFrom, dateTo);
|
||||
int postCount = stories.size();
|
||||
Map<String, Integer> authorWithCount = new HashMap<>();
|
||||
for (var story: stories) {
|
||||
@ -35,7 +37,7 @@ public class ReportService {
|
||||
}
|
||||
}
|
||||
Map.Entry<String, Integer> maxEntry = Collections.max(authorWithCount.entrySet(), Map.Entry.comparingByValue());
|
||||
return new ReportDTO(reportCreateDTO.getDateFrom(), reportCreateDTO.getDateTo(),
|
||||
return new ReportDTO(dateFrom, dateTo,
|
||||
postCount, maxEntry.getKey(), maxEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,6 @@ import java.util.List;
|
||||
public interface StoryRepository extends JpaRepository<StoryModel, Long> {
|
||||
Page<StoryModel> findAllByUserId(Long userIdб, Pageable pageable);
|
||||
|
||||
@Query("SELECT s FROM _story s WHERE s.dateFrom = :dateFrom AND s.dateTo = :dateTo")
|
||||
@Query("SELECT s FROM StoryModel s WHERE s.postdate >= :dateFrom AND s.postdate <= :dateTo")
|
||||
List<StoryModel> findStoriesBetweenDates(@Param("dateFrom") Long dateFrom, @Param("dateTo") Long dateTo);
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.android.mobileappserver.User;
|
||||
|
||||
import com.android.mobileappserver.Story.StoryModel;
|
||||
import com.android.mobileappserver.Story.StoryNotFoundException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user