RepositoryService.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:Smart-Shopping 作者:
/**
 * Add new shopping list for a given user
 * 
 * @param userName
 *            name of the user for which to create the new list
 * @param newListName
 *            name of the new list
 * @return newly created list
 * @throws UserNotFoundException
 *             if user with given name doesn't exist
 * @throws ListTooLongException if size of the list containing ShoppingLists would exceed limit of Short type after adding new ShoppingList
 */
@PreAuthorize("hasRole('USER')")
@Transactional(readOnly = false)
public ShoppingList addShoppingListToUserByName(String userName, String newListName) {
    LOGGER.debug("addShoppingListToUserByName: user: {}, listName: {}", userName, newListName);

    AppUser user = getUser(userName); //throws UserNotFoundException

    // get count of user lists
    short count = shoppingListRepository.countByOwnerName(userName);
    if (count == Short.MAX_VALUE)
        throw new ListTooLongException(ListTooLongException.listType.SHOPPING_LIST, user.getId());
    count++;

    ShoppingList list = user.addShoppingList(newListName, count);
    list = shoppingListRepository.save(list);

    LOGGER.info("addShoppingListToUserByName: Created new list: {}", list);
    return list;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号