|
| 1 | +package dev.marco.example.springboot.feature; |
| 2 | + |
| 3 | +import org.json.JSONException; |
| 4 | +import org.json.JSONObject; |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; |
| 6 | +import org.springframework.http.MediaType; |
| 7 | +import org.springframework.http.ResponseEntity; |
| 8 | +import org.springframework.web.bind.annotation.*; |
| 9 | + |
| 10 | +/** |
| 11 | + * The goal of this controller is to show the test of the services and some REST methods |
| 12 | + */ |
| 13 | +@RestController |
| 14 | +@CrossOrigin(origins = {"${app.dev.frontend.local"}) |
| 15 | +public class FeatureController { |
| 16 | + |
| 17 | + @Autowired |
| 18 | + FeatureService featureService; |
| 19 | + |
| 20 | + @GetMapping(value = "/feature", consumes = MediaType.APPLICATION_JSON_VALUE) |
| 21 | + public ResponseEntity<String> getSum(@RequestBody OperationValues operationValues) throws JSONException { |
| 22 | + Integer sumResult = featureService.getSum(operationValues.getValueA(), operationValues.getValueB()); |
| 23 | + JSONObject result = new JSONObject(); |
| 24 | + result.put("result", sumResult); |
| 25 | + return ResponseEntity.ok(result.toString()); |
| 26 | + } |
| 27 | + |
| 28 | + @PostMapping(value = "/feature", consumes = MediaType.APPLICATION_JSON_VALUE) |
| 29 | + public ResponseEntity<String> postSum(@RequestBody OperationValues operationValues) throws JSONException { |
| 30 | + Integer sumResult = featureService.getSum(operationValues.getValueA(), operationValues.getValueB()); |
| 31 | + JSONObject result = new JSONObject(); |
| 32 | + result.put("result", sumResult); |
| 33 | + return ResponseEntity.ok(result.toString()); |
| 34 | + } |
| 35 | + |
| 36 | +} |
0 commit comments