Skip to content

Commit

Permalink
Merge pull request #2 from dai-fuji/fix/modifyForPullRequest
Browse files Browse the repository at this point in the history
指摘事項修正(バリデーションのステータスコード対応除く)
  • Loading branch information
dai-fuji authored Jul 3, 2022
2 parents f188074 + cbd7a95 commit e45fb69
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/main/java/com/fujimoto/rest/DemoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import javax.validation.constraints.Pattern;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand All @@ -16,31 +15,26 @@
public class DemoController {

@GetMapping("/names")
public String getName( @RequestParam("id") @Pattern (regexp = "^[1-3]$" ) String id) {
Map<Integer, String> namesById = Map.of(1,"Ichiro",2, "Jiro",3,"Saburo");
public String getName(@RequestParam("id") @Pattern(regexp = "^[1-3]$") String id) {
Map<Integer, String> namesById = Map.of(1, "Ichiro", 2, "Jiro", 3, "Saburo");
return namesById.get(Integer.valueOf(id));
}

@GetMapping("/fruit")
public List<String> getFruitList(@RequestParam("priceMin") @Pattern (regexp = "^[0-9]{1,4}$" ) String priceMin) {
Map<String, Integer> fruits = Map.of("apple",100,"orange", 150,"grape",1000);
@GetMapping("/fruits")
public List<String> getFruitList(@RequestParam("priceMin") @Pattern(regexp = "^[0-9]{1,4}$") String priceMin) {
Map<String, Integer> priceByFruit = Map.of("apple", 100, "orange", 150, "grape", 1000);
Integer priceMinToInt = Integer.valueOf(priceMin);
List<String> fruitsFilterByPrice = new ArrayList<>();

fruits.forEach((fruitName, fruitPrice) -> {
Integer price = Integer.valueOf(fruitPrice);
if (priceMinToInt < price){
fruitsFilterByPrice.add(fruitName);
}
});
if (fruitsFilterByPrice.isEmpty()){
return null;
}

List<String> fruitsFilterByPrice = priceByFruit.entrySet().stream()
.filter(map -> map.getValue() > priceMinToInt)
.map(map -> map.getKey())
.toList();

return fruitsFilterByPrice;
}

@PostMapping("/names")
public ResponseEntity<String> create(@RequestBody CreateForm form){
public ResponseEntity<String> create(@RequestBody CreateForm form) {
URI url = UriComponentsBuilder.fromUriString("http:localhost:8080")
.path("/names/id")
.build()
Expand All @@ -49,15 +43,14 @@ public ResponseEntity<String> create(@RequestBody CreateForm form){
}

@PatchMapping("/names/{id}")
public ResponseEntity<Map<String, String>> updateForm(@PathVariable("id") int id , @RequestBody UpdateForm form){
return ResponseEntity.ok(Map.of("message", "name successfully updated" ));
public ResponseEntity<Map<String, String>> updateForm(@PathVariable("id") int id, @RequestBody UpdateForm form) {
return ResponseEntity.ok(Map.of("message", "name successfully updated"));
}

@DeleteMapping("/names/{id}")
public ResponseEntity<Map<String, String>> deleteForm(@PathVariable("id") int id , @RequestBody UpdateForm form){
return ResponseEntity.ok(Map.of("message", "name successfully deleted" ));
public ResponseEntity<Map<String, String>> deleteForm(@PathVariable("id") int id, @RequestBody UpdateForm form) {
return ResponseEntity.ok(Map.of("message", "name successfully deleted"));
}



}

0 comments on commit e45fb69

Please sign in to comment.