diff --git a/src/main/java/org/ntlab/citrusserver/entities/Book.java b/src/main/java/org/ntlab/citrusserver/entities/Book.java index c182121..c68c40e 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Book.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Book.java @@ -17,7 +17,7 @@ this.title = title; this.publicity = publicity; this.color = color; - + this.time = time; } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index ecf2664..b5937f1 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java @@ -32,14 +32,12 @@ //本の一覧を返す public HashMap getBooks(String accountId) { - if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない return booksMap.get(accountId); } //本の新規作成 public Book createBook(String accountId, String title, String color, Boolean publicity) { - if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない if(!booksMap.containsKey(accountId)){ booksMap.put(accountId, new HashMap<>()); } @@ -54,19 +52,13 @@ //本の情報を取得 public Book getBook(String accountId, Integer bookId) { - if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない return booksMap.get(accountId).get(bookId); } //本の削除 - public int deleteBook(String accountId, Integer bookId) + public void deleteBook(String accountId, Integer bookId) { - if(accountManager.getAccount(accountId) == null) return -1; //アカウントが存在しない - else - { - booksMap.get(accountId).remove(bookId); - return 1; - } + booksMap.get(accountId).remove(bookId); } //((( いいねは省略 ))) @@ -79,51 +71,39 @@ } //本のタイトルを変更 - public int putTitle(String accountId, Integer bookId, String title) + public void putTitle(String accountId, Integer bookId, String title) { - if(accountManager.getAccount(accountId) == null) return -1; //アカウントが存在しない - else - { booksMap.get(accountId).get(bookId).setTitle(title); - return 1; - } - } //本の公開情報を返す public Boolean getPublicity(String accountId, Integer bookId) { - if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない return booksMap.get(accountId).get(bookId).getPublicity(); } //公開情報を変更する - public int putPublicity(String accountId, Integer bookId, Boolean publicity) + public void putPublicity(String accountId, Integer bookId, Boolean publicity) { Account account = accountManager.getAccount(accountId); Book book = booksMap.get(accountId).get(bookId); - if(account == null) return -1; //アカウントが存在しない - else - { - if(book.getPublicity() == publicity) return 1;//変更が無ければ終了 - book.setPublicity(publicity); - notifyListener(account, book); - return 1; - } + if(book.getPublicity() == publicity) return;//変更が無ければ終了 + book.setPublicity(publicity); + notifyListener(account, book); + + } + + public void deleteAllBooks(String accountId) + { + booksMap.remove(accountId); } //((( 目標・振り返りは省略 ))) //本の色を変更する - public int putColor(String accountId, Integer bookId, String color) + public void putColor(String accountId, Integer bookId, String color) { - if(accountManager.getAccount(accountId) == null) return -1; //アカウントが存在しない - else - { booksMap.get(accountId).get(bookId).setColor(color); - return 1; - } - } //--------------------------------------------------------------------------------- diff --git a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java new file mode 100644 index 0000000..b3b0e12 --- /dev/null +++ b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java @@ -0,0 +1,79 @@ +package org.ntlab.citrusserver.repositories; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.HashMap; +import java.util.HashSet; + + +import java.util.HashMap; +import java.util.HashSet; + +@Repository +public class FavoriteManager { + private final AccountManager accountManager; + + @Autowired + public FavoriteManager(AccountManager accountManager) { + this.accountManager = accountManager; + } + + private final HashMap>> //otheraccounts + favoritedMap = new HashMap<>(); + + + //book_idをいいねしたaccount_idをリストとして返す + public HashSet getFavorited(String accountId, int bookId) { + if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない + + return favoritedMap.get(accountId).get(bookId); + } + + //other_account_idの人がaccount_idのbook_idにいいねをした時 + public void putFavorited(String accountId, int bookId, String otherAccountId) { + favoritedMap.get(accountId).get(bookId).add(otherAccountId); + } + + //イイねしたaccount_idをイイねした人リストから削除 + public void removeFavorited(String accountId, int bookId, String otherAccountId) { + favoritedMap.get(accountId).get(bookId).remove(otherAccountId); + } + + + + + HashMap>> favoritesMap = new HashMap(); + + + //いいねした本の一覧を返す + public HashMap> getFavorites(String accountId) { + if(accountManager.getAccount(accountId) == null) return null; + return favoritesMap.get(accountId); + } + + //取得したotherAccountIdのいいねした本を返す + public HashSet getFavoritesByID(String accountId, String otherAccountId) { + if(accountManager.getAccount(accountId) == null) return null; + if(!favoritesMap.get(accountId).containsKey(otherAccountId)) return null; + return favoritesMap.get(accountId).get(otherAccountId); + } + + //いいねした本を追加する + public void putFavorites(String accountId, String otherAccountId, Integer bookId) { + if(!favoritesMap.containsKey(accountId)){ + favoritesMap.put(accountId, new HashMap<>()); + } + if(!favoritesMap.get(accountId).containsKey(otherAccountId)){ + favoritesMap.get(accountId).put(otherAccountId, new HashSet<>()); + } + favoritesMap.get(accountId).get(otherAccountId).add(bookId); + + } + //いいねした本を消去する + public void removeFavorites(String accountId, String otherAccountId, Integer bookId) { + favoritesMap.get(accountId).get(otherAccountId).remove(bookId); + } + +} diff --git a/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java index b6452cb..fb9717b 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java @@ -4,22 +4,17 @@ import org.ntlab.citrusserver.entities.Book; import org.springframework.stereotype.Repository; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; +import java.util.*; import java.util.regex.*; @Repository public class PublicBookManager implements IBookListener{ - private final BookManager bookManager; - private final HashMap> publicBooks = new HashMap<>(); public PublicBookManager(BookManager bookManager) { - this.bookManager = bookManager; - this.bookManager.addListener(this); + bookManager.addListener(this); } public ArrayList getAllPublicBooks(){ @@ -30,6 +25,15 @@ return books; } + public ArrayList getAllPublicBooks(int sortBy){ + if(sortBy == 0){ + ArrayList books = getAllPublicBooks(); + books.sort(Comparator.comparing(Book::getTime).reversed()); + return books; + } + return null; + } + public ArrayList searchBooksByTitle(String title){ ArrayList books = new ArrayList<>(); var ptn = Pattern.compile(title); @@ -43,7 +47,13 @@ return books; } + public ArrayList searchBooksByTitle(String title, int sortBy){ + if(sortBy == 0){ + ArrayList result = searchBooksByTitle(title); + result.sort(Comparator.comparing(Book::getTime).reversed()); + return result; + } return null; } @@ -60,17 +70,32 @@ } public ArrayList searchBooksByAccount(String accountId, int sortBy){ + if(sortBy == 0){ + ArrayList result = searchBooksByAccount(accountId); + result.sort(Comparator.comparing(Book::getTime).reversed()); + return result; + } return null; } public ArrayList searchBooksByTitleAndAccount(String title, String accountId){ ArrayList books = searchBooksByTitle(title); + ArrayList result = new ArrayList<>(); for(Book book : books){ if(book.getAccountId().equals(accountId)){ - books.add(book); + result.add(book); } } - return books; + return result; + } + + public ArrayList searchBooksByTitleAndAccount(String title, String accountId, int sortBy){ + if (sortBy == 0) { + ArrayList result = searchBooksByTitleAndAccount(title, accountId); + result.sort(Comparator.comparing(Book::getTime).reversed()); + return result; + } + return null; } @Override @@ -81,7 +106,9 @@ } this.publicBooks.get(account.getId()).add(book); } else{ - this.publicBooks.get(account.getId()).remove(book); + if(publicBooks.containsKey(account.getId())){ + this.publicBooks.get(account.getId()).remove(book); + } } } } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java index 31b4055..18913c6 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java @@ -12,13 +12,13 @@ @Repository public class ScheduleManager { - private final AccountManager accountManager; //仮 + private final BookManager bookManager; private final HashMap nextScheduleId = new HashMap<>(); @Autowired - public ScheduleManager(AccountManager accountManager) { - this.accountManager = accountManager; + public ScheduleManager(BookManager bookManager) { + this.bookManager = bookManager; } //管理 @@ -46,7 +46,12 @@ return schedules.get(accountId).get(year).get(month).get(day); } - public Schedule addSchedule(String accountId, int year, int month, int day, String title, String startTime, String endTime, int bookId){ + public Schedule addSchedule(String accountId, int year, int month, int day, String title, String startTime, String endTime, Integer bookId){ + if(bookId == null || bookId.equals(0)){ + bookId = 0; + } + else if(!bookManager.getBooks(accountId).containsKey(bookId))return null; + if(!schedules.containsKey(accountId)){ schedules.put(accountId, new HashMap<>()); } @@ -92,7 +97,32 @@ schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setTitle(newTitle); } - public void setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, int newBookId){ + //voidからintに変更 1で成功 -1でエラー処理 + public int setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, Integer newBookId){ + if(newBookId == null || newBookId.equals(0)){ + newBookId = 0; + } + else if(!bookManager.getBooks(accountId).containsKey(newBookId))return -1; schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setBookId(newBookId); + + return 1; + } + + public void deleteSchedules(String accountId){ + schedules.remove(accountId); + } + + public void deleteScheduleBookId(String accountId, Integer bookId){ + for(int year : schedules.get(accountId).keySet()){ + for (int month : schedules.get(accountId).get(year).keySet()){ + for(int day : schedules.get(accountId).get(year).get(month).keySet()){ + for (int scheduleId : schedules.get(accountId).get(year).get(month).get(day).keySet()){ + if(schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).getBookId().equals(bookId)){ + schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setBookId(0); + } + } + } + } + } } } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java index 4251341..6b48638 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java @@ -340,4 +340,14 @@ int day = Integer.parseInt(yearMonthDays[2]); return setCheck(accountId, bookId, year, month, day, todoId, check); } + + public void deleteAllTodosByBookId(String accountId, int bookId){ + if(todos.containsKey(accountId)){ + todos.get(accountId).remove(bookId); + } + } + public void deleteAllTodosByAccountId(String accountId){ + todos.remove(accountId); + } + } diff --git a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java index 1c958b8..dba0fae 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java @@ -4,6 +4,9 @@ import jakarta.ws.rs.core.Response; import org.ntlab.citrusserver.entities.Account; import org.ntlab.citrusserver.repositories.AccountManager; +import org.ntlab.citrusserver.repositories.BookManager; +import org.ntlab.citrusserver.repositories.ScheduleManager; +import org.ntlab.citrusserver.repositories.TodoManager; import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; @@ -17,9 +20,16 @@ public class AccountsRest { private final AccountManager accountManager; //finalは書き換えられない + private final BookManager bookManager; + private final TodoManager todoManager; + private final ScheduleManager scheduleManager; + @Autowired//springbootの決まり - public AccountsRest(AccountManager am) { + public AccountsRest(AccountManager am, BookManager bm, TodoManager tm, ScheduleManager sm) { accountManager = am; + bookManager = bm; + todoManager = tm; + scheduleManager = sm; } // アカウントの一覧をリストとして返す(GET) @@ -36,6 +46,10 @@ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//bodyに入力する値がある時 public String signup(@FormParam("account_id") String accountId, @FormParam("password") String password) { String token; + if (password == null) { + var response = Response.status(Response.Status.BAD_REQUEST).entity("passwordを入力してください"); + throw new WebApplicationException(response.build()); + } token = accountManager.createAccount(accountId, password); return token; } @@ -50,8 +64,7 @@ var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 throw new WebApplicationException(response.build()); } - Account ac = accountManager.getAccount(accountId); - return ac; + return accountManager.getAccount(accountId); } // アカウント情報を全削除する(DELETE) @@ -62,6 +75,10 @@ @QueryParam("password")String password) { if(accountManager.checkToken(accountId, token)) { accountManager.deleteAccount(accountId, token, password); + bookManager.deleteAllBooks(accountId); + todoManager.deleteAllTodosByAccountId(accountId); + scheduleManager.deleteSchedules(accountId); + return; } //404 if (!accountManager.getAccountsID().contains(accountId)){ //account_idが存在しない時 @@ -84,6 +101,7 @@ @FormParam("token") String token){ if(accountManager.checkToken(accountId, token)) { accountManager.changePassword(accountId, newPassword, oldPassword, token); + return; } //404 @@ -113,6 +131,7 @@ @FormParam("token") String token){ if(accountManager.checkToken(accountId, token)) { accountManager.changeIntroduction(accountId, introduction, token); + return; } //404 if (!accountManager.getAccountsID().contains(accountId)){ //account_idが存在しない時 diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index fe0dea4..3398b0b 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -6,6 +6,7 @@ import org.ntlab.citrusserver.entities.Book; import org.ntlab.citrusserver.repositories.AccountManager; import org.ntlab.citrusserver.repositories.BookManager; +import org.ntlab.citrusserver.repositories.TodoManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -20,11 +21,13 @@ private final BookManager bookManager; private final AccountManager accountManager; + private final TodoManager todoManager; @Autowired // スプリングブートにいうサイン - public BooksRest(BookManager bm, AccountManager ac){//public クラス名()がコンストラクタ + public BooksRest(BookManager bm, AccountManager ac, TodoManager tm){//public クラス名()がコンストラクタ bookManager = bm; accountManager = ac; + todoManager = tm; } @@ -36,7 +39,7 @@ @Produces(MediaType.APPLICATION_JSON) public HashMap getBooks(@PathParam("account_id") String account_id, @QueryParam("token") String token){ - if(bookManager.getBooks(account_id) == null){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -57,7 +60,7 @@ @Consumes(MediaType.APPLICATION_FORM_URLENCODED) // postmanのbodyに入力する値がある時 public Book createBook(@PathParam("account_id") String account_id, @FormParam("title") String title, @FormParam("color") String color, @FormParam("publicity") Boolean publicity, @FormParam("token") String token) { - if (bookManager.createBook(account_id, title, color, publicity) == null){ + if (accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -80,7 +83,7 @@ @Produces(MediaType.APPLICATION_JSON) public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if (bookManager.getBook(account_id, book_id) == null){ + if (accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -101,7 +104,7 @@ @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public String deleteBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if(bookManager.deleteBook(account_id, book_id) == -1){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -111,6 +114,8 @@ throw new WebApplicationException(response.build()); } else{ + todoManager.deleteAllTodosByBookId(account_id, book_id);//削除時、Todoも消す + bookManager.deleteBook(account_id, book_id); return "success"; } } @@ -123,7 +128,7 @@ @Produces(MediaType.TEXT_PLAIN) public String getTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if (bookManager.getTitle(account_id, book_id) == null) { + if (accountManager.getAccount(account_id) == null) { var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -133,7 +138,7 @@ throw new WebApplicationException(response.build()); } else{ - return (bookManager.getTitle(account_id, book_id)); + return bookManager.getTitle(account_id, book_id); } } } @@ -145,7 +150,7 @@ @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public String putTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("title") String title, @FormParam("token") String token){ - if(bookManager.putTitle(account_id, book_id, title) == -1){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -155,6 +160,7 @@ throw new WebApplicationException(response.build()); } else{ + bookManager.putTitle(account_id, book_id, title); return "success"; } } @@ -167,7 +173,7 @@ @Produces(MediaType.TEXT_PLAIN) public Boolean getPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if (bookManager.getPublicity(account_id, book_id) == null) { + if (accountManager.getAccount(account_id) == null) { var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -188,7 +194,8 @@ @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public String putPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("publicity") Boolean publicity, @FormParam("token") String token){ - if(bookManager.putPublicity(account_id, book_id, publicity) == -1){ + + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -198,6 +205,7 @@ throw new WebApplicationException(response.build()); } else{ + bookManager.putPublicity(account_id, book_id, publicity); return "success"; } } @@ -209,7 +217,8 @@ @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public String putColor(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("color") String color, @FormParam("token") String token){ - if(bookManager.putColor(account_id, book_id, color) == -1){ + + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -219,8 +228,14 @@ throw new WebApplicationException(response.build()); } else{ + bookManager.putColor(account_id, book_id, color); return "success"; } } } + + ///--------------------------------------------------------------------- + ///private + ///--------------------------------------------------------------------- + } \ No newline at end of file diff --git a/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java index 71ce363..8f5aac4 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java @@ -6,7 +6,6 @@ import org.ntlab.citrusserver.repositories.PublicBookManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Repository; import java.util.ArrayList; @@ -27,52 +26,34 @@ return publicBookManager.getAllPublicBooks(); } -// //検索条件を指定して本を検索(タイトル) -// @Path("/search") -// @GET -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList searchBooksByTitle(@QueryParam("search_title") String search_title) { -// return publicBookManager.searchBooksByTitle(search_title); -// } -// //検索条件を指定して本を検索(タイトル ソート可能) -// @Path("/search") -// @GET -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList searchBooksByTitle(@QueryParam("search_title") String search_title, @QueryParam("sort_by") Integer sort_by) { -// return publicBookManager.searchBooksByTitle(search_title, sort_by); -// } -// -// //検索条件を指定して本を検索(アカウント) -// @Path("/search") -// @GET -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList searchBooksByAccount(@QueryParam("search_account_id") String search_account_id) { -// return publicBookManager.searchBooksByAccount(search_account_id); -// } -// -// //検索条件を指定して本を検索(アカウント ソート可能) -// @Path("/search") -// @GET -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList searchBooksByAccount(@QueryParam("search_account_id") String search_account_id, @QueryParam("sort_by") int sort_by) { -// return publicBookManager.searchBooksByAccount(search_account_id, sort_by); -// } - - //検索条件を指定して本を検索(アカウントとタイトル) + //検索条件を指定して本を検索(アカウントかタイトルか両方) @Path("/search") @GET @Produces(MediaType.APPLICATION_JSON) - public ArrayList searchBooksByTitleAndAccount(@QueryParam("search_title") String search_title, @QueryParam("search_account_id") String search_account_id) { - if(search_title != null && search_account_id != null) { - return publicBookManager.searchBooksByTitleAndAccount(search_title, search_account_id); - } else if(search_title!= null) { - return publicBookManager.searchBooksByTitle(search_title); - } else if(search_account_id != null) { - return publicBookManager.searchBooksByAccount(search_account_id); + public ArrayList searchBooksByTitleAndAccount(@QueryParam("search_title") String search_title, @QueryParam("search_account_id") String search_account_id, + @QueryParam("sort_by") Integer sort_by) { + if(sort_by == null) { + if (search_title != null && search_account_id != null) { + return publicBookManager.searchBooksByTitleAndAccount(search_title, search_account_id); + } else if (search_title != null) { + return publicBookManager.searchBooksByTitle(search_title); + } else if (search_account_id != null) { + return publicBookManager.searchBooksByAccount(search_account_id); + } else { + return publicBookManager.getAllPublicBooks(); + } } else { - return publicBookManager.getAllPublicBooks(); + if(search_title != null && search_account_id != null) { + return publicBookManager.searchBooksByTitleAndAccount(search_title, search_account_id, sort_by); + } else if(search_title != null) { + return publicBookManager.searchBooksByTitle(search_title, sort_by); + } else if(search_account_id != null) { + return publicBookManager.searchBooksByAccount(search_account_id, sort_by); + } else { + return publicBookManager.getAllPublicBooks(); + } + } } - } }