diff --git a/src/main/java/org/ntlab/citrusserver/entities/Book.java b/src/main/java/org/ntlab/citrusserver/entities/Book.java index dc010ff..76c3dd9 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Book.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Book.java @@ -6,9 +6,11 @@ private String title; private boolean publicity; private String color; + private String accountId; - public Book(Integer bookid, String title, boolean publicity, String color) { + public Book(String accountId, Integer bookid, String title, boolean publicity, String color) { + this.accountId = accountId; this.bookId = bookid; this.title = title; @@ -25,4 +27,6 @@ public String getColor() {return color;} public void setBookId(int id) {bookId = id;} public int getBookId() {return bookId;} + public void setAccountId(String a) {accountId = a;} + public String getAccountId() {return accountId;} } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index 478547a..cbe4285 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java @@ -14,20 +14,19 @@ private final HashMap> booksMap = new HashMap<>(); private final AccountManager accountManager; //仮 - private final List iBookListeners = new ArrayList<>(); + @Autowired + public BookManager(AccountManager accountManager) { + this.accountManager = accountManager; + } + //IBookListenerを追加 public void addListener(IBookListener iBookListener) { iBookListeners.add(iBookListener); } - @Autowired - public BookManager(AccountManager accountManager) { - this.accountManager = accountManager; - } - //本の一覧を返す public HashMap getBooks(String accountId) { @@ -44,7 +43,7 @@ } Account account = accountManager.getAccount(accountId); //アカウントの取得 int newBookId = account.getNewBookId(); //新たに生成されたIdを取得(作成数もここで加算している) - Book book = new Book(newBookId, title, publicity, color); //本の初期化 + Book book = new Book(accountId, newBookId, title, publicity, color); //本の初期化 booksMap.get(accountId).put(newBookId, book); //ブックに追加 return booksMap.get(accountId).get(newBookId); //(int->Bookを返すように変更した) } @@ -124,6 +123,10 @@ } + //--------------------------------------------------------------------------------- + // private + //--------------------------------------------------------------------------------- + //IBookListenerに通知する private void notifyListener(Account account, Book book) { diff --git a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java index 295576a..6b99f95 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java @@ -1,11 +1,13 @@ package org.ntlab.citrusserver.repositories; import org.ntlab.citrusserver.entities.Account; +import org.ntlab.citrusserver.entities.Book; import org.ntlab.citrusserver.entities.Schedule; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import java.util.HashMap; +import java.util.Set; @Repository public class ScheduleManager { @@ -28,16 +30,20 @@ Schedule>>>>> schedules = new HashMap<>(); - public void getScheduleAll(String accountId){ + public HashMap>>> getScheduleAll(String accountId) { + return schedules.get(accountId); } - public void getScheduleYear(String accountId, int year){ + public HashMap>> getScheduleYear(String accountId, int year){ + return schedules.get(accountId).get(year); } - public void getScheduleMonth(String accountId, int year, int month){ + public HashMap> getScheduleMonth(String accountId, int year, int month){ + return schedules.get(accountId).get(year).get(month); } - public void getScheduleDay(String accountId, int year, int month, int day){ + public HashMap getScheduleDay(String accountId, int year, int month, int day){ + return schedules.get(accountId).get(year).get(month).get(day); } public Schedule addSchedule(String accountId, int year, int month, int day, String title, String startTime, String endTime, int bookId){ @@ -70,13 +76,23 @@ return schedules.get(accountId).get(year).get(month).get(day).get(scheduleId); } - public void deleteSchedule(String accountId, int year, int month, int day, int scheduleId){} + public void deleteSchedule(String accountId, int year, int month, int day, int scheduleId){ + schedules.get(accountId).get(year).get(month).get(day).remove(scheduleId); + } - public void setScheduleStartTime(String accountId, int year, int month, int day, int scheduleId, int oldTime, int newTime){} + public void setScheduleStartTime(String accountId, int year, int month, int day, int scheduleId, String newTime){ + schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setStartTime(newTime); + } - public void setScheduleEndTime(String accountId, int year, int month, int day, int scheduleId, int oldTime, int newTime){} + public void setScheduleEndTime(String accountId, int year, int month, int day, int scheduleId, String newTime){ + schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setEndTime(newTime); + } - public void changeScheduleTitle(String accountId, int year, int month, int day, int scheduleId, String oldTitle, String newTitle){} + public void changeScheduleTitle(String accountId, int year, int month, int day, int scheduleId, String newTitle){ + schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setTitle(newTitle); + } - public void setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, int newBookId){} + public void setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, int newBookId){ + schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setScheduleId(newBookId); + } } diff --git a/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java b/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java index 8d88538..14f3f42 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java @@ -32,7 +32,8 @@ // if(accountManager.checkToken(accountId,token)) { // return scheduleManager.getScheduleAll(accountId); // } -// return null; +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } // @Path("/{account_id}/schedule/{year}") @@ -42,7 +43,8 @@ // if(accountManager.checkToken(accountId,token)) { // return scheduleManager.getScheduleYear(accountId,year); // } -// return null; +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } // @Path("/{account_id}/schedule/{year}/{month}") @@ -53,7 +55,8 @@ // if(accountManager.checkToken(accountId,token)) { // return scheduleManager.getScheduleMonth(accountId,year,month); // } -// return null; +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } // @Path("/{account_id}/schedule/{year}/{month}/{day}") @@ -64,7 +67,8 @@ // if(accountManager.checkToken(accountId,token)) { // return scheduleManager.getScheduleYear(accountId,year,month,day); // } -// return null; +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } @Path("/{account_id}/schedule/{year}/{month}/{day}") @@ -94,9 +98,10 @@ if(accountManager.checkToken(accountId,token)) { Schedule schedule = scheduleManager.getScheduleId(accountId, year, month, day, scheduleId); return schedule; + }else { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); } - var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); - throw new WebApplicationException(response.build()); } // @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}") @@ -109,8 +114,10 @@ // if(accountManager.checkToken(accountId,token)) { // scheduleManager.deleteSchedule(accountId, year, month, day, scheduleId); // return "success"; +// }else { +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } -// return null; // } // @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/start_time") @@ -123,8 +130,10 @@ // if(accountManager.checkToken(accountId,token)) { // scheduleManager.setScheduleStartTime(accountId, year, month, day, scheduleId); // return "success"; +// }else { +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } -// return null; // } // @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/end_time") @@ -137,8 +146,10 @@ // if(accountManager.checkToken(accountId,token)) { // scheduleManager.setScheduleEndTime(accountId, year, month, day, scheduleId); // return "success"; +// }else { +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } -// return null; // } // @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/title") @@ -151,8 +162,10 @@ // if(accountManager.checkToken(accountId,token)) { // scheduleManager.setScheduleTitle(accountId, year, month, day, scheduleId); // return schedule; +// }else { +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } -// return null; // } // @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/book_id") @@ -165,7 +178,9 @@ // if(accountManager.checkToken(accountId,token)) { // scheduleManager.setSchedulesBook(accountId, year, month, day, scheduleId);//token後でつける // return "success"; +// }else { +// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); +// throw new WebApplicationException(response.build()); // } -// return null; // } }