diff --git a/src/main/java/org/ntlab/citrusserver/entities/Account.java b/src/main/java/org/ntlab/citrusserver/entities/Account.java index 7694b27..6aac4b0 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Account.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Account.java @@ -1,4 +1,21 @@ package org.ntlab.citrusserver.entities; public class Account { + String introduction; + int bookcount = 0; + String accountId; + String password; + + public void setIntroduction(String i) {introduction = i;} + public String getIntroduction() {return introduction;} + public int getNewBookId() { + bookcount += 1; + return bookcount; + } + public int getBookCount() {return bookcount;} + public void setId(String i) {accountId = i;} + 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/entities/Book.java b/src/main/java/org/ntlab/citrusserver/entities/Book.java index 1bbf11e..f9aec9b 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Book.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Book.java @@ -1,4 +1,29 @@ package org.ntlab.citrusserver.entities; public class Book { + + private String title; + private boolean publicity; + private String color; + private int bookId; + private int todoId = 0; + + public Book(String title, boolean publicity, String color) { + this.title = title; + this.publicity = publicity; + this.color = color; + } + + public void setTitle(String t) {title = t;} + public String getTitle() {return title;} + public void setPublicity(boolean p) {publicity = p;} + public boolean getPublicity() {return publicity;} + public void setColor(String c) {color = c;} + public String getColor() {return color;} + public void setBookId(int id) {bookId = id;} + public int getBookId() {return bookId;} + public int getTodoId() { + todoId += 1; + return todoId; + } } diff --git a/src/main/java/org/ntlab/citrusserver/entities/Todo.java b/src/main/java/org/ntlab/citrusserver/entities/Todo.java index 95d24e9..8ba929b 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Todo.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Todo.java @@ -1,4 +1,33 @@ package org.ntlab.citrusserver.entities; public class Todo { + String title; + boolean check; + int year; + int month; + int day; + Integer todoId; + + public Todo(String t, boolean c, int y, int m, int d, Integer tid) { + title = t; + check = c; + year = y; + month = m; + day = d; + todoId = tid; + } + public void setTitle(String t) {title = t;} + public String getTitle() {return title;} + public void setCheck(boolean c) {check = c;} + public boolean getCheck() {return check;} + public void setYear(int y) {year = y;} + public int getYear() {return year;} + public void setMonth(int m) {month = m;} + public int getMonth() {return month;} + public void setDay(int d) {day = d;} + public int getDay() {return day;} + public void setTodoId(Integer t) {todoId = t;} + public Integer getTodoId() { + return todoId; + } } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java index e7291b8..04c0eba 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java @@ -1,4 +1,84 @@ package org.ntlab.citrusserver.repositories; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; +import org.ntlab.citrusserver.entities.Account; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; + +import java.lang.reflect.Array; +import java.util.*; + +import java.util.HashMap; + +@Repository public class AccountManager { + private HashMap accounts = new HashMap(); + + private HashMap accountToken = new HashMap<>(); //keyがaccountId,valueがtoken + + // アカウントの一覧をリストとして返す(GET) + public Set getAccountsID() { + return accounts.keySet(); + } + + // account_idとpasswordを設定し新しいアカウントを作成する(POST) + public String newAccount(String accountId, String password) { + UUID str = UUID.randomUUID(); + String token = str.toString(); + //accounts.setId(accountId); + //accounts.setPassword(password); + accountToken.put(accountId, token); //accountIDとtokenをHashMapに入れる + return token; + } + + // 指定されたアカウントの情報を返す(GET) + public Account getAccount(String accountId) { + return accounts.get(accountId); + } + + // アカウント情報を全削除する(DELETE) + public void deleteAccount(String accountId, String password, String token) { + + } + + // 指定されたIDの自己紹介を返す(GET) + public void AccountIntro() { + + } + + // 指定されたIDのお気に入りの本のリストを返す(GET) + public void favoriteBook() { + + } + + // 指定されたIDのお気に入りの本のリストを返す(指定した人物) (GET) + public void FavoriteparBook() { + + } + + // 指定されたIDのアカウントを変更する (PUT) + public void newpassword() { + + } + + // 指定されたIDの自己紹介を変更する (PUT) + public void newintro() { + + } + + // お気に入りにの本のbook_idを削除する (DELETE) + public void deletefavbook() { + + } + + // いいねした本のアカウントIDとbook_idを追加する(いいねした側に追加) (PUT) + public void putfavoriteid() { + + } + + // アカウントidとパスワードでログインし、tokenを返す (POST) + public void login() { + + } } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index b371ae5..cadd0f9 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java @@ -1,4 +1,79 @@ package org.ntlab.citrusserver.repositories; +import org.ntlab.citrusserver.entities.Account; +import org.ntlab.citrusserver.entities.Book; +import org.springframework.stereotype.Repository; +import java.util.HashMap; + +@Repository public class BookManager { + + private HashMap> booksMap = new HashMap<>(); + private final AccountManager accountManager; //仮 + + public BookManager(AccountManager accountManager) { + this.accountManager = accountManager; + } + + //本の一覧を返す + public HashMap> getBooks() + { + return booksMap; + } + + //本の新規作成 + public int createBook(String accountId, String title, String color, Boolean publicity) + { + Account account = accountManager.getAccount(accountId); //アカウントの取得 + Book book = new Book(title, publicity, color); //本の初期化 + int newBookId = account.getNewBookId(); //新たに生成されたIdを取得(作成数もここで加算している) + booksMap.get(accountId).put(newBookId, book); //ブックに追加 + return newBookId; + } + + //本の情報を取得 + public Book getBook(String accountId, Integer bookId) + { + return booksMap.get(accountId).get(bookId); + } + + //本の削除 + public void deleteBook(String accountId, Integer bookId) + { + booksMap.get(accountId).remove(bookId); + } + + //((( いいねは省略 ))) + + //本のタイトルを返す + public String getTitle(String accountId, Integer bookId) + { + return booksMap.get(accountId).get(bookId).getTitle(); + } + + //本のタイトルを変更 + public void putTitle(String accountId, Integer bookId, String title) + { + booksMap.get(accountId).get(bookId).setTitle(title); + } + + //本の公開情報を返す + public Boolean getPublicity(String accountId, Integer bookId) + { + return booksMap.get(accountId).get(bookId).getPublicity(); + } + + //公開情報を変更する + public void putPublicity(String accountId, Integer bookId, Boolean publicity) + { + booksMap.get(accountId).get(bookId).setPublicity(publicity); + } + + //((( 目標・振り返りは省略 ))) + + //本の色を変更する + public void putColor(String accountId, Integer bookId, String color) + { + booksMap.get(accountId).get(bookId).setColor(color); + } } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java index c210486..a60d082 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java @@ -1,4 +1,259 @@ package org.ntlab.citrusserver.repositories; +import org.ntlab.citrusserver.entities.Todo; +import org.springframework.stereotype.Repository; + +import java.util.HashMap; + +@Repository public class TodoManager { + + /** + * todoをすべて管理します + */ + private final HashMap>>>>> todos + = new HashMap<>(); + + /** + * アカウントの本の次に与えるべきtodoのidを管理します + */ + private final HashMap nextTodoId = new HashMap<>(); + +// private final BookManager bookManager; +// +// TodoManger(BookManager bookManager){ +// this.bookManager = bookManager; +// } + + /** + * + * アカウントと本を指定してそれに所属するtodoをすべて返す + * + * @param accountId アカウントのid + * @param bookId 本のid + * @return そのアカウントの本に所属するtodoをすべて返します + */ + public HashMap getAllTodos(String accountId, int bookId){ + HashMap result = new HashMap<>(); + for(var yearValues : todos.get(accountId).get(bookId).values()){ + for(var monthValues : yearValues.values()){ + for(var dayValues : monthValues.values()){ + for(int todoId : dayValues.keySet()){ + result.put(todoId, dayValues.get(todoId)); + } + } + } + } + return result; + } + + /** + *年月をそれぞれintで指定してtodoをtodo_id->todoの辞書で返す + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param year 年 + * @param month 月 + * @return そのアカウントの本に所属するtodoのうち、指定した年月のtodoを返します + */ + public HashMap getTodosByMonth(String accountId, int bookId, int year, int month){ + HashMap result = new HashMap<>(); + var yearMonthMap = todos.get(accountId).get(bookId).get(year).get(month); + for(var dayValues : yearMonthMap.values()){ + for(int todoId : dayValues.keySet()){ + result.put(todoId, dayValues.get(todoId)); + } + } + return result; + } + + /** + *年月を-区切りの文字列で指定してtodoをtodo_id->todoの辞書で返す + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param yearMonth 年月を-で区切った文字列(yyyy-mm) + * @return そのアカウントの本に所属するtodoのうち、指定した年月のtodoを返します + */ + public HashMap getTodosByMonth(String accountId, int bookId, String yearMonth){ + String[] yearMonths = yearMonth.split("-"); + int year = Integer.parseInt(yearMonths[0]); + int month = Integer.parseInt(yearMonths[1]); + return getTodosByMonth(accountId, bookId, year, month); + } + + /** + * 年月日をそれぞれintで指定してtodoをtodo_id->todoの辞書で返す + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param year 年 + * @param month 月 + * @param day 日 + * @return そのアカウントの本に所属するtodoのうち、指定した年月日のtodoを返します + */ + public HashMap getTodosByDay(String accountId, int bookId, int year, int month, int day){ + return todos.get(accountId).get(bookId).get(year).get(month).get(day); + } + + /** + * 年月日を-区切りの文字列で指定してtodoをtodo_id->todoの辞書で返す + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param yearMonthDay 年月日を-で区切った文字列(yyyy-mm-dd) + * @return そのアカウントの本に所属するtodoのうち、指定した年月日のtodoを返します + */ + public HashMap getTodosByDay(String accountId, int bookId, String yearMonthDay){ + String[] yearMonthDays = yearMonthDay.split("-"); + int year = Integer.parseInt(yearMonthDays[0]); + int month = Integer.parseInt(yearMonthDays[1]); + int day = Integer.parseInt(yearMonthDays[2]); + return getTodosByDay(accountId, bookId, year, month, day); + } + + + /** + *todo_idを指定してtodoを一つ取得する + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param year 年 + * @param month 月 + * @param day 日 + * @param todoId todoのid + * @return idを指定してtodoを返す + */ + public Todo getTodoById(String accountId, int bookId, int year, int month, int day, int todoId){ + return todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId); + } + + /** + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param yearMonthDay 年月日を-で区切った文字列(yyyy-mm-dd) + * @param todoId todoのid + * @return 指定したtodo + */ + public Todo getTodoById(String accountId, int bookId, String yearMonthDay, int todoId){ + String[] yearMonthDays = yearMonthDay.split("-"); + int year = Integer.parseInt(yearMonthDays[0]); + int month = Integer.parseInt(yearMonthDays[1]); + int day = Integer.parseInt(yearMonthDays[2]); + return getTodoById(accountId, bookId, year, month, day, todoId); + } + + /** + *todoを追加する + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param year 年 + * @param month 月 + * @param day 日 + * @param title 追加するべきtodoのタイトル + */ + public int addTodo(String accountId, int bookId, int year, int month, int day, String title){ + if(!todos.containsKey(accountId)){ + todos.put(accountId, new HashMap<>()); + } + if(!todos.get(accountId).containsKey(bookId)){ + todos.get(accountId).put(bookId, new HashMap<>()); + } + if(!todos.get(accountId).get(bookId).containsKey(year)){ + todos.get(accountId).get(bookId).put(year, new HashMap<>()); + } + if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ + todos.get(accountId).get(bookId).get(year).put(month, new HashMap<>()); + } + if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ + todos.get(accountId).get(bookId).get(year).get(month).put(day, new HashMap<>()); + } + String accountBook = accountId + bookId + year + month + day; + if(!nextTodoId.containsKey(accountBook)){ + nextTodoId.put(accountBook, 0); + } + + int todoId = nextTodoId.get(accountBook); + Todo newTodo = new Todo(title, false, year, month, day, todoId); + todos.get(accountId).get(bookId).get(year).get(month).get(day).put(todoId, newTodo); + nextTodoId.put(accountBook, todoId + 1); + return todoId; + } + + /** + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param yearMonthDay 年月日を-で区切った文字列(yyyy-mm-dd) + * @param title 追加したいtodoのタイトル + */ + public int addTodo(String accountId, int bookId, String yearMonthDay, String title){ + String[] yearMonthDays = yearMonthDay.split("-"); + int year = Integer.parseInt(yearMonthDays[0]); + int month = Integer.parseInt(yearMonthDays[1]); + int day = Integer.parseInt(yearMonthDays[2]); + return addTodo(accountId, bookId, year, month, day, title); + } + + /** + *todo_idを指定してtodoを削除する + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param todoId 削除したいtodoのid + */ + public void deleteTodoById(String accountId, int bookId, int year, int month, int day, int todoId){ + todos.get(accountId).get(bookId).get(year).get(month).get(day).remove(todoId); + } + + /** + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param yearMonthDay 年月日を-で区切った文字列(yyyy-mm-dd) + * @param todoId 削除したいtodoのid + */ + public void deleteTodoById(String accountId, int bookId, String yearMonthDay, int todoId){ + String[] yearMonthDays = yearMonthDay.split("-"); + int year = Integer.parseInt(yearMonthDays[0]); + int month = Integer.parseInt(yearMonthDays[1]); + int day = Integer.parseInt(yearMonthDays[2]); + deleteTodoById(accountId, bookId, year, month, day, todoId); + } + + /** + *指定したtodo_idのtodoの達成状態を変更する + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param todoId 変更したいtodoのid + * @param check 変更後の達成状態 + */ + public void setCheck(String accountId, int bookId, int year, int month, int day, int todoId, boolean check){ + todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setCheck(check); + } + + /** + * + * @param accountId アカウントのid + * @param bookId 本のid + * @param yearMonthDay 年月日を-で区切った文字列(yyyy-mm-dd) + * @param todoId 変更したいtodoのid + * @param check 変更後の達成状態 + */ + public void setCheck(String accountId, int bookId, String yearMonthDay, int todoId, boolean check){ + String[] yearMonthDays = yearMonthDay.split("-"); + int year = Integer.parseInt(yearMonthDays[0]); + int month = Integer.parseInt(yearMonthDays[1]); + int day = Integer.parseInt(yearMonthDays[2]); + setCheck(accountId, bookId, year, month, day, todoId, check); + } }