Updated rest
This commit is contained in:
parent
5652436981
commit
121dd53752
@ -1,10 +1,7 @@
|
|||||||
package com.cubetiqs.demo.rest;
|
package com.cubetiqs.demo.rest;
|
||||||
|
|
||||||
import com.cubetiqs.demo.domain.Product;
|
import com.cubetiqs.demo.domain.Product;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -13,11 +10,23 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(path = "/products")
|
@RequestMapping(path = "/products")
|
||||||
public class ProductController {
|
public class ProductController {
|
||||||
@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
|
private final List<Product> items = new ArrayList<>();
|
||||||
|
|
||||||
|
@RequestMapping(method = {RequestMethod.GET})
|
||||||
public List<Product> getAllProducts() {
|
public List<Product> getAllProducts() {
|
||||||
List<Product> items = new ArrayList<>();
|
|
||||||
items.add(new Product(1L, "Apple", BigDecimal.valueOf(1.0), false));
|
items.add(new Product(1L, "Apple", BigDecimal.valueOf(1.0), false));
|
||||||
items.add(new Product(2L, "Apple", BigDecimal.valueOf(0.5), true));
|
items.add(new Product(2L, "Apple", BigDecimal.valueOf(0.5), true));
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Product getOneProduct(@PathVariable int id) {
|
||||||
|
return items.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Product createProduct(@RequestBody Product item) {
|
||||||
|
items.add(item);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user