area api impl

This commit is contained in:
priyank-sriv 2020-05-13 01:58:05 +05:30
parent 167655d659
commit e8c383d10f
4 changed files with 79 additions and 0 deletions

View File

@ -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()));
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}