From fa398dd4747a2e9fde8e760d7d34cfb290fe4880 Mon Sep 17 00:00:00 2001 From: Tyler Tanner Date: Fri, 28 Oct 2022 12:38:39 -0500 Subject: [PATCH] Fixed BCRL creation bug --- .../controllers/ReadingListController.java | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/ClubIndex/src/main/java/com/skilldistillery/jpaclubindex/controllers/ReadingListController.java b/ClubIndex/src/main/java/com/skilldistillery/jpaclubindex/controllers/ReadingListController.java index 24f75ae..57e4a3a 100644 --- a/ClubIndex/src/main/java/com/skilldistillery/jpaclubindex/controllers/ReadingListController.java +++ b/ClubIndex/src/main/java/com/skilldistillery/jpaclubindex/controllers/ReadingListController.java @@ -12,6 +12,7 @@ import com.skilldistillery.jpaclubindex.data.UserDAO; import com.skilldistillery.jpaclubindex.data.UserRLDAO; import com.skilldistillery.jpaclubindex.entities.Book; +import com.skilldistillery.jpaclubindex.entities.BookClub; import com.skilldistillery.jpaclubindex.entities.BookClubReadingList; import com.skilldistillery.jpaclubindex.entities.User; import com.skilldistillery.jpaclubindex.entities.UserReadingList; @@ -63,12 +64,15 @@ public String createReadingList(HttpSession session) { @RequestMapping(path="createReadingList.do", params = "bookClubId", method=RequestMethod.POST) public String createBCRL(HttpSession session, BookClubReadingList bcrl, String firstBook, int bookClubId) { + BookClub bc = bcDao.getBookClubById(bookClubId); + bcrl.addBook(bookDao.findBookByTitle(firstBook).get(0)); - bcrl.setBookClub(bcDao.getBookClubById(bookClubId)); + bcrl.setBookClub(bc); + bc.addReadingList(bcrl); bcrl = bcrlDao.createBCRL(bcrl); - session.setAttribute("bookClub", bcDao.getBookClubById(bookClubId)); + session.setAttribute("bookClub", bc); return "redirect:createdBCRL.do"; } @@ -76,22 +80,7 @@ public String createBCRL(HttpSession session, BookClubReadingList bcrl, String f public String createdBCRL(HttpSession session) { return "bookclub/bookClub"; } - -// @RequestMapping(path="createReadingList.do", params = "userId", method=RequestMethod.POST) -// public String createUserRL(HttpSession session, UserReadingList uRL, String firstBook, int userId) { -// uRL.addBook(bookDao.findBookByTitle(firstBook).get(0)); -// uRL.setUser(userDao.findUserById(userId)); -// -// uRL = userRLDao.createUserRL(uRL); -// -// User user = userDao.findUserById(userId); -// user.setBookClubs(bcDao.getBookClubsByUser(user)); -// -// session.setAttribute("user", user); -// -// return "redirect:createdURL.do"; -// } - + @RequestMapping(path="createReadingList.do", params = "userId", method=RequestMethod.POST) public String createUserRL(HttpSession session, UserReadingList uRL, String firstBook, int userId) { User user = userDao.findUserById(userId);