area api impl
This commit is contained in:
parent
167655d659
commit
e8c383d10f
@ -0,0 +1,29 @@
|
||||
package com.baeldung.ratelimiting.controller;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baeldung.ratelimiting.dto.AreaV1;
|
||||
import com.baeldung.ratelimiting.dto.RectangleDimensionsV1;
|
||||
import com.baeldung.ratelimiting.dto.TriangleDimensionsV1;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/v1/area", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
class AreaCalculationController {
|
||||
|
||||
@PostMapping(value = "/rectangle", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<AreaV1> rectangle(@RequestBody RectangleDimensionsV1 dimensions) {
|
||||
|
||||
return ResponseEntity.ok(new AreaV1("rectangle", dimensions.getLength() * dimensions.getWidth()));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/triangle", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<AreaV1> triangle(@RequestBody TriangleDimensionsV1 dimensions) {
|
||||
|
||||
return ResponseEntity.ok(new AreaV1("triangle", 0.5d * dimensions.getHeight() * dimensions.getBase()));
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.baeldung.ratelimiting.dto;
|
||||
|
||||
public class AreaV1 {
|
||||
|
||||
private String shape;
|
||||
private Double area;
|
||||
|
||||
public AreaV1(String shape, Double area) {
|
||||
this.area = area;
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public Double getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public String getShape() {
|
||||
return shape;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.baeldung.ratelimiting.dto;
|
||||
|
||||
public class RectangleDimensionsV1 {
|
||||
|
||||
private double length;
|
||||
private double width;
|
||||
|
||||
public double getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.baeldung.ratelimiting.dto;
|
||||
|
||||
public class TriangleDimensionsV1 {
|
||||
|
||||
private double base;
|
||||
private double height;
|
||||
|
||||
public double getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user