Skip to content

Commit 1ba63f7

Browse files
committed
fix: cleanup
1 parent 8618e0b commit 1ba63f7

File tree

3 files changed

+6
-28
lines changed

3 files changed

+6
-28
lines changed

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

+2-21
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import java.util.List;
1616
import java.util.stream.Collectors;
17-
import java.util.stream.Stream;
1817

1918
import org.slf4j.Logger;
2019
import org.slf4j.LoggerFactory;
@@ -40,9 +39,6 @@ public class CompanySiteController {
4039
private final CompanySiteService companySiteService;
4140
private final EntityDtoMapper entityDtoMapper;
4241

43-
private record Selections(boolean withPolygons, boolean withRings, boolean withLocations) {
44-
}
45-
4642
public CompanySiteController(CompanySiteService companySiteService, EntityDtoMapper entityDtoMapper) {
4743
this.companySiteService = companySiteService;
4844
this.entityDtoMapper = entityDtoMapper;
@@ -51,31 +47,16 @@ public CompanySiteController(CompanySiteService companySiteService, EntityDtoMap
5147
@QueryMapping
5248
public List<CompanySiteDto> getCompanySiteByTitle(@Argument("title") String title, @Argument("year") Long year,
5349
DataFetchingEnvironment dataFetchingEnvironment) {
54-
Selections selections = createSelections(dataFetchingEnvironment);
5550
List<CompanySiteDto> companySiteDtos = this.companySiteService
56-
.findCompanySiteByTitleAndYear(title, year, selections.withPolygons(), selections.withRings(),
57-
selections.withLocations())
51+
.findCompanySiteByTitleAndYear(title, year)
5852
.stream().map(this.entityDtoMapper::mapToDto).collect(Collectors.toList());
5953
return companySiteDtos;
6054
}
6155

62-
private Selections createSelections(DataFetchingEnvironment dataFetchingEnvironment) {
63-
boolean addPolygons = dataFetchingEnvironment.getSelectionSet().contains("polygons");
64-
boolean addRings = dataFetchingEnvironment.getSelectionSet().getFields().stream()
65-
.anyMatch(sf -> "rings".equalsIgnoreCase(sf.getName()));
66-
boolean addLocations = dataFetchingEnvironment.getSelectionSet().getFields().stream()
67-
.filter(sf -> "rings".equalsIgnoreCase(sf.getName())).flatMap(sf -> Stream.of(sf.getSelectionSet()))
68-
.anyMatch(sf -> sf.contains("locations"));
69-
Selections selections = new Selections(addPolygons, addRings, addLocations);
70-
return selections;
71-
}
72-
7356
@QueryMapping
7457
public CompanySiteDto getCompanySiteById(@Argument("id") Long id, DataFetchingEnvironment dataFetchingEnvironment) {
75-
Selections selections = createSelections(dataFetchingEnvironment);
7658
return this.companySiteService
77-
.findCompanySiteByIdDetached(id, selections.withPolygons(), selections.withRings(),
78-
selections.withLocations())
59+
.findCompanySiteByIdDetached(id)
7960
.stream().map(this.entityDtoMapper::mapToDto).findFirst()
8061
.orElseThrow(() -> new ResourceNotFoundException(String.format("No CompanySite found for id: %d", id)));
8162
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public CompanySiteService(CompanySiteRepository companySiteRepository, PolygonRe
5858
this.entityManager = entityManager;
5959
}
6060

61-
public Collection<CompanySite> findCompanySiteByTitleAndYear(String title, Long year, boolean withPolygons,
62-
boolean withRings, boolean withLocations) {
61+
public Collection<CompanySite> findCompanySiteByTitleAndYear(String title, Long year) {
6362
if (title == null || title.length() < 2 || year == null) {
6463
return List.of();
6564
}
@@ -76,8 +75,7 @@ public Optional<CompanySite> findCompanySiteById(Long id) {
7675
.findFirst();
7776
}
7877

79-
public Optional<CompanySite> findCompanySiteByIdDetached(Long id, boolean withPolygons, boolean withRings,
80-
boolean withLocations) {
78+
public Optional<CompanySite> findCompanySiteByIdDetached(Long id) {
8179
return Optional.ofNullable(id).flatMap(myId -> this.companySiteRepository.findById(myId)).stream()
8280
.findFirst();
8381
}

backend/src/test/java/ch/xxx/maps/adapter/controller/CompanySiteControllerTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
import static org.junit.jupiter.api.Assertions.assertEquals;
1616
import static org.mockito.ArgumentMatchers.any;
17-
import static org.mockito.ArgumentMatchers.anyBoolean;
1817

1918
import java.math.BigDecimal;
2019
import java.time.LocalDate;
2120
import java.util.Optional;
2221
import java.util.Set;
2322

2423
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525
import org.mockito.Mockito;
2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureGraphQlTester;
@@ -58,8 +58,7 @@ public void init() {
5858

5959
// @Test
6060
public void getCompanySiteByIdFound() throws Exception {
61-
Mockito.when(this.companySiteService.findCompanySiteByIdDetached(any(Long.class), anyBoolean(), anyBoolean(),
62-
anyBoolean())).thenReturn(Optional.of(this.createCompanySiteEntity()));
61+
Mockito.when(this.companySiteService.findCompanySiteByIdDetached(any(Long.class))).thenReturn(Optional.of(this.createCompanySiteEntity()));
6362
String myDocument = "{ getCompanySiteById(id:1) \n" + " { id, title, atDate, \n"
6463
+ " polygons { id, fillColor, borderColor, title, longitude, latitude,\n"
6564
+ " rings{ id, primaryRing,\n" + " locations { id, longitude, latitude}}}}}";

0 commit comments

Comments
 (0)