Skip to content

Commit a4359af

Browse files
committed
fix: location order
1 parent 63871b7 commit a4359af

File tree

2 files changed

+3
-41
lines changed

2 files changed

+3
-41
lines changed

backend/src/main/java/ch/xxx/maps/adapter/controller/CompanySiteController.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.slf4j.Logger;
2020
import org.slf4j.LoggerFactory;
21-
import org.springframework.context.ApplicationContext;
2221
import org.springframework.graphql.data.method.annotation.Argument;
2322
import org.springframework.graphql.data.method.annotation.BatchMapping;
2423
import org.springframework.graphql.data.method.annotation.MutationMapping;
@@ -31,30 +30,22 @@
3130
import ch.xxx.maps.domain.model.dto.PolygonDto;
3231
import ch.xxx.maps.domain.model.dto.RingDto;
3332
import ch.xxx.maps.domain.model.entity.CompanySite;
34-
import ch.xxx.maps.domain.model.entity.CompanySiteRepository;
35-
import ch.xxx.maps.domain.model.entity.LocationRepository;
36-
import ch.xxx.maps.domain.model.entity.PolygonRepository;
37-
import ch.xxx.maps.domain.model.entity.RingRepository;
3833
import ch.xxx.maps.usecase.mapper.EntityDtoMapper;
3934
import ch.xxx.maps.usecase.service.CompanySiteService;
4035
import graphql.schema.DataFetchingEnvironment;
41-
import jakarta.persistence.EntityManager;
4236

4337
@Controller
4438
public class CompanySiteController {
4539
private static final Logger LOGGER = LoggerFactory.getLogger(CompanySite.class);
4640
private final CompanySiteService companySiteService;
4741
private final EntityDtoMapper entityDtoMapper;
48-
private final ApplicationContext applicationContext;
4942

5043
private record Selections(boolean withPolygons, boolean withRings, boolean withLocations) {
5144
}
5245

53-
public CompanySiteController(CompanySiteService companySiteService, EntityDtoMapper entityDtoMapper,
54-
ApplicationContext applicationContext) {
46+
public CompanySiteController(CompanySiteService companySiteService, EntityDtoMapper entityDtoMapper) {
5547
this.companySiteService = companySiteService;
5648
this.entityDtoMapper = entityDtoMapper;
57-
this.applicationContext = applicationContext;
5849
}
5950

6051
@QueryMapping

backend/src/main/java/ch/xxx/maps/usecase/service/CompanySiteService.java

+2-31
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,6 @@ public Collection<CompanySite> findCompanySiteByTitleAndYear(String title, Long
6868
title = title.trim().toLowerCase();
6969
List<CompanySite> companySites = this.companySiteRepository.findByTitleFromTo(title, beginOfYear, endOfYear)
7070
.stream().peek(this.entityManager::detach).toList();
71-
// companySites = addEntities(withPolygons, withRings, withLocations, companySites);
72-
return companySites;
73-
}
74-
75-
76-
77-
private List<CompanySite> addEntities(boolean withPolygons, boolean withRings, boolean withLocations,
78-
List<CompanySite> companySites) {
79-
if (withPolygons) {
80-
Map<Long, List<Polygon>> fetchPolygons = this.fetchPolygonEntitys(companySites);
81-
Map<Long, List<Ring>> fetchRings = !withRings ? Map.of()
82-
: this.fetchRings(fetchPolygons.values().stream().flatMap(List::stream).toList());
83-
Map<Long, List<Location>> fetchLocations = !withLocations ? Map.of()
84-
: this.fetchLocations(fetchRings.values().stream().flatMap(List::stream).toList());
85-
companySites.forEach(myCompanySite -> {
86-
myCompanySite.setPolygons(new HashSet<>(fetchPolygons.getOrDefault(myCompanySite.getId(), List.of())));
87-
if (withRings) {
88-
myCompanySite.getPolygons().forEach(myPolygon -> {
89-
myPolygon.setRings(new HashSet<>(fetchRings.getOrDefault(myPolygon.getId(), List.of())));
90-
if (withLocations) {
91-
myPolygon.getRings().forEach(myRing -> {
92-
myRing.setLocations(
93-
new HashSet<>(fetchLocations.getOrDefault(myRing.getId(), List.of())));
94-
});
95-
}
96-
});
97-
}
98-
});
99-
}
10071
return companySites;
10172
}
10273

@@ -108,7 +79,6 @@ public Optional<CompanySite> findCompanySiteById(Long id) {
10879
public Optional<CompanySite> findCompanySiteByIdDetached(Long id, boolean withPolygons, boolean withRings,
10980
boolean withLocations) {
11081
return Optional.ofNullable(id).flatMap(myId -> this.companySiteRepository.findById(myId)).stream()
111-
// .peek(myCompanySite -> this.addEntities(withPolygons, withRings, withLocations, List.of(myCompanySite)))
11282
.findFirst();
11383
}
11484

@@ -208,7 +178,7 @@ public LinkedHashMap<RingDto, List<Location>> fetchLocationDtos(List<RingDto> ri
208178
.findAllByRingIds(ringDtos.stream().map(RingDto::getId).collect(Collectors.toList())).stream()
209179
.peek(this.entityManager::detach).toList();
210180
return ringDtos.stream()
211-
.map(myRi -> Map.entry(myRi, findLocations(locations, myRi.getId())))
181+
.map(myRi -> Map.entry(myRi, findLocations(locations, myRi.getId())))
212182
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> {throw new RuntimeException();}, LinkedHashMap::new));
213183
}
214184

@@ -236,6 +206,7 @@ public Map<Long, List<Location>> fetchLocations(List<Ring> rings) {
236206

237207
private List<Location> findLocations(List<Location> locations, Long myRiId) {
238208
return locations.stream().filter(myLocation -> myLocation.getRing().getId().equals(myRiId))
209+
.sorted((a,b) -> a.getOrderId().compareTo(b.getOrderId()))
239210
.collect(Collectors.toList());
240211
}
241212
}

0 commit comments

Comments
 (0)