Skip to content

Commit

Permalink
FAIRSPC-81: aligned the way we map resources across all controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreenwood committed Oct 14, 2024
1 parent c35bae3 commit a0c37d1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import io.fairspace.saturn.config.properties.FeatureProperties;

@RestController
@RequestMapping("${application.basePath}/features/")
@RequestMapping("${application.basePath}/features")
@RequiredArgsConstructor
public class FeaturesController {

private final FeatureProperties featureProperties;

@GetMapping
@GetMapping("/")
public ResponseEntity<Set<Feature>> getFeatures() {
return ResponseEntity.ok(featureProperties.getFeatures());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@Log4j2
@RestController
@RequestMapping("${application.basePath}/metadata/")
@RequestMapping("${application.basePath}/metadata")
@RequiredArgsConstructor
@Validated
public class MetadataController {
Expand All @@ -43,7 +43,9 @@ public class MetadataController {

private final Services services;

@GetMapping(produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_LD_JSON, TEXT_TURTLE, APPLICATION_N_TRIPLES})
@GetMapping(
value = "/",
produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_LD_JSON, TEXT_TURTLE, APPLICATION_N_TRIPLES})
public ResponseEntity<String> getMetadata(
@RequestParam(required = false) String subject,
@RequestParam(name = "withValueProperties", defaultValue = "false") boolean withValueProperties,
Expand All @@ -54,7 +56,9 @@ public ResponseEntity<String> getMetadata(
return ResponseEntity.ok(metadata);
}

@PutMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_LD_JSON, TEXT_TURTLE, APPLICATION_N_TRIPLES})
@PutMapping(
value = "/",
consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_LD_JSON, TEXT_TURTLE, APPLICATION_N_TRIPLES})
@ResponseStatus(HttpStatus.NO_CONTENT)
public void putMetadata(
@RequestBody String body,
Expand All @@ -66,6 +70,7 @@ public void putMetadata(
}

@PatchMapping(
value = "/",
consumes = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_LD_JSON, TEXT_TURTLE, APPLICATION_N_TRIPLES})
@ResponseStatus(HttpStatus.NO_CONTENT)
public void patchMetadata(
Expand All @@ -76,7 +81,7 @@ public void patchMetadata(
services.getMetadataService().patch(model, doViewsUpdate);
}

@DeleteMapping
@DeleteMapping("/")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteMetadata(
@RequestParam(required = false) @ValidIri String subject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import io.fairspace.saturn.services.AccessDeniedException;
import io.fairspace.saturn.services.views.SparqlQueryService;

import static io.fairspace.saturn.controller.enums.CustomMediaType.APPLICATION_SPARQL_QUERY;

@RestController
@RequestMapping("${application.basePath}/rdf")
@Validated
Expand All @@ -29,7 +31,7 @@ public class SparqlController {
* @param sparqlQuery the SPARQL query
* @return the result of the query (JSON)
*/
@PostMapping(value = "/query", consumes = "application/sparql-query", produces = "application/json")
@PostMapping(value = "/query", consumes = APPLICATION_SPARQL_QUERY)
// todo: uncomment the line below and remove the metadataPermissions.hasMetadataQueryPermission() call once
// the MetadataPermissions is available in the IoC container
// @PreAuthorize("@metadataPermissions.hasMetadataQueryPermission()")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
import io.fairspace.saturn.services.users.UserService;

@RestController
@RequestMapping("${application.basePath}/users/")
@RequestMapping("${application.basePath}/users")
@RequiredArgsConstructor
public class UserController {

private final UserService userService;

@GetMapping
@GetMapping("/")
public ResponseEntity<Collection<User>> getUsers() {
return ResponseEntity.ok(userService.getUsers());
}

@PatchMapping
@PatchMapping("/")
public ResponseEntity<Void> updateUserRoles(@RequestBody UserRolesUpdate update) {
userService.update(update);
return ResponseEntity.noContent().build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.fairspace.saturn.controller;

import jakarta.validation.Valid;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -29,28 +28,25 @@ public ViewController(Services services) {
this.services = services;
}

@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping("/")
public ViewsDto getViews() {
var views = services.getViewService().getViews();
return new ViewsDto(views);
}

@PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping("/")
public ResponseEntity<ViewPageDto> getViewData(@Valid @RequestBody ViewRequest requestBody) {
var result = services.getQueryService().retrieveViewPage(requestBody);
return ResponseEntity.ok(result);
}

@GetMapping(value = "/facets", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping("/facets")
public ResponseEntity<FacetsDto> getFacets() {
var facets = services.getViewService().getFacets();
return ResponseEntity.ok(new FacetsDto(facets));
}

@PostMapping(
value = "/count",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping("/count")
public ResponseEntity<CountDto> count(@Valid @RequestBody CountRequest requestBody) {
var result = services.getQueryService().count(requestBody);
return ResponseEntity.ok(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import static io.fairspace.saturn.vocabulary.Vocabularies.VOCABULARY;

@RestController
@RequestMapping("${application.basePath}/vocabulary/")
@RequestMapping("${application.basePath}/vocabulary")
public class VocabularyController {

@GetMapping
@GetMapping("/")
public ResponseEntity<String> getVocabulary(
@RequestHeader(value = HttpHeaders.ACCEPT, required = false) String acceptHeader) {
var format = getFormat(acceptHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -35,19 +34,19 @@ public WorkspaceController(Services services) {
this.services = services;
}

@PutMapping(value = "/")
@PutMapping("/")
public ResponseEntity<Workspace> createWorkspace(@RequestBody Workspace workspace) {
var createdWorkspace = services.getWorkspaceService().createWorkspace(workspace);
return ResponseEntity.ok(createdWorkspace);
}

@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping("/")
public ResponseEntity<List<Workspace>> listWorkspaces() {
var workspaces = services.getWorkspaceService().listWorkspaces();
return ResponseEntity.ok(workspaces);
}

@DeleteMapping(value = "/")
@DeleteMapping("/")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteWorkspace(@RequestParam("workspace") String workspaceUri) {
services.getWorkspaceService().deleteWorkspace(NodeFactory.createURI(workspaceUri));
Expand All @@ -60,7 +59,7 @@ public ResponseEntity<Map<Node, WorkspaceRole>> getUsers(@RequestParam("workspac
return ResponseEntity.ok(users);
}

@PatchMapping(value = "/users/", consumes = MediaType.APPLICATION_JSON_VALUE)
@PatchMapping(value = "/users/")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setUserRole(@RequestBody UserRoleDto userRoleDto) {
services.getWorkspaceService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public enum CustomMediaType {
public static final String TEXT_TURTLE = "text/turtle";

public static final String APPLICATION_N_TRIPLES = "application/n-triples";

public static final String APPLICATION_SPARQL_QUERY = "application/sparql-query";
}

0 comments on commit a0c37d1

Please sign in to comment.