diff --git a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java index 3de0d2a..8bd0e13 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java @@ -40,9 +40,9 @@ return token; } - //tokenを返す (accountIdとtokenを比較してtrueかfalseを返すように変更) - public String createToken(String accountId) { - return accountToken.get(accountId); + //accountIdとtokenを比較してtrueかfalseを返す + public boolean checkToken(String accountId, String token) { + return accountToken.get(accountId).equals(token); } // 指定されたアカウントの情報を返す(GET) @@ -62,7 +62,9 @@ // 指定されたIDのパスワードを変更する (PUT) public void changePassword(String accountId, String token, String oldPassword, String newPassword) { if(accountToken.get(accountId).equals(token)) { - + if(accounts.get(accountId).getPassword().equals(oldPassword)) { + accounts.get(accountId).setPassword(newPassword); + } } } @@ -72,8 +74,10 @@ } // 指定されたIDの自己紹介を変更する (PUT) - public void newintroduction(String accountId, String token, String introduction) { - + public void changeIntroduction(String accountId, String token, String introduction) { + if(accountToken.get(accountId).equals(token)) { + accounts.get(accountId).setIntroduction(introduction); + } } // 指定されたIDのお気に入りの本のリストを返す(GET) @@ -87,7 +91,7 @@ } // お気に入りの本のbook_idを削除する (DELETE) - public void deletefavbookid(String accountId, String token, String otherAccountId, Integer bookId) { + public void deleteFavoriteBookId(String accountId, String token, String otherAccountId, Integer bookId) { } @@ -98,6 +102,13 @@ // アカウントidとパスワードでログインし、tokenを返す (POST) public String login(String accountId, String password) { - return accountToken.get(accountId); + if(accounts.get(accountId).getPassword().equals(password)) { + UUID str = UUID.randomUUID(); + String token = str.toString(); + accountToken.put(accountId, token); + return accountToken.get(accountId); + } + return null; } + } diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index 1c7ac5d..99945c0 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -30,13 +30,9 @@ /// 本一覧を返す @GET @Produces(MediaType.APPLICATION_JSON) - public Book getBook(@PathParam("account_id") String account_id){ - Book book = bookManager.getBook(account_id); - return book; + public HashMap> getBooks(){ + return bookManager.getBooks(); } - /// 本の新規作成 - @POST - @Consumes(MediaType.APPLICATION_JSON) /// {account_id}/books/{book_id} @Path("/{account_id}/books/{book_id}") @@ -45,11 +41,9 @@ @GET @Produces(MediaType.APPLICATION_JSON) public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ - Book book = bookManager.getBook(account_id, book_id); - return book; + + return ; } - /// 本の削除 - @DELETE /// /{account_id}/books/{book_id}/favorited @Path("/{account_id}/books/{book_id}/favorited") @@ -61,13 +55,7 @@ Book book = bookManager.getBook(account_id, book_id); return book; } -/// /{account_id}/books/{book_id}/favorited/{other_account_id} - @Path("/{account_id}/books/{book_id}/favorited/{other_account_id}") - /// いいねした人を追加 - @PUT - /// いいねしたアカウントの削除 - @DELETE /// /{account_id}/books/{book_id}/title @Path("/{account_id}/books/{book_id}/title") @@ -79,8 +67,6 @@ Book book = bookManager.getBook(account_id, book_id); return book; } - /// 本のタイトル変更 - @PUT /// /accounts/{account_id}/books/{book_id}/public @Path("/{account_id}/books/{book_id}/public") @@ -92,13 +78,7 @@ Book book = bookManager.getBook(account_id, book_id); return book; } - /// 公開状態を変更する - @PUT -/// /accounts/{account_id}/books/{book_id}/goals/{year}/{month} - @Path("/accounts/{account_id}/books/{book_id}/goals/{year}/{month}") - - ///