Search in sources :

Example 6 with UserAccount

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

the class UserAccountDaoTests method resetFavorites.

@Test
public void resetFavorites() {
    UserAccount u = userAccountDao.findByName("demouser");
    u.getFavorites().clear();
    userAccountDao.persist(u);
}
Also used : UserAccount(com.springone.myrestaurants.domain.UserAccount) Test(org.junit.Test)

Example 7 with UserAccount

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

the class UserAccountDaoTests method readUser.

@Test
public void readUser() {
    UserAccount u = userAccountDao.findByName("demouser");
    assertBasicPropertyValues(u);
    u = userAccountDao.findUserAccount(1L);
    assertBasicPropertyValues(u);
    System.out.println(u);
    int originalFavoriteSize = u.getFavorites().size();
    String revisionOld = u.getRevision();
    u.getFavorites().add("4");
    userAccountDao.persist(u);
    //u =  userAccountDao.findByName("demouser");
    System.out.println(u);
    Assert.assertEquals(originalFavoriteSize + 1, u.getFavorites().size());
    Assert.assertNotSame("revision should not be the same", revisionOld, u.getRevision());
//restTemplate.getForObject("http://127.0.0.1:5984/spring_demo/demouser",UserAccount.class);
//System.out.println("user = " + u);
/*
		System.out.println(u);		
		int[] favorites = u.getFavorites();
		List<Integer> favList = Utils.convertToList(favorites);
		favList.add(4);
		int[] newList = Utils.convertToPrimArray(favList);
		u.setFavorites(newList);
		*/
/*
		HttpEntity<User> response = restTemplate.exchange(
				"http://127.0.0.1:5984/spring_demo/demouser", HttpMethod.PUT,
				new HttpEntity(new HttpHeaders()), User.class);
		System.out.println("http put response = " + response.getBody());*/
/*
		restTemplate.put("http://127.0.0.1:5984/spring_demo/demouser", u);
		
		u = restTemplate.getForObject("http://127.0.0.1:5984/spring_demo/demouser",User.class);
		System.out.println("user = " + u);*/
}
Also used : UserAccount(com.springone.myrestaurants.domain.UserAccount) Test(org.junit.Test)

Example 8 with UserAccount

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

the class SignUpController method createForm.

@RequestMapping(params = "form", method = RequestMethod.GET)
public String createForm(Model model) {
    model.addAttribute("userAccount", new UserAccount());
    addDateTimeFormatPatterns(model);
    return "useraccounts/create";
}
Also used : UserAccount(com.springone.myrestaurants.domain.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with UserAccount

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

the class BaseApplicationController method populateCurrentUserName.

@ModelAttribute("currentUserAccountId")
public String populateCurrentUserName() {
    String currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
    UserAccount userAccount = userAccountDao.findByName(currentUser);
    if (userAccount != null) {
        return userAccount.getId().toString();
    } else {
        return "USER-ID-NOT-AVAILABLE";
    }
}
Also used : UserAccount(com.springone.myrestaurants.domain.UserAccount) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 10 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") Long id, @PathVariable("userId") Long userId, Model model) {
    Restaurant restaurant = this.restaurantDao.findRestaurant(id);
    UserAccount account = this.userAccountDao.findUserAccount(userId);
    account.getFavorites().add(restaurant);
    this.userAccountDao.persist(account);
    addDateTimeFormatPatterns(model);
    model.addAttribute("useraccount", account);
    model.addAttribute("itemId", id);
    return "redirect:/useraccounts/" + account.getId();
}
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