14
14
15
15
import java .util .List ;
16
16
import java .util .stream .Collectors ;
17
- import java .util .stream .Stream ;
18
17
19
18
import org .slf4j .Logger ;
20
19
import org .slf4j .LoggerFactory ;
@@ -40,9 +39,6 @@ public class CompanySiteController {
40
39
private final CompanySiteService companySiteService ;
41
40
private final EntityDtoMapper entityDtoMapper ;
42
41
43
- private record Selections (boolean withPolygons , boolean withRings , boolean withLocations ) {
44
- }
45
-
46
42
public CompanySiteController (CompanySiteService companySiteService , EntityDtoMapper entityDtoMapper ) {
47
43
this .companySiteService = companySiteService ;
48
44
this .entityDtoMapper = entityDtoMapper ;
@@ -51,31 +47,16 @@ public CompanySiteController(CompanySiteService companySiteService, EntityDtoMap
51
47
@ QueryMapping
52
48
public List <CompanySiteDto > getCompanySiteByTitle (@ Argument ("title" ) String title , @ Argument ("year" ) Long year ,
53
49
DataFetchingEnvironment dataFetchingEnvironment ) {
54
- Selections selections = createSelections (dataFetchingEnvironment );
55
50
List <CompanySiteDto > companySiteDtos = this .companySiteService
56
- .findCompanySiteByTitleAndYear (title , year , selections .withPolygons (), selections .withRings (),
57
- selections .withLocations ())
51
+ .findCompanySiteByTitleAndYear (title , year )
58
52
.stream ().map (this .entityDtoMapper ::mapToDto ).collect (Collectors .toList ());
59
53
return companySiteDtos ;
60
54
}
61
55
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
-
73
56
@ QueryMapping
74
57
public CompanySiteDto getCompanySiteById (@ Argument ("id" ) Long id , DataFetchingEnvironment dataFetchingEnvironment ) {
75
- Selections selections = createSelections (dataFetchingEnvironment );
76
58
return this .companySiteService
77
- .findCompanySiteByIdDetached (id , selections .withPolygons (), selections .withRings (),
78
- selections .withLocations ())
59
+ .findCompanySiteByIdDetached (id )
79
60
.stream ().map (this .entityDtoMapper ::mapToDto ).findFirst ()
80
61
.orElseThrow (() -> new ResourceNotFoundException (String .format ("No CompanySite found for id: %d" , id )));
81
62
}
0 commit comments