Last active
July 19, 2020 09:50
-
-
Save hkakutalua/281564f0b895e213ebe6d8f781a778bd to your computer and use it in GitHub Desktop.
@transactional Without Save
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
@RestController | |
@RequestMapping("carts/{cart_id}/items") | |
class CartItemsController( | |
private val cartsRepository: CartsRepository, | |
private val productsRepository: ProductsRepository) { | |
@PostMapping | |
fun addItemToCart( | |
@PathVariable("cart_id") cartId: UUID, | |
@RequestBody cartItem: CartItemInputModel | |
) : ResponseEntity<Any> { | |
... | |
cart.addProduct(product, cartItem.quantity) | |
//cartsRepository.save(cart) // with @Transactional there's no need of this line | |
val savedProductItem = cart.items.first { x -> x.product.id == cartItem.productId } | |
return ResponseEntity.status(HttpStatus.CREATED) | |
.body(mapToCartItemViewModel(savedProductItem)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment