You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2019/10/30 20:14:15 UTC

[juneau-petstore] 14/31: create and update methods added to the service

This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau-petstore.git

commit 7d0b9ed2205a4b4ece8404cb16141973a998131f
Author: rasa <fi...@gmail.com>
AuthorDate: Sun Oct 13 18:35:10 2019 +0300

    create and update methods added to the service
---
 .../juneau/petstore/service/PetStoreService.java   | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java
index 3e45a30..2300d8c 100644
--- a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java
+++ b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java
@@ -180,9 +180,8 @@ public class PetStoreService extends AbstractPersistenceService {
 	 * @param c The pet input data.
 	 * @return a new {@link Pet} object.
 	 */
-	public Pet create(CreatePet c) {
-		
-		return merge(new Pet().status(PetStatus.AVAILABLE).apply(c));
+	public Pet create(CreatePet c) {	
+		return petRepository.save((new Pet().status(PetStatus.AVAILABLE).apply(c)));
 	}
 
 	/**
@@ -192,7 +191,7 @@ public class PetStoreService extends AbstractPersistenceService {
 	 * @return a new {@link Order} object.
 	 */
 	public Order create(CreateOrder c) {
-		return merge(new Order().status(OrderStatus.PLACED).apply(c));
+		return orderRepository.save((new Order().status(OrderStatus.PLACED).apply(c)));
 	}
 
 	/**
@@ -202,7 +201,7 @@ public class PetStoreService extends AbstractPersistenceService {
 	 * @return a new {@link User} object.
 	 */
 	public User create(User c) {
-		return merge(new User().apply(c));
+		return userRepository.save((new User().apply(c)));
 	}
 
 	/**
@@ -213,8 +212,8 @@ public class PetStoreService extends AbstractPersistenceService {
 	 * @throws IdNotFound Pet was not found.
 	 */
 	public Pet update(UpdatePet u) throws IdNotFound {
-		EntityManager em = getEntityManager();
-		return merge(em, find(em, Pet.class, u.getId()).apply(u));
+		Pet pet =  petRepository.findById(u.getId()).get();		
+		return petRepository.save(pet.apply(u));
 	}
 
 	/**
@@ -225,8 +224,8 @@ public class PetStoreService extends AbstractPersistenceService {
 	 * @throws IdNotFound Order was not found.
 	 */
 	public Order update(Order o) throws IdNotFound {
-		EntityManager em = getEntityManager();
-		return merge(em, find(em, Order.class, o.getId()).apply(o));
+		Order order =  orderRepository.findById(o.getId()).get();		
+		return orderRepository.save(order.apply(o));
 	}
 
 	/**
@@ -238,9 +237,8 @@ public class PetStoreService extends AbstractPersistenceService {
 	 * @throws InvalidUsername The username was not valid.
 	 */
 	public User update(User u) throws IdNotFound, InvalidUsername {
-		assertValidUsername(u.getUsername());
-		EntityManager em = getEntityManager();
-		return merge(em, find(em, User.class, u.getUsername()).apply(u));
+		User user =  userRepository.findByUsername(u.getUsername());		
+		return userRepository.save(user.apply(u));
 	}
 
 	/**