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);
}
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);*/
}
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";
}
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";
}
}
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();
}
Aggregations