Skip to content

Commit 988ac3a

Browse files
committed
Refactor DataController (allows accessing items in relationships)
1 parent d703f3e commit 988ac3a

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
profile=dev
22
springBootVersion=2.3.1.RELEASE
33
javaxInjectVersion=1
4-
elideVersion=4.6.2
4+
elideVersion=4.6.6
55
mysqlConnectorVersion=8.0.18
66
propdepsVersion=0.0.7
77
swaggerVersion=2.9.2

src/main/java/com/faforever/api/data/DataController.java

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import org.springframework.security.access.prepost.PreAuthorize;
1010
import org.springframework.security.core.Authentication;
1111
import org.springframework.stereotype.Component;
12+
import org.springframework.web.bind.annotation.DeleteMapping;
13+
import org.springframework.web.bind.annotation.GetMapping;
14+
import org.springframework.web.bind.annotation.PatchMapping;
15+
import org.springframework.web.bind.annotation.PostMapping;
1216
import org.springframework.web.bind.annotation.RequestBody;
1317
import org.springframework.web.bind.annotation.RequestMapping;
1418
import org.springframework.web.bind.annotation.RequestMethod;
@@ -44,10 +48,7 @@ private static Object getPrincipal(final Authentication authentication) {
4448
}
4549

4650
//!!! No @Transactional - transactions are being handled by Elide
47-
@RequestMapping(
48-
method = RequestMethod.GET,
49-
produces = JSON_API_MEDIA_TYPE,
50-
value = {"/{entity}", "/{entity}/{id}/relationships/{entity2}", "/{entity}/{id}/{child}", "/{entity}/{id}"})
51+
@GetMapping(value = "/**", produces = JSON_API_MEDIA_TYPE)
5152
@Cacheable(cacheResolver = "elideCacheResolver", keyGenerator = GetCacheKeyGenerator.NAME)
5253
public ResponseEntity<String> get(@RequestParam final Map<String, String> allRequestParams,
5354
final HttpServletRequest request,
@@ -61,76 +62,67 @@ public ResponseEntity<String> get(@RequestParam final Map<String, String> allReq
6162
}
6263

6364
//!!! No @Transactional - transactions are being handled by Elide
64-
@RequestMapping(
65-
method = RequestMethod.POST,
66-
consumes = {JSON_API_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE},
67-
produces = JSON_API_MEDIA_TYPE,
68-
value = {"/{entity}", "/{entity}/{id}/relationships/{entity2}", "/{entity}/{id}/{child}", "/{entity}/{id}"})
69-
@Cacheable(cacheResolver = "elideCacheResolver")
65+
@PostMapping(value = "/**", consumes = {JSON_API_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}, produces = JSON_API_MEDIA_TYPE)
7066
@PreAuthorize("isAuthenticated()")
71-
public ResponseEntity<String> post(@RequestBody final String body,
67+
public ResponseEntity<String> post(@RequestParam final Map<String, String> allRequestParams,
68+
@RequestBody final String body,
7269
final HttpServletRequest request,
7370
final Authentication authentication) {
7471
ElideResponse response = elide.post(
7572
getJsonApiPath(request),
7673
body,
74+
new MultivaluedHashMap<>(allRequestParams),
7775
getPrincipal(authentication)
7876
);
7977
return wrapResponse(response);
8078
}
8179

8280
//!!! No @Transactional - transactions are being handled by Elide
83-
@RequestMapping(
84-
method = RequestMethod.PATCH,
85-
consumes = {JSON_API_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE},
86-
produces = JSON_API_MEDIA_TYPE,
87-
value = {"/{entity}/{id}", "/{entity}/{id}/relationships/{entity2}"})
81+
@PatchMapping(value = "/**", consumes = {JSON_API_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}, produces = JSON_API_MEDIA_TYPE)
8882
@PreAuthorize("isAuthenticated()")
89-
public ResponseEntity<String> patch(@RequestBody final String body,
83+
public ResponseEntity<String> patch(@RequestParam final Map<String, String> allRequestParams,
84+
@RequestBody final String body,
9085
final HttpServletRequest request,
9186
final Authentication authentication) {
9287
ElideResponse response = elide.patch(
9388
JSON_API_MEDIA_TYPE,
9489
JSON_API_MEDIA_TYPE,
9590
getJsonApiPath(request),
9691
body,
92+
new MultivaluedHashMap<>(allRequestParams),
9793
getPrincipal(authentication)
9894
);
9995
return wrapResponse(response);
10096
}
10197

10298
//!!! No @Transactional - transactions are being handled by Elide
103-
@RequestMapping(
104-
method = RequestMethod.PATCH,
105-
consumes = JSON_API_PATCH_MEDIA_TYPE,
106-
produces = JSON_API_MEDIA_TYPE,
107-
value = "/{entity}")
108-
// should contain "/{entity}/{id}" but spring will call this method even for JSON_API_MEDIA_TYPE
99+
@PatchMapping(value = "/**", consumes = JSON_API_PATCH_MEDIA_TYPE, produces = JSON_API_MEDIA_TYPE)
109100
@PreAuthorize("isAuthenticated()")
110-
public ResponseEntity<String> extensionPatch(@RequestBody final String body,
101+
public ResponseEntity<String> extensionPatch(@RequestParam final Map<String, String> allRequestParams,
102+
@RequestBody final String body,
111103
final HttpServletRequest request,
112104
final Authentication authentication) {
113105
ElideResponse response = elide.patch(
114106
JSON_API_PATCH_MEDIA_TYPE,
115107
JSON_API_MEDIA_TYPE,
116108
getJsonApiPath(request),
117109
body,
110+
new MultivaluedHashMap<>(allRequestParams),
118111
getPrincipal(authentication)
119112
);
120113
return wrapResponse(response);
121114
}
122115

123116
//!!! No @Transactional - transactions are being handled by Elide
124-
@RequestMapping(
125-
method = RequestMethod.DELETE,
126-
produces = JSON_API_MEDIA_TYPE,
127-
value = {"/{entity}/{id}", "/{entity}/{id}/relationships/{entity2}"})
117+
@DeleteMapping(value = "/**", produces = JSON_API_MEDIA_TYPE)
128118
@PreAuthorize("isAuthenticated()")
129-
public ResponseEntity<String> delete(final HttpServletRequest request,
119+
public ResponseEntity<String> delete(@RequestParam final Map<String, String> allRequestParams,
120+
final HttpServletRequest request,
130121
final Authentication authentication) {
131122
ElideResponse response = elide.delete(
132123
getJsonApiPath(request),
133124
null,
125+
new MultivaluedHashMap<>(allRequestParams),
134126
getPrincipal(authentication)
135127
);
136128
return wrapResponse(response);

0 commit comments

Comments
 (0)