Last active
July 10, 2016 14:09
-
-
Save brunokrebs/40842f369f36155d55cac561d11f986d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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