diff --git a/src/main/java/org/ntlab/citrusserver/entities/Account.java b/src/main/java/org/ntlab/citrusserver/entities/Account.java index 37cbba8..0567713 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Account.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Account.java @@ -1,9 +1,14 @@ package org.ntlab.citrusserver.entities; +import com.fasterxml.jackson.annotation.JsonIgnore; + public class Account { private String introduction; + @JsonIgnore private int bookcount = 0; + @JsonIgnore private String accountId; + @JsonIgnore private String password; public Account(String aid, String pass) { @@ -13,12 +18,16 @@ public void setIntroduction(String i) {introduction = i;} public String getIntroduction() {return introduction;} + @JsonIgnore public int getNewBookId() { bookcount += 1; return bookcount; } + @JsonIgnore public int getBookCount() {return bookcount;} + public void setId(String i) {accountId = i;} + @JsonIgnore public String getId() {return accountId;} public void setPassword(String p) {password = p;} public String getPassword() {return password;} diff --git a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java index 8bd0e13..e532b24 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java @@ -14,15 +14,10 @@ @Repository public class AccountManager { - private final AccountsRest accountsRest; private HashMap accounts = new HashMap(); //keyにaccountId,valueにaccount private HashMap accountToken = new HashMap<>(); //keyがaccountId,valueがtoken - public AccountManager(AccountsRest accountsRest) { - this.accountsRest = accountsRest; - } - // アカウントの一覧をリストとして返す(GET) public Set getAccountsID() { return accounts.keySet(); diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index 779fa8b..122e63a 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java @@ -26,6 +26,9 @@ //本の新規作成 public int createBook(String accountId, String title, String color, Boolean publicity) { + if(!booksMap.containsKey(accountId)){ + booksMap.put(accountId, new HashMap<>()); + } Account account = accountManager.getAccount(accountId); //アカウントの取得 int newBookId = account.getNewBookId(); //新たに生成されたIdを取得(作成数もここで加算している) Book book = new Book(newBookId, title, publicity, color); //本の初期化 diff --git a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java index fcc7a81..b462fb7 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java @@ -20,7 +20,7 @@ accountManager = am; } - //accountの一覧を返す + // アカウントの一覧をリストとして返す(GET) @GET @Produces(MediaType.APPLICATION_JSON) public Set getAccount(){ @@ -28,7 +28,7 @@ } - //accountの新規作成 + // account_idとpasswordを設定し新しいアカウントを作成する(POST) @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//bodyに入力する値がある時 public String signup(@FormParam("account_id") String accountId, @FormParam("password") String password) { @@ -37,36 +37,44 @@ return token; } + + ////////// @Path("/{account_id}") - - //account_idの情報を返す”introduction”と[本] + // 指定されたアカウントの情報を返す(GET) @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) + // @DELETE -/////// // @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); // -// +// } + ///////// @Path("/accounts/{account_id}/introduction") - //自己紹介を返す + // 指定されたIDの自己紹介を返す(GET) @GET @Produces(MediaType.APPLICATION_JSON) - public String getAccount(@PathParam("account_id") String accountId){ //account_idを渡してintroductionが返ってくる + public String getIntroduction(@PathParam("account_id") String accountId){ //account_idを渡してintroductionが返ってくる String ac = accountManager.AccountIntro(accountId); return ac; } + +// 指定されたIDの自己紹介を変更する (PUT) // @PUT ///////// @@ -86,7 +94,7 @@ @GET @Produces(MediaType.APPLICATION_JSON) public ArrayList> favoriteBook(@PathParam("account_id") String accountId, @QueryParam("token")String token){ - return accountManager.favoriteBook(accountId,token); + return accountManager.Favorites(accountId,token); } //////// @@ -95,14 +103,23 @@ @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から値が返ってくる - return accountManager.FavoriteBook(accountId,otherAccountId,token); + return accountManager.FavoritesBookId(accountId,otherAccountId,token); } ////////// + // @Path("/accounts/{account_id}/favorites/{other_account_id}/{book_id}") + // お気に入りの本のbook_idを削除する (DELETE) // @DELETE + + // いいねした本のアカウントIDとbook_idを追加する(いいねした側に追加) (PUT) // @PUT + + + + //////// + // アカウントidとパスワードでログインし、tokenを返す (POST) // @Path("/accounts/{account_id}/login") // @POST // @Consumes(MediaType.APPLICATION_JSON) diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index 99945c0..badab34 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -14,26 +14,34 @@ @Component -public class BookRest {//BookRestはクラス +public class BooksRest {//BookRestはクラス private final BookManager bookManager; @Autowired //スプリングブートにいうサイン - public BookRest(BookManager bm){ //public クラス名()がコンストラクタ + public BooksRest(BookManager bm){ //public クラス名()がコンストラクタ bookManager = bm; } /// {account_id}/books private final HashMap> books = new HashMap<>(); - @Path("/{account_id}/books") - /// 本一覧を返す + /// その人の本のタイトルとかを返す + @Path("/{account_id}/books") @GET @Produces(MediaType.APPLICATION_JSON) - public HashMap> getBooks(){ - return bookManager.getBooks(); + public HashMap getBooks(@PathParam("account_id") String account_id){ + return bookManager.getBooks(account_id); } + @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); + } + + /// {account_id}/books/{book_id} @Path("/{account_id}/books/{book_id}") @@ -41,20 +49,19 @@ @GET @Produces(MediaType.APPLICATION_JSON) public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ - - return ; + return bookManager.getBook(account_id, book_id); } -/// /{account_id}/books/{book_id}/favorited - @Path("/{account_id}/books/{book_id}/favorited") - - /// いいねしたアカウントを返す - @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; - } +///// /{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 @@ -63,9 +70,8 @@ /// 本のタイトルを返す @GET @Produces(MediaType.TEXT_PLAIN) - 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; + public String getTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ + return bookManager.getTitle(account_id, book_id); } /// /accounts/{account_id}/books/{book_id}/public @@ -73,10 +79,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; + @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); }