Skip to content

Commit

Permalink
Fixing stats restitution
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven authored and goulven committed Dec 9, 2024
1 parent 73e095f commit 6ad3747
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

package org.open4goods.api.controller.api;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.open4goods.api.services.VerticalsGenerationService;
import org.open4goods.commons.model.constants.RolesConstants;
import org.open4goods.commons.services.BrandService;
import org.open4goods.commons.services.VerticalsConfigService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -36,19 +32,15 @@ public BrandController(BrandService brandService) {

@GetMapping("/brands/stats/companies/missing")
@PreAuthorize("hasAuthority('" + RolesConstants.ROLE_XWIKI_ALL + "')")
public LinkedHashMap<String,String> statsMissingCompanies(HttpServletRequest request) {
public List<String> statsMissingCompanies(HttpServletRequest request) {
// Fetch the stats map
Map<String, Long> stats = brandService.getMissCounter();

// Sort the map by value in descending order
return stats.entrySet().stream()
.sorted(Map.Entry.<String, Long>comparingByValue().reversed())
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> "", // Replace the value with an empty string
(e1, e2) -> e1, // In case of duplicates, keep the first one
LinkedHashMap::new // Maintain the order
));
.map(e->e.getKey())
.toList();

}
}

0 comments on commit 6ad3747

Please sign in to comment.