diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index 122e63a..b25a3cd 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java @@ -18,14 +18,16 @@ } //本の一覧を返す - public HashMap getBooks(String accountId) + public HashMap getBooks(String accountId, String token) { + if(!accountManager.checkToken(accountId, token)) return null; //tokenが違う時に返す return booksMap.get(accountId); } //本の新規作成 - public int createBook(String accountId, String title, String color, Boolean publicity) + public int createBook(String accountId, String title, String color, Boolean publicity, String token) { + if(!accountManager.checkToken(accountId, token)) return 0; //tokenが違う時に返す if(!booksMap.containsKey(accountId)){ booksMap.put(accountId, new HashMap<>()); } @@ -37,48 +39,55 @@ } //本の情報を取得 - public Book getBook(String accountId, Integer bookId) + public Book getBook(String accountId, Integer bookId, String token) { + if(!accountManager.checkToken(accountId, token)) return null; //tokenが違う時に返す return booksMap.get(accountId).get(bookId); } //本の削除 - public void deleteBook(String accountId, Integer bookId) + public void deleteBook(String accountId, Integer bookId, String token) { + if(!accountManager.checkToken(accountId, token)) return; //tokenが違う時に返す booksMap.get(accountId).remove(bookId); } //((( いいねは省略 ))) //本のタイトルを返す - public String getTitle(String accountId, Integer bookId) + public String getTitle(String accountId, Integer bookId, String token) { + if(!accountManager.checkToken(accountId, token)) return null; //tokenが違う時に返す return booksMap.get(accountId).get(bookId).getTitle(); } //本のタイトルを変更 - public void putTitle(String accountId, Integer bookId, String title) + public void putTitle(String accountId, Integer bookId, String title, String token) { + if(!accountManager.checkToken(accountId, token)) return; //tokenが違う時に返す booksMap.get(accountId).get(bookId).setTitle(title); } //本の公開情報を返す - public Boolean getPublicity(String accountId, Integer bookId) + public Boolean getPublicity(String accountId, Integer bookId, String token) { + if(!accountManager.checkToken(accountId, token)) return null; //tokenが違う時に返す return booksMap.get(accountId).get(bookId).getPublicity(); } //公開情報を変更する - public void putPublicity(String accountId, Integer bookId, Boolean publicity) + public void putPublicity(String accountId, Integer bookId, Boolean publicity, String token) { + if(!accountManager.checkToken(accountId, token)) return; //tokenが違う時に返す booksMap.get(accountId).get(bookId).setPublicity(publicity); } //((( 目標・振り返りは省略 ))) //本の色を変更する - public void putColor(String accountId, Integer bookId, String color) + public void putColor(String accountId, Integer bookId, String color, String token) { + if(!accountManager.checkToken(accountId, token)) return; //tokenが違う時に返す booksMap.get(accountId).get(bookId).setColor(color); } } diff --git a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java index b462fb7..425033f 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java @@ -37,35 +37,38 @@ return token; } - - -////////// - @Path("/{account_id}") // 指定されたアカウントの情報を返す(GET) + @Path("/{account_id}") @GET @Produces(MediaType.APPLICATION_JSON) public Account getAccountInfo(@PathParam("account_id") String accountId){ //account_idを渡してManegerから値が返ってくる Account ac = accountManager.getAccount(accountId); return ac; } + // アカウント情報を全削除する(DELETE) - // @DELETE + @Path("/{account_id}") + @DELETE + public void deleteAccount(@PathParam("account_id") String accountId, + @QueryParam("token") String token, + @QueryParam("password")String password) { + accountManager.deleteAccount(accountId, token, password); + } -// @Path("/{account_id}/password") -// //指定されたIDのパスワードを変更する (PUT) -// @PUT -// public void changePassword(@PathParam("account_id") String accountId, -// @QueryParam("token") String token, -// @PathParam("old_password")String oldPassword, -// @PathParam("new_password")String newPassword){ //account_idを渡してManegerから値が返ってくる -// return accountManager.changePassword(accountId,token,oldPassword,newPassword); -// -// } + //指定されたIDのパスワードを変更する (PUT) + @Path("/{account_id}/password") + @PUT + public void changePassword(@PathParam("account_id") String accountId, + @QueryParam("token") String token, + @FormParam("old_password")String oldPassword, + @FormParam("new_password")String newPassword){ + accountManager.changePassword(accountId,token,oldPassword,newPassword); -///////// - @Path("/accounts/{account_id}/introduction") + } + // 指定されたIDの自己紹介を返す(GET) + @Path("/accounts/{account_id}/introduction") @GET @Produces(MediaType.APPLICATION_JSON) public String getIntroduction(@PathParam("account_id") String accountId){ //account_idを渡してintroductionが返ってくる @@ -73,10 +76,14 @@ return ac; } - -// 指定されたIDの自己紹介を変更する (PUT) -// @PUT - + // 指定されたIDの自己紹介を変更する (PUT) + @Path("/accounts/{account_id}/introduction") + @PUT + public void changeIntroduction(@PathParam("account_id") String accountId, + @FormParam("token") String token, + @FormParam("introduction")String introduction){ //account_idを渡してManegerから値が返ってくる + accountManager.changeIntroduction(accountId,token,introduction); +} ///////// // @Path("/accounts/{account_id}/photo") // //画像を返す @@ -88,18 +95,17 @@ // // @PUT -///////// - @Path("/accounts/{account_id}/favorites") + //指定されたIDのお気に入りの本のリストを返す + @Path("/accounts/{account_id}/favorites") @GET @Produces(MediaType.APPLICATION_JSON) public ArrayList> favoriteBook(@PathParam("account_id") String accountId, @QueryParam("token")String token){ return accountManager.Favorites(accountId,token); } -//////// - @Path("/accounts/{account_id}/favorites/{other_account_id}") //指定されたIDのお気に入りの本のリストを返す(指定した人物) + @Path("/accounts/{account_id}/favorites/{other_account_id}") @GET @Produces(MediaType.APPLICATION_JSON) public ArrayList FavoriteBook(@PathParam("account_id") String accountId,@PathParam("other_account_id") String otherAccountId,@QueryParam("token")String token){ //account_idを渡してManegerから値が返ってくる @@ -107,13 +113,13 @@ } ////////// - +// お気に入りの本のbook_idを削除する (DELETE) // @Path("/accounts/{account_id}/favorites/{other_account_id}/{book_id}") - // お気に入りの本のbook_idを削除する (DELETE) // @DELETE // いいねした本のアカウントIDとbook_idを追加する(いいねした側に追加) (PUT) -// @PUT + //@Path("/accounts/{account_id}/favorites/{other_account_id}/{book_id}") +// @PUT diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index badab34..daefeea 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -14,80 +14,89 @@ @Component -public class BooksRest {//BookRestはクラス +public class BooksRest { // BookRestはクラス private final BookManager bookManager; - @Autowired //スプリングブートにいうサイン + @Autowired // スプリングブートにいうサイン public BooksRest(BookManager bm){ //public クラス名()がコンストラクタ bookManager = bm; } -/// {account_id}/books private final HashMap> books = new HashMap<>(); - +/// {account_id}/books /// その人の本のタイトルとかを返す @Path("/{account_id}/books") @GET @Produces(MediaType.APPLICATION_JSON) - public HashMap getBooks(@PathParam("account_id") String account_id){ - return bookManager.getBooks(account_id); + public HashMap getBooks(@PathParam("account_id") String account_id, @QueryParam("token") String token){ + return bookManager.getBooks(account_id, token); } @Path("/{account_id}/books") @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//bodyに入力する値がある時 - public int createBook(@PathParam("account_id") String account_id, @FormParam("title") String title, @FormParam("color") String color, @FormParam("publicity") Boolean publicity) { - return bookManager.createBook(account_id, title, color, publicity); + public int createBook(@PathParam("account_id") String account_id, @FormParam("title") String title, @FormParam("color") String color, @FormParam("publicity") Boolean publicity, @QueryParam("token") String token) { + return bookManager.createBook(account_id, title, color, publicity, token); } /// {account_id}/books/{book_id} - @Path("/{account_id}/books/{book_id}") - /// 本の情報を取得 + @Path("/{account_id}/books/{book_id}") @GET @Produces(MediaType.APPLICATION_JSON) - public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ - return bookManager.getBook(account_id, book_id); + public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ + return bookManager.getBook(account_id, book_id, token); + } + /// 本の削除 + @Path("/{account_id}/books/{book_id}") + @DELETE + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void deleteTodoById(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ + bookManager.deleteBook(account_id, book_id, token); } -///// /{account_id}/books/{book_id}/favorited -// @Path("/{account_id}/books/{book_id}/favorited") -// -// /// いいねしたアカウントを返す -// @GET -// @Produces(MediaType.APPLICATION_JSON) -// public Book g(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ -// Book book = bookManager.getBook(account_id, book_id); -// return book; -// } - - /// /{account_id}/books/{book_id}/title - @Path("/{account_id}/books/{book_id}/title") - /// 本のタイトルを返す + @Path("/{account_id}/books/{book_id}/title") @GET @Produces(MediaType.TEXT_PLAIN) - public String getTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ - return bookManager.getTitle(account_id, book_id); + public String getTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ + return bookManager.getTitle(account_id, book_id, token); + } + + /// 本のタイトル変更 + @Path("/{account_id}/books/{book_id}/title") + @PUT + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void putTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("title") String title, @QueryParam("token") String token){ + bookManager.putTitle(account_id, book_id, title, token); } /// /accounts/{account_id}/books/{book_id}/public - @Path("/{account_id}/books/{book_id}/public") - /// 本の公開状態を返す + @Path("/{account_id}/books/{book_id}/public") @GET @Produces(MediaType.TEXT_PLAIN) - public Boolean getPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ - return bookManager.getPublicity(account_id, book_id); + public Boolean getPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ + return bookManager.getPublicity(account_id, book_id, token); } + /// 公開情報を変更する + @Path("/{account_id}/books/{book_id}/public") + @PUT + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void putPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("publicity") Boolean publicity, @QueryParam("token") String token){ + bookManager.putPublicity(account_id, book_id, publicity, token); + } - - - - - +/// /accounts/{account_id}/books/{book_id}/color + /// 公開情報を変更する + @Path("/{account_id}/books/{book_id}/color") + @PUT + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void putColor(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("color") String color, @QueryParam("token") String token){ + bookManager.putColor(account_id, book_id, color, token); + } } \ No newline at end of file diff --git a/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java b/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java index b3adde7..d953d28 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java @@ -69,9 +69,8 @@ @POST @Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public void createTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @FormParam("title") String title,@QueryParam("token") String token) { - todoManager.createTodo(account_id, book_id, year, month, day, title,token); - + public int createTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @FormParam("title") String title,@QueryParam("token") String token) { + return todoManager.createTodo(account_id, book_id, year, month, day, title,token); } //todoを選んで達成状態を変更する