diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index ecf2664..eb656ad 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,34 @@ } //本のタイトルを変更 - 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 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/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index 3386151..6289f93 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -36,8 +36,7 @@ @Produces(MediaType.APPLICATION_JSON) public HashMap getBooks(@PathParam("account_id") String account_id, @QueryParam("token") String token){ - HashMap books = bookManager.getBooks(account_id); - if(books == null){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -47,7 +46,7 @@ throw new WebApplicationException(response.build()); } else{ - return books; + return bookManager.getBooks(account_id); } } } @@ -58,8 +57,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) { - Book book = bookManager.createBook(account_id, title, color, publicity); - if (book == null){ + if (accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -69,7 +67,7 @@ throw new WebApplicationException(response.build()); } else { - return book; + return bookManager.createBook(account_id, title, color, publicity); } } } @@ -82,8 +80,7 @@ @Produces(MediaType.APPLICATION_JSON) public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - Book book = bookManager.getBook(account_id, book_id); - if (book == null){ + if (accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -93,7 +90,7 @@ throw new WebApplicationException(response.build()); } else{ - return book; + return bookManager.getBook(account_id, book_id); } } } @@ -104,8 +101,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){ - int check = bookManager.deleteBook(account_id, book_id); - if(check == -1){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -115,6 +111,7 @@ throw new WebApplicationException(response.build()); } else{ + bookManager.deleteBook(account_id, book_id); return "success"; } } @@ -127,8 +124,7 @@ @Produces(MediaType.TEXT_PLAIN) public String getTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - String str = bookManager.getTitle(account_id, book_id); - if (str == null) { + if (accountManager.getAccount(account_id) == null) { var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -138,7 +134,7 @@ throw new WebApplicationException(response.build()); } else{ - return str; + return bookManager.getTitle(account_id, book_id); } } } @@ -150,8 +146,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){ - int check = bookManager.putTitle(account_id, book_id, title); - if(check == -1){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -161,6 +156,7 @@ throw new WebApplicationException(response.build()); } else{ + bookManager.putTitle(account_id, book_id, title); return "success"; } } @@ -173,8 +169,7 @@ @Produces(MediaType.TEXT_PLAIN) public Boolean getPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - Boolean publicity = bookManager.getPublicity(account_id, book_id); - if (publicity == null) { + if (accountManager.getAccount(account_id) == null) { var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -184,7 +179,7 @@ throw new WebApplicationException(response.build()); } else{ - return publicity; + return bookManager.getPublicity(account_id, book_id); } } } @@ -196,8 +191,7 @@ @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){ - int check = bookManager.putPublicity(account_id, book_id, publicity); - if(check == -1){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -207,6 +201,7 @@ throw new WebApplicationException(response.build()); } else{ + bookManager.putPublicity(account_id, book_id, publicity); return "success"; } } @@ -219,8 +214,7 @@ @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){ - int check = bookManager.putColor(account_id, book_id, color); - if(check == -1){ + if(accountManager.getAccount(account_id) == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -230,6 +224,7 @@ throw new WebApplicationException(response.build()); } else{ + bookManager.putColor(account_id, book_id, color); return "success"; } }