diff --git a/src/main/java/org/ntlab/citrusserver/entities/Account.java b/src/main/java/org/ntlab/citrusserver/entities/Account.java index a5aa746..37cbba8 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Account.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Account.java @@ -1,10 +1,10 @@ package org.ntlab.citrusserver.entities; public class Account { - String introduction; - int bookcount = 0; - String accountId; - String password; + private String introduction; + private int bookcount = 0; + private String accountId; + private String password; public Account(String aid, String pass) { accountId = aid; diff --git a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java index 4278aac..3de0d2a 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java @@ -3,6 +3,7 @@ import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import org.ntlab.citrusserver.entities.Account; +import org.ntlab.citrusserver.resources.AccountsRest; import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; @@ -13,17 +14,22 @@ @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(); } // account_idとpasswordを設定し新しいアカウントを作成する(POST) - public String newAccount(String accountId, String password) { + public String createAccount(String accountId, String password) { UUID str = UUID.randomUUID(); String token = str.toString(); Account account = new Account(accountId, password); @@ -34,6 +40,11 @@ return token; } + //tokenを返す (accountIdとtokenを比較してtrueかfalseを返すように変更) + public String createToken(String accountId) { + return accountToken.get(accountId); + } + // 指定されたアカウントの情報を返す(GET) public Account getAccount(String accountId) { return accounts.get(accountId); @@ -41,7 +52,18 @@ // アカウント情報を全削除する(DELETE) public void deleteAccount(String accountId, String password, String token) { + if(accountToken.get(accountId).equals(token)) { + if(accounts.get(accountId).getPassword().equals(password)) { + accounts.remove(accountId); + } + } + } + // 指定されたIDのパスワードを変更する (PUT) + public void changePassword(String accountId, String token, String oldPassword, String newPassword) { + if(accountToken.get(accountId).equals(token)) { + + } } // 指定されたIDの自己紹介を返す(GET) @@ -49,38 +71,33 @@ return accounts.get(accountId).getIntroduction(); } + // 指定されたIDの自己紹介を変更する (PUT) + public void newintroduction(String accountId, String token, String introduction) { + + } + // 指定されたIDのお気に入りの本のリストを返す(GET) - public ArrayList> favoriteBook(String accountId, String token) { + public ArrayList> Favorites(String accountId, String token) { return null; } // 指定されたIDのお気に入りの本のリストを返す(指定した人物) (GET) - public ArrayList FavoriteBook(String accountId, String otherAccountId, String token) { + public ArrayList FavoritesBookId(String accountId, String otherAccountId, String token) { return null; } - // 指定されたIDのアカウントを変更する (PUT) - public void newpassword() { - - } - - // 指定されたIDの自己紹介を変更する (PUT) - public void newintro() { - - } - - // お気に入りにの本のbook_idを削除する (DELETE) - public void deletefavbook() { + // お気に入りの本のbook_idを削除する (DELETE) + public void deletefavbookid(String accountId, String token, String otherAccountId, Integer bookId) { } // いいねした本のアカウントIDとbook_idを追加する(いいねした側に追加) (PUT) - public void putfavoriteid() { + public void putfavoriteid(String accountId, String token, String otherAccountId, Integer bookId) { } // アカウントidとパスワードでログインし、tokenを返す (POST) - public void login() { - + public String login(String accountId, String password) { + return accountToken.get(accountId); } } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index af3fb10..779fa8b 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java @@ -18,9 +18,9 @@ } //本の一覧を返す - public HashMap> getBooks() + public HashMap getBooks(String accountId) { - return booksMap; + return booksMap.get(accountId); } //本の新規作成 diff --git a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java index c6d54d3..fcc7a81 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java @@ -5,6 +5,8 @@ import org.ntlab.citrusserver.repositories.AccountManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; + +import java.util.ArrayList; import java.util.HashMap; import java.util.Set; @@ -18,91 +20,93 @@ accountManager = am; } -///accountの一覧を返す - private HashMap accounts = new HashMap<>(); + //accountの一覧を返す @GET @Produces(MediaType.APPLICATION_JSON) public Set getAccount(){ - return accounts.keySet(); + return accountManager.getAccountsID(); } -//accountの新規作成 + //accountの新規作成 @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//bodyに入力する値がある時 - public void signup(@FormParam("account_id") String account_id, @FormParam("password") String password) { - accounts.put(account_id, password); + public String signup(@FormParam("account_id") String accountId, @FormParam("password") String password) { + String token; + token = accountManager.createAccount(accountId, password); + return token; } ////////// @Path("/{account_id}") -//account_idの情報を返す”introduction”と[本] + //account_idの情報を返す”introduction”と[本] @GET - public Account getAccount(@PathParam("account_id") String accountId){ //account_idを渡してManegerから値が返ってくる + @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}/password") +// @Path("/{account_id}/password") +//// +// @PUT // - @PUT - - -/////// +// +///////// @Path("/accounts/{account_id}/introduction") -//自己紹介を返す + //自己紹介を返す @GET - public String getAccount(@PathParam("account_id") String account_id){ //account_idを渡してintroductionが返ってくる - Account ac = accountManager.getAccount(account_id); - return ac.getIntroduction(); + @Produces(MediaType.APPLICATION_JSON) + public String getAccount(@PathParam("account_id") String accountId){ //account_idを渡してintroductionが返ってくる + String ac = accountManager.AccountIntro(accountId); + return ac; } - @PUT +// @PUT ///////// - @Path("/accounts/{account_id}/photo") -//画像を返す - @GET - public String getAccount(@PathParam("account_id") String account_id){ //account_idを渡してManegerから値が返ってくる - Account ac = accountManager.getAccount(account_id); - return ac.getPhoto(); - } - - @PUT +// @Path("/accounts/{account_id}/photo") +// //画像を返す +// @GET +// public String getAccount(@PathParam("account_id") String accountId){ //account_idを渡してManegerから値が返ってくる +// Account ac = accountManager.getAccount(accountId); +// return ac.getPhoto(); +// } +// +// @PUT ///////// @Path("/accounts/{account_id}/favorites") -//お気に入りの本のリストを返す + //指定されたIDのお気に入りの本のリストを返す @GET - public String getAccount(@PathParam("account_id") String account_id,@QueryParam("token")String token){ //account_idを渡してManegerから値が返ってくる - Account ac = accountManager.getAccount(account_id,token); - return ac.getFavorites(); + @Produces(MediaType.APPLICATION_JSON) + public ArrayList> favoriteBook(@PathParam("account_id") String accountId, @QueryParam("token")String token){ + return accountManager.favoriteBook(accountId,token); } - //////// @Path("/accounts/{account_id}/favorites/{other_account_id}") -//お気に入りの本のリストを返す + //指定されたIDのお気に入りの本のリストを返す(指定した人物) @GET - public String getAccount(@PathParam("account_id") String account_id,@PathParam("other_account_id") String other_account_id,@QueryParam("token")String token){ //account_idを渡してManegerから値が返ってくる - Account ac = accountManager.getAccount(account_id,other_account_id,token); - return ac.getFavoritesBookId(); + @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); } +////////// +// @Path("/accounts/{account_id}/favorites/{other_account_id}/{book_id}") +// @DELETE +// @PUT //////// - @Path("/accounts/{account_id}/favorites/{other_account_id}/{book_id}") - @DELETE - @PUT -//////// - @Path("/accounts/{account_id}/login") - @POST - @Consumes(MediaType.APPLICATION_JSON) - public void login(@PathParam("account_id") String account_id),@FormParam("password") String password) { - accounts.put(account_id, password); - } +// @Path("/accounts/{account_id}/login") +// @POST +// @Consumes(MediaType.APPLICATION_JSON) +// public void login(@PathParam("account_id") String accountId,@FormParam("password") String password) { +// accountManager.put(accountId, password); +// } } diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index 19bac65..1c7ac5d 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -1,17 +1,108 @@ package org.ntlab.citrusserver.resources; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; +import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; +import org.ntlab.citrusserver.entities.Book; +import org.ntlab.citrusserver.repositories.BookManager; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.HashMap; + + @Path("/accounts") @Component -public class BooksRest { - @GET - @Produces(MediaType.TEXT_PLAIN)//returnの形をどうするか - public String getAccounts() { - return null; + + +public class BookRest {//BookRestはクラス + + private final BookManager bookManager; + @Autowired //スプリングブートにいうサイン + public BookRest(BookManager bm){ //public クラス名()がコンストラクタ + bookManager = bm; } + + +/// {account_id}/books + private final HashMap> books = new HashMap<>(); + @Path("/{account_id}/books") + + /// 本一覧を返す + @GET + @Produces(MediaType.APPLICATION_JSON) + public Book getBook(@PathParam("account_id") String account_id){ + Book book = bookManager.getBook(account_id); + return book; + } + /// 本の新規作成 + @POST + @Consumes(MediaType.APPLICATION_JSON) + +/// {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){ + Book book = bookManager.getBook(account_id, book_id); + return book; + } + /// 本の削除 + @DELETE + +/// /{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/{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") + + /// 本のタイトルを返す + @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; + } + /// 本のタイトル変更 + @PUT + +/// /accounts/{account_id}/books/{book_id}/public + @Path("/{account_id}/books/{book_id}/public") + + /// 本の公開状態を返す + @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; + } + /// 公開状態を変更する + @PUT + +/// /accounts/{account_id}/books/{book_id}/goals/{year}/{month} + @Path("/accounts/{account_id}/books/{book_id}/goals/{year}/{month}") + + /// + + + + + + } \ 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 008907d..27d89be 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java @@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.HashMap; + @Path("/accounts") @Component public class TodoRest { @@ -19,7 +21,7 @@ this.todoManager = todoManager; todoManager = tm; } - + //test用 @Path("/TodoTest") @GET @Produces(MediaType.TEXT_PLAIN) @@ -32,36 +34,33 @@ @Path("/{account_id}/books/{book_id}/todos") @GET @Produces(MediaType.APPLICATION_JSON) - public Todo getName(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") Integer token) { - Todo todo = todoManager.getAllTodos(account_id, book_id, token); - return todo;//account部分のリスト名要変更 - //ドット部分以降打合せ(相手の関数名に合わせる) + public HashMap>>> getAllTodos(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token) { + return todoManager.getAllTodos(account_id, book_id, token); + } //指定された本の指定された年と月のtodoをすべて返す - //yearとmonthはintなのか!!! @Path("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}") @GET @Produces(MediaType.APPLICATION_JSON) - public Todo getTodoMonth(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @QueryParam("token") String token) { - Todo todo = todoManager.getTodosByMonth(account_id, book_id, year, month,token); - return todo; + public HashMap> getTodosByMonth(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @QueryParam("token") String token) { + return todoManager.getTodosByMonth(account_id, book_id, year, month,token); } //指定された本の指定された年と月と日のtodoをすべて返す @Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}") @GET @Produces(MediaType.APPLICATION_JSON) - public Todo getTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @QueryParam("token") String token) { - Todo todo = todoManager.getTodosByDay(account_id, book_id, year, month, day, token); - return todo; + public HashMap getTodosByDay(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @QueryParam("token") String token) { + return todoManager.getTodosByDay(account_id, book_id, year, month, day, token); + } //本のtodoを年月日とtodo_idを指定してtodoを一つ返す @Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") @GET @Produces(MediaType.APPLICATION_JSON) - public Todo getTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @PathParam("todo_id") Integer todo_id, @QueryParam("token") String token) { + public Todo getTodoById(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @PathParam("todo_id") Integer todo_id, @QueryParam("token") String token) { Todo todo = todoManager.getTodoById(account_id, book_id, year, month, day, todo_id, token); return todo; } @@ -70,9 +69,9 @@ @POST @Path("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Todo putTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @QueryParam("token") String token) { - Todo todo = todoManager.createTodo(account_id, book_id, year, month, day, token); - return todo; + 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); + } //todoを選んで達成状態を変更する @@ -80,11 +79,18 @@ @PUT @Path("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}/check") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Todo putTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day,@PathParam("todo_id") Integer todo_id, @FormParam("check") boolean check){ - Todo todo = todoManager.setCheck(account_id, book_id, year, month, day, todo_id,check); - return todo; + public void setCheck(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day,@PathParam("todo_id") Integer todo_id, @FormParam("check") boolean check, @QueryParam("token") String token){ + todoManager.setCheck(account_id, book_id, year, month, day, todo_id,check,token); } + //delete追加必要 + //本のtodoを年月日とtodo_idを指定してそのtodoを削除する + @DELETE + @Path("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void deleteTodoById(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @PathParam("todo_id") Integer todo_id, @QueryParam("token") String token){ + todoManager.deleteTodoById(account_id, book_id, year, month, day, todo_id,token); + }