Skip to content

Commit

Permalink
Refactor spreadsheet duplicate endpoints to remove redundant path seg…
Browse files Browse the repository at this point in the history
…ment (#126)

Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>
  • Loading branch information
ayolab authored Feb 27, 2025
1 parent 3c5ed41 commit 036fe8f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public ResponseEntity<Void> updateSpreadsheetConfigCollection(@PathVariable UUID
return ResponseEntity.noContent().build();
}

@PostMapping(value = "/explore/spreadsheet-configs/duplicate", params = "duplicateFrom")
@PostMapping(value = "/explore/spreadsheet-configs", params = "duplicateFrom")
@Operation(summary = "Duplicate a spreadsheet configuration")
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Spreadsheet config has been successfully duplicated")})
public ResponseEntity<Void> duplicateSpreadsheetConfig(@RequestParam("duplicateFrom") UUID sourceId,
Expand All @@ -399,7 +399,7 @@ public ResponseEntity<Void> duplicateSpreadsheetConfig(@RequestParam("duplicateF
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@PostMapping(value = "/explore/spreadsheet-config-collections/duplicate", params = "duplicateFrom")
@PostMapping(value = "/explore/spreadsheet-config-collections", params = "duplicateFrom")
@Operation(summary = "Duplicate a spreadsheet configuration collection")
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Spreadsheet config collection has been successfully duplicated")})
public ResponseEntity<Void> duplicateSpreadsheetConfigCollection(@RequestParam("duplicateFrom") UUID sourceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public UUID duplicateSpreadsheetConfigCollection(UUID collectionId) {
Objects.requireNonNull(collectionId);

var path = UriComponentsBuilder
.fromPath(SPREADSHEET_CONFIG_COLLECTIONS_PATH + DELIMITER + "duplicate")
.fromPath(SPREADSHEET_CONFIG_COLLECTIONS_PATH)
.queryParam(DUPLICATE_FROM_PARAMETER, collectionId)
.buildAndExpand()
.toUriString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public UUID duplicateSpreadsheetConfig(UUID configUuid) {
Objects.requireNonNull(configUuid);

var path = UriComponentsBuilder
.fromPath(SPREADSHEET_CONFIG_SERVER_ROOT_PATH + DELIMITER + "duplicate")
.fromPath(SPREADSHEET_CONFIG_SERVER_ROOT_PATH)
.queryParam(DUPLICATE_FROM_PARAMETER, configUuid)
.buildAndExpand()
.toUriString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public MockResponse dispatch(RecordedRequest request) {
return new MockResponse(201, Headers.of("Content-Type", "application/json"), objectMapper.writeValueAsString(COLLECTION_UUID));
} else if (path.matches(SPREADSHEET_CONFIG_COLLECTION_SERVER_BASE_URL + "/" + COLLECTION_UUID)) {
return new MockResponse(204);
} else if (path.matches(SPREADSHEET_CONFIG_COLLECTION_SERVER_BASE_URL + "/duplicate\\?duplicateFrom=" + COLLECTION_UUID) && "POST".equals(request.getMethod())) {
} else if (path.matches(SPREADSHEET_CONFIG_COLLECTION_SERVER_BASE_URL + "\\?duplicateFrom=" + COLLECTION_UUID) && "POST".equals(request.getMethod())) {
return new MockResponse(201, Headers.of("Content-Type", "application/json"), objectMapper.writeValueAsString(UUID.randomUUID()));
} else if (path.matches("/v1/directories/.*/elements\\?allowNewName=.*") && "POST".equals(request.getMethod()) || path.matches("/v1/elements/" + COLLECTION_UUID)) {
ElementAttributes elementAttributes = new ElementAttributes(COLLECTION_UUID, COLLECTION_NAME, "SPREADSHEET_CONFIG_COLLECTION", USER_ID, 0L, null);
Expand Down Expand Up @@ -136,7 +136,7 @@ void testUpdateSpreadsheetConfigCollection() throws Exception {

@Test
void testDuplicateSpreadsheetConfigCollection() throws Exception {
mockMvc.perform(post(BASE_URL + "/duplicate")
mockMvc.perform(post(BASE_URL)
.param("duplicateFrom", COLLECTION_UUID.toString())
.param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString())
.header("userId", USER_ID))
Expand All @@ -145,7 +145,7 @@ void testDuplicateSpreadsheetConfigCollection() throws Exception {

@Test
void testDuplicateSpreadsheetConfigCollectionWithInvalidUUID() throws Exception {
mockMvc.perform(post(BASE_URL + "/duplicate")
mockMvc.perform(post(BASE_URL)
.param("duplicateFrom", "invalid-uuid")
.param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString())
.header("userId", USER_ID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public MockResponse dispatch(RecordedRequest request) {
return new MockResponse(201, Headers.of("Content-Type", "application/json"), objectMapper.writeValueAsString(CONFIG_UUID));
} else if (path.matches(SPREADSHEET_CONFIG_SERVER_BASE_URL + "/" + CONFIG_UUID) && "PUT".equals(request.getMethod())) {
return new MockResponse(204);
} else if (path.matches(SPREADSHEET_CONFIG_SERVER_BASE_URL + "/duplicate\\?duplicateFrom=" + CONFIG_UUID) && "POST".equals(request.getMethod())) {
} else if (path.matches(SPREADSHEET_CONFIG_SERVER_BASE_URL + "\\?duplicateFrom=" + CONFIG_UUID) && "POST".equals(request.getMethod())) {
return new MockResponse(201, Headers.of("Content-Type", "application/json"), objectMapper.writeValueAsString(UUID.randomUUID()));
} else if (path.matches(SPREADSHEET_CONFIG_SERVER_BASE_URL + "/metadata\\?ids=" + CONFIG_UUID)) {
Map<String, Object> metadata = new HashMap<>();
Expand Down Expand Up @@ -142,7 +142,7 @@ void testUpdateSpreadsheetConfig() throws Exception {

@Test
void testDuplicateSpreadsheetConfig() throws Exception {
mockMvc.perform(post(BASE_URL + "/duplicate")
mockMvc.perform(post(BASE_URL)
.param("duplicateFrom", CONFIG_UUID.toString())
.param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString())
.header("userId", USER_ID))
Expand All @@ -151,7 +151,7 @@ void testDuplicateSpreadsheetConfig() throws Exception {

@Test
void testDuplicateSpreadsheetConfigWithInvalidUUID() throws Exception {
mockMvc.perform(post(BASE_URL + "/duplicate")
mockMvc.perform(post(BASE_URL)
.param("duplicateFrom", "invalid-uuid")
.param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString())
.header("userId", USER_ID))
Expand Down

0 comments on commit 036fe8f

Please sign in to comment.