Search in sources :

Example 1 with UserAccount

use of com.springone.myrestaurants.domain.UserAccount in project spring-data-document-examples by spring-projects.

the class UserAccountDao method merge.

@Transactional
public UserAccount merge(UserAccount userAccount) {
    UserAccount merged = this.entityManager.merge(userAccount);
    this.entityManager.flush();
    return merged;
}
Also used : UserAccount(com.springone.myrestaurants.domain.UserAccount) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserAccount

use of com.springone.myrestaurants.domain.UserAccount in project spring-data-document-examples by spring-projects.

the class UserAccountDao method findByName.

public UserAccount findByName(String name) {
    if (name == null)
        return null;
    Query q = entityManager.createQuery("SELECT u FROM UserAccount u WHERE u.userName = :username");
    q.setParameter("username", name);
    java.util.List resultList = q.getResultList();
    if (resultList.size() > 0) {
        return (UserAccount) resultList.get(0);
    }
    return null;
}
Also used : Query(javax.persistence.Query) UserAccount(com.springone.myrestaurants.domain.UserAccount)

Example 3 with UserAccount

use of com.springone.myrestaurants.domain.UserAccount in project spring-data-document-examples by spring-projects.

the class SignUpController method updateForm.

@RequestMapping(value = "/{username}", params = "form2", method = RequestMethod.GET)
public String updateForm(@PathVariable("username") String userName, Model model) {
    UserAccount userAccount = userAccountDao.findByName(userName);
    model.addAttribute("userAccount", userAccount);
    addDateTimeFormatPatterns(model);
    return "useraccounts/update";
}
Also used : UserAccount(com.springone.myrestaurants.domain.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with UserAccount

use of com.springone.myrestaurants.domain.UserAccount in project spring-data-document-examples by spring-projects.

the class JpaUserAccountDao method findByName.

public UserAccount findByName(String name) {
    if (name == null)
        return null;
    Query q = entityManager.createQuery("SELECT u FROM UserAccount u WHERE u.userName = :username");
    q.setParameter("username", name);
    java.util.List resultList = q.getResultList();
    if (resultList.size() > 0) {
        return (UserAccount) resultList.get(0);
    }
    return null;
}
Also used : Query(javax.persistence.Query) UserAccount(com.springone.myrestaurants.domain.UserAccount)

Example 5 with UserAccount

use of com.springone.myrestaurants.domain.UserAccount in project spring-data-document-examples by spring-projects.

the class RestaurantController method addFavoriteRestaurant.

@RequestMapping(value = "/{id}/{userId}", params = "favorite", method = RequestMethod.PUT)
public String addFavoriteRestaurant(@PathVariable("id") String id, @PathVariable("userId") String userId, Model model) {
    Restaurant restaurant = this.restaurantDao.findRestaurant(id);
    //TODO will always return demo user.
    UserAccount account = this.userAccountDao.findUserAccount(314L);
    account.getFavorites().add(restaurant.getId());
    this.userAccountDao.persist(account);
    addDateTimeFormatPatterns(model);
    model.addAttribute("useraccount", account);
    model.addAttribute("itemId", id);
    //TODO converted to return 'getUserName' instead of 'getId'
    return "redirect:/useraccounts/" + account.getUserName();
}
Also used : Restaurant(com.springone.myrestaurants.domain.Restaurant) UserAccount(com.springone.myrestaurants.domain.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserAccount (com.springone.myrestaurants.domain.UserAccount)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Restaurant (com.springone.myrestaurants.domain.Restaurant)2 Query (javax.persistence.Query)2 Test (org.junit.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1