Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ahan10 committed Mar 11, 2024
2 parents a923008 + 78636bb commit ceebfa5
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 69 deletions.
1 change: 1 addition & 0 deletions LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,4 @@
Ahan: Converted postgresql data to json files, finished CommentStubDB.java implementation and added more tests for CommentDaoImpl.java. Also updated ReadMe/ Wiki with updated feature list and latest screenshots.
Eric: Added ability for user to navigate to comic book pgae by clicking on comic book in their reading / read table in profile
Oscar: Finished implementing cancel button for "About Me" section and created test case for updating the field in database.
Hashir: Final touches for submission criteria for ITR2 + adding more tests for stories and integration + refactoring
Binary file not shown.
44 changes: 0 additions & 44 deletions src/main/java/org/longbox/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,5 @@

public class Main {
public static void main(String[] args) {
// This entry point is used to test methods informally and
// build stub database entries for the JSON files used with GSON
// sample code is shown below in the two comment blocks.
/* UserDaoImpl u = new UserDaoImpl();
ComicBookDaoImpl cb = new ComicBookDaoImpl();
ComicBook cbdto = cb.getComicBookById(5);
User user;
ComicBookFinishedListDaoImpl finishedListDao = new ComicBookFinishedListDaoImpl();*/

/* try {
user = u.getUserById(2);
System.out.println(user);
} catch (UserIDDoesNotExistException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
boolean success;
try {
success = finishedListDao.saveToFinished(user, cbdto);
System.out.println(success);
} catch (UserIDDoesNotExistException e) {
e.printStackTrace();
throw new RuntimeException(e);
}*/

/* int result;
try {
finishedListDao.removeFromFinished(Long.valueOf(2),Long.valueOf(3));
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
System.out.println(finishedListDao.getUsersFinishedList(Long.valueOf(2)));*/


}
}
1 change: 0 additions & 1 deletion src/main/java/org/longbox/config/HibernateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ public static SessionFactory getSessionFactory() {
}
return sessionFactory;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface ComicBookFavouritesListDao {

void removeFromFavorites(long userId, long comicBookId);

boolean doesRecordExist(Long userId, Long comicBookId);

List<ComicBook> getFavoritesByUser(long userId);

List<User> getUsersByComicBook(long comicBookId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public void removeFromFavorites(long userId, long comicBookId) {
}
}

public boolean doesRecordExist(Long userId, Long comicBookId) {
Session session = sessionFactory.openSession();
Query<Long> query = session.createQuery(
"SELECT COUNT(*) FROM ComicBookFavoritesList c WHERE c.user.id = :userId AND c.comicBook.id = :comicBookId", Long.class);
query.setParameter("userId", userId);
query.setParameter("comicBookId", comicBookId);
Long count = query.uniqueResult();
return count != null && count > 0;
}

@Override
public List<ComicBook> getFavoritesByUser(long userId) {
// Implement retrieving favorite comic books for a given user from the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public void removeFromFavorites(long userId, long comicBookId) {
serializeStubData();
}

@Override
public boolean doesRecordExist(Long userId, Long comicBookId) {
return false;
}

@Override
public List<ComicBook> getFavoritesByUser(long userId) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.io.PrintStream;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
public class ComicBookFinishedListStubDb implements ComicBookFinishedListDao, JsonConvertor {
Expand All @@ -37,7 +39,7 @@ public void saveToFinished(Long userId, Long comicBookId) throws UserIDDoesNotEx
public void removeFromFinished(Long userId, Long comicBookId) {
List<ComicBookListItemFinishedDto> finishedList = deserializeStubData(ABSOLUTE_FILE_PATH);
for (int i = 0; i < finishedList.size(); i++) {
if (finishedList.get(i).getUserId() == userId && finishedList.get(i).getComicBookId() == comicBookId) {
if (Objects.equals(finishedList.get(i).getUserId(), userId) && Objects.equals(finishedList.get(i).getComicBookId(), comicBookId)) {
finishedList.remove(i);
}
}
Expand All @@ -47,6 +49,12 @@ public void removeFromFinished(Long userId, Long comicBookId) {

@Override
public boolean doesRecordExist(Long userId, Long comicBookId) {
List<ComicBookListItemFinishedDto> finishedList = deserializeStubData(ABSOLUTE_FILE_PATH);
for (ComicBookListItemFinishedDto record : finishedList) {
if (Objects.equals(record.getUserId(), userId) && Objects.equals(record.getComicBookId(), comicBookId)) {
return true;
}
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.longbox.persistence.stubdatabase;

public class UserStubDbTest {
}
116 changes: 97 additions & 19 deletions src/main/resources/ComicBookReadingListStubDb.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,97 @@
[{"user_id":6,"comic_book_id":1,"date_started":"2024-03-10T18:08:54.959"},
{"user_id":6,"comic_book_id":10,"date_started":"2024-03-10T18:09:11.459"},
{"user_id":6,"comic_book_id":21,"date_started":"2024-03-10T18:09:24.145"},
{"user_id":6,"comic_book_id":27,"date_started":"2024-03-10T18:09:28.183"},
{"user_id":1,"comic_book_id":5,"date_started":"2024-03-10T18:10:02.415"},
{"user_id":1,"comic_book_id":19,"date_started":"2024-03-10T18:10:22.265"},
{"user_id":1,"comic_book_id":24,"date_started":"2024-03-10T18:10:28.782"},
{"user_id":1,"comic_book_id":35,"date_started":"2024-03-10T18:10:44.147"},
{"user_id":4,"comic_book_id":5,"date_started":"2024-03-10T18:11:25.824"},
{"user_id":4,"comic_book_id":16,"date_started":"2024-03-10T18:11:34.679"},
{"user_id":4,"comic_book_id":24,"date_started":"2024-03-10T18:11:38.495"},
{"user_id":4,"comic_book_id":33,"date_started":"2024-03-10T18:11:53.08"},
{"user_id":2,"comic_book_id":15,"date_started":"2024-03-10T18:12:57.025"},
{"user_id":2,"comic_book_id":22,"date_started":"2024-03-10T18:13:00.802"},
{"user_id":2,"comic_book_id":8,"date_started":"2024-03-10T18:13:15.79"},
{"user_id":3,"comic_book_id":7,"date_started":"2024-03-10T18:13:55.67"},
{"user_id":3,"comic_book_id":18,"date_started":"2024-03-10T18:14:05.857"},
{"user_id":3,"comic_book_id":25,"date_started":"2024-03-10T18:14:13.846"},
{"user_id":3,"comic_book_id":31,"date_started":"2024-03-10T18:14:16.45"}]
[
{
"user_id": 6,
"comic_book_id": 1,
"date_started": "2024-03-10T18:08:54.959"
},
{
"user_id": 6,
"comic_book_id": 10,
"date_started": "2024-03-10T18:09:11.459"
},
{
"user_id": 6,
"comic_book_id": 21,
"date_started": "2024-03-10T18:09:24.145"
},
{
"user_id": 6,
"comic_book_id": 27,
"date_started": "2024-03-10T18:09:28.183"
},
{
"user_id": 1,
"comic_book_id": 5,
"date_started": "2024-03-10T18:10:02.415"
},
{
"user_id": 1,
"comic_book_id": 19,
"date_started": "2024-03-10T18:10:22.265"
},
{
"user_id": 1,
"comic_book_id": 24,
"date_started": "2024-03-10T18:10:28.782"
},
{
"user_id": 1,
"comic_book_id": 35,
"date_started": "2024-03-10T18:10:44.147"
},
{
"user_id": 4,
"comic_book_id": 5,
"date_started": "2024-03-10T18:11:25.824"
},
{
"user_id": 4,
"comic_book_id": 16,
"date_started": "2024-03-10T18:11:34.679"
},
{
"user_id": 4,
"comic_book_id": 24,
"date_started": "2024-03-10T18:11:38.495"
},
{
"user_id": 4,
"comic_book_id": 33,
"date_started": "2024-03-10T18:11:53.08"
},
{
"user_id": 2,
"comic_book_id": 15,
"date_started": "2024-03-10T18:12:57.025"
},
{
"user_id": 2,
"comic_book_id": 22,
"date_started": "2024-03-10T18:13:00.802"
},
{
"user_id": 2,
"comic_book_id": 8,
"date_started": "2024-03-10T18:13:15.79"
},
{
"user_id": 3,
"comic_book_id": 7,
"date_started": "2024-03-10T18:13:55.67"
},
{
"user_id": 3,
"comic_book_id": 18,
"date_started": "2024-03-10T18:14:05.857"
},
{
"user_id": 3,
"comic_book_id": 25,
"date_started": "2024-03-10T18:14:13.846"
},
{
"user_id": 3,
"comic_book_id": 31,
"date_started": "2024-03-10T18:14:16.45"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.longbox.integration.persistence.dao;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.longbox.businesslogic.exception.UserIDDoesNotExistException;
import org.longbox.persistence.dao.ComicBookFavouritesListDaoImpl;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ComicBookFavoritesListDaoImplTest {

ComicBookFavouritesListDaoImpl favouritesListDao;

@BeforeEach
void setup() {
favouritesListDao = new ComicBookFavouritesListDaoImpl();
favouritesListDao.removeFromFavorites(5L,30L);
}

@Test
void saveToFavoritesTest() {
try {
favouritesListDao.removeFromFavorites(6L,20L);
favouritesListDao.saveToFavorites(6L,20L);
} catch (UserIDDoesNotExistException e) {
throw new RuntimeException(e);
}
assertTrue(favouritesListDao.doesRecordExist(6L,20L));
}

@Test
void removeFromFavoritesTest() {
try {
favouritesListDao.saveToFavorites(5L,30L);
favouritesListDao.removeFromFavorites(5L,30L);
} catch (UserIDDoesNotExistException e) {
throw new RuntimeException(e);
}
assertFalse(favouritesListDao.doesRecordExist(5L,30L));
}

@Test
void doesRecordExistTest() {
assertFalse(favouritesListDao.doesRecordExist(5L,30L));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.longbox.integration.persistence.dao;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.longbox.businesslogic.exception.UserIDDoesNotExistException;
import org.longbox.persistence.dao.ComicBookFinishedListDaoImpl;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ComicBookFinishedListDaoImplTest {
ComicBookFinishedListDaoImpl finishedListDao;

@BeforeEach
void setup() {
finishedListDao = new ComicBookFinishedListDaoImpl();
}

/*
* This test should always pass
* The first run will not have an exception
* The second run will not insert as it is already inserted but insertion will pass
*/
@Test
void saveToFinishedTest() {
Long userId = 1L;
Long comicId = 1L;
try {
finishedListDao.removeFromFinished(userId,comicId);
finishedListDao.saveToFinished(userId, comicId);
} catch (UserIDDoesNotExistException e) {
throw new RuntimeException(e);
}
assertTrue(finishedListDao.doesRecordExist(userId,comicId));
}

/*
* This test should always pass
* The first run will not have an exception
* The second run will not insert as it is already inserted but insertion will pass
*/
@Test
void removeFromFinishedTest() {
Long userId = 1L;
Long comicId = 1L;
try {
finishedListDao.saveToFinished(userId, comicId);
finishedListDao.removeFromFinished(userId,comicId);
} catch (UserIDDoesNotExistException e) {
throw new RuntimeException(e);
}
assertFalse(finishedListDao.doesRecordExist(userId,comicId));
}

@Test
void removeFromFinishedListNoRecord() {
Long userId = 20L;
Long comicId = 100L;
finishedListDao.removeFromFinished(userId,comicId);
assertTrue(true);
}

@Test
void doesRecordExistNoRecord() {
Long userId = 20L;
Long comicId = 100L;
assertFalse(finishedListDao.doesRecordExist(userId,comicId));
}

}
Loading

0 comments on commit ceebfa5

Please sign in to comment.