diff --git a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java index 7874daf..027b7b6 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java @@ -12,13 +12,13 @@ @Repository public class ScheduleManager { - private final AccountManager accountManager; //仮 + private final BookManager bookManager; private final HashMap nextScheduleId = new HashMap<>(); @Autowired - public ScheduleManager(AccountManager accountManager) { - this.accountManager = accountManager; + public ScheduleManager(BookManager bookManager) { + this.bookManager = bookManager; } //管理 @@ -47,7 +47,10 @@ } public Schedule addSchedule(String accountId, int year, int month, int day, String title, String startTime, String endTime, Integer bookId){ - if(bookId == null)bookId = 0; + if(bookId == null){ + bookId = 0; + } + else if(!bookManager.getBooks(accountId).containsKey(bookId))return null; if(!schedules.containsKey(accountId)){ schedules.put(accountId, new HashMap<>()); @@ -94,9 +97,15 @@ 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, Integer newBookId){ - if(newBookId == null)newBookId = 0; + //voidからintに変更 1で成功 -1でエラー処理 + public int setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, Integer newBookId){ + if(newBookId == null){ + newBookId = 0; + } + else if(!bookManager.getBooks(accountId).containsKey(newBookId))return -1; schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setBookId(newBookId); + + return 1; } public void deleteSchedules(String accountId){