Skip to content

Instantly share code, notes, and snippets.

@brunokrebs
Last active July 10, 2016 14:09
Show Gist options
  • Save brunokrebs/40842f369f36155d55cac561d11f986d to your computer and use it in GitHub Desktop.
Save brunokrebs/40842f369f36155d55cac561d11f986d to your computer and use it in GitHub Desktop.
package com.someaddress.endpoint;
import com.someaddress.modelo.Product;
import com.someaddress.repository.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/rest/products")
public class ProductEndpoint {
@Autowired
private ProductRepository productRepository;
@RequestMapping(path = "/{productId}", method = RequestMethod.GET)
public @ResponseBody Product getProduct(@PathVariable String productId) {
return productRepository.getOne(productId);
}
@RequestMapping(path = "/", method = RequestMethod.POST)
public void saveProduct(@RequestBody @Validated DetailsUpdateIntent intent) {
Product product = new Product();
if (intent.getId() != null) {
product = productRepository.getOne(intent.getId());
}
product.handleDetailsUpdate(intent);
productRepository.save(product);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment