Skip to content

Commit 357ca2d

Browse files
committed
add controller to demonstrate rename endpoint refactoring
1 parent 9ae89da commit 357ca2d

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.lakesidemutual.customercore.interfaces;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.*;
6+
7+
import java.net.URI;
8+
9+
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
10+
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
11+
12+
/**
13+
* This controller demonstrates the use of a 301 Moved Permanently response to redirect requests to a new URI.
14+
*
15+
* See the <a href="https://interface-refactoring.github.io/refactorings/renameendpoint">Rename Endpoint</a> refactoring for more information.
16+
*/
17+
@RestController
18+
@RequestMapping(path = "getCustomers")
19+
public class OldCustomerInformationHolder {
20+
21+
/**
22+
* Handles GET requests for customer information.
23+
*
24+
* @param ids The customer IDs.
25+
* @param fields The fields to be included in the response (optional).
26+
* @return A ResponseEntity with a status of 301 Moved Permanently and the location header set to the new URI.
27+
*/
28+
@GetMapping(value = "/{ids}")
29+
@ResponseBody
30+
public ResponseEntity getCustomer(
31+
@PathVariable String ids,
32+
@RequestParam(value = "fields", required = false, defaultValue = "") String fields) {
33+
URI movedTo = linkTo(methodOn(CustomerInformationHolder.class).getCustomer(ids, fields)).toUri();
34+
return ResponseEntity
35+
.status(HttpStatus.MOVED_PERMANENTLY)
36+
.location(movedTo)
37+
.build();
38+
}
39+
}

0 commit comments

Comments
 (0)