|
| 1 | +package io.keploy.samples.javadedup; |
| 2 | + |
| 3 | +import io.keploy.samples.javadedup.model.Item; |
| 4 | +import io.keploy.samples.javadedup.model.Product; |
| 5 | +import io.keploy.samples.javadedup.model.User; |
| 6 | +import org.springframework.http.HttpStatus; |
| 7 | +import org.springframework.http.ResponseEntity; |
| 8 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 9 | +import org.springframework.web.bind.annotation.GetMapping; |
| 10 | +import org.springframework.web.bind.annotation.PathVariable; |
| 11 | +import org.springframework.web.bind.annotation.PostMapping; |
| 12 | +import org.springframework.web.bind.annotation.PutMapping; |
| 13 | +import org.springframework.web.bind.annotation.RequestBody; |
| 14 | +import org.springframework.web.bind.annotation.RestController; |
| 15 | + |
| 16 | +import java.time.Instant; |
| 17 | +import java.util.Arrays; |
| 18 | +import java.util.LinkedHashMap; |
| 19 | +import java.util.List; |
| 20 | +import java.util.Map; |
| 21 | + |
| 22 | +@RestController |
| 23 | +public class DedupController { |
| 24 | + |
| 25 | + @GetMapping("/") |
| 26 | + public Map<String, Object> health() { |
| 27 | + Map<String, Object> response = new LinkedHashMap<>(); |
| 28 | + response.put("status", "ok"); |
| 29 | + return response; |
| 30 | + } |
| 31 | + |
| 32 | + @GetMapping("/hello/{name}") |
| 33 | + public String hello(@PathVariable String name) { |
| 34 | + return greeting(name); |
| 35 | + } |
| 36 | + |
| 37 | + @PostMapping("/user") |
| 38 | + public Map<String, Object> createUser(@RequestBody User user) { |
| 39 | + Map<String, Object> response = new LinkedHashMap<>(); |
| 40 | + response.put("message", "User created successfully"); |
| 41 | + response.put("user", user); |
| 42 | + return response; |
| 43 | + } |
| 44 | + |
| 45 | + @PutMapping("/item/{id}") |
| 46 | + public Map<String, Object> updateItem(@PathVariable String id, @RequestBody Item item) { |
| 47 | + Map<String, Object> response = new LinkedHashMap<>(); |
| 48 | + response.put("message", "Item updated successfully"); |
| 49 | + response.put("id", id); |
| 50 | + response.put("updatedData", item); |
| 51 | + return response; |
| 52 | + } |
| 53 | + |
| 54 | + @GetMapping("/products") |
| 55 | + public List<Product> products() { |
| 56 | + return Arrays.asList( |
| 57 | + new Product("prod001", "Eco-friendly Water Bottle", "A reusable bottle.", |
| 58 | + Arrays.asList("eco", "kitchen")), |
| 59 | + new Product("prod002", "Wireless Charger", "Charges your devices.", |
| 60 | + Arrays.asList("tech", "mobile")) |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + @DeleteMapping("/products/{id}") |
| 65 | + public Map<String, Object> deleteProduct(@PathVariable String id) { |
| 66 | + Map<String, Object> response = new LinkedHashMap<>(); |
| 67 | + response.put("status", "product " + id + " deleted"); |
| 68 | + return response; |
| 69 | + } |
| 70 | + |
| 71 | + @GetMapping("/api/v2/users") |
| 72 | + public Map<String, Object> apiUsers() { |
| 73 | + Map<String, Object> first = new LinkedHashMap<>(); |
| 74 | + first.put("name", "gamma"); |
| 75 | + Map<String, Object> second = new LinkedHashMap<>(); |
| 76 | + second.put("name", "delta"); |
| 77 | + |
| 78 | + Map<String, Object> response = new LinkedHashMap<>(); |
| 79 | + response.put("version", 2); |
| 80 | + response.put("users", Arrays.asList(first, second)); |
| 81 | + return response; |
| 82 | + } |
| 83 | + |
| 84 | + @GetMapping("/timestamp") |
| 85 | + public Map<String, Object> timestamp() { |
| 86 | + Map<String, Object> response = new LinkedHashMap<>(); |
| 87 | + response.put("current_time", Instant.now().toString()); |
| 88 | + return response; |
| 89 | + } |
| 90 | + |
| 91 | + @GetMapping("/status/{name}") |
| 92 | + public ResponseEntity<Map<String, Object>> status(@PathVariable String name) { |
| 93 | + Map<String, Object> response = new LinkedHashMap<>(); |
| 94 | + response.put("message", greeting(name)); |
| 95 | + response.put("service", "java-dedup"); |
| 96 | + return new ResponseEntity<>(response, HttpStatus.OK); |
| 97 | + } |
| 98 | + |
| 99 | + private String greeting(String name) { |
| 100 | + return "Hello, " + name + "!"; |
| 101 | + } |
| 102 | +} |
0 commit comments