diff --git a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java index 2b2dca2..13a5982 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java @@ -7,8 +7,6 @@ import org.springframework.stereotype.Repository; import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; @Repository public class ScheduleManager implements IBookListener{ @@ -136,8 +134,8 @@ } @Override - public void bookDeleted(Account accountin, Book book) { - String account = accountin.getId(); + public void bookDeleted(Account accountIn, Book book) { + String account = accountIn.getId(); for(int year : schedules.get(account).keySet()){ for (int month : schedules.get(account).get(year).keySet()){ for(int day : schedules.get(account).get(year).get(month).keySet()){ @@ -150,4 +148,82 @@ } } } + + public void autoAddSchedule(){ + String accountId1 = "fish"; + int year = 2024; + int month = 5; + int day = 28; + String title1 = "cinema"; + String startTime1 = "13:00"; + String endTime1 = "14:00"; + Integer bookId1 = 0; + + String accountId2 = "bird"; + + String title2 = "test"; + String startTime2 = "10:00"; + String endTime2 = "12:00"; + Integer bookId2 = 1; + + //account1 + if(!schedules.containsKey(accountId1)){ + schedules.put(accountId1, new HashMap<>()); + } + if(!schedules.get(accountId1).containsKey(year)){ + schedules.get(accountId1).put(year, new HashMap<>()); + } + if(!schedules.get(accountId1).get(year).containsKey(month)){ + schedules.get(accountId1).get(year).put(month, new HashMap<>()); + } + if(!schedules.get(accountId1).get(year).get(month).containsKey(day)){ + schedules.get(accountId1).get(year).get(month).put(day, new HashMap<>()); + } + + String accountSchedule1 = accountId1 + year + month + day;// + + if(!nextScheduleId.containsKey(accountSchedule1)){ + nextScheduleId.put(accountSchedule1, 0); + } + + int newScheduleId1 = nextScheduleId.get(accountSchedule1); + Schedule newSchedule11 = new Schedule(title1, startTime1, endTime1, bookId1, newScheduleId1); + Schedule newSchedule12 = new Schedule(title2, startTime2, endTime2, bookId2, newScheduleId1); + + schedules.get(accountId1).get(year).get(month).get(day).put(newScheduleId1, newSchedule11); + nextScheduleId.put(accountSchedule1, newScheduleId1 + 1); + + schedules.get(accountId1).get(year).get(month).get(day).put(newScheduleId1, newSchedule12); + nextScheduleId.put(accountSchedule1, newScheduleId1 + 1); + + //account2 + + if(!schedules.containsKey(accountId2)){ + schedules.put(accountId2, new HashMap<>()); + } + if(!schedules.get(accountId2).containsKey(year)){ + schedules.get(accountId2).put(year, new HashMap<>()); + } + if(!schedules.get(accountId2).get(year).containsKey(month)){ + schedules.get(accountId2).get(year).put(month, new HashMap<>()); + } + if(!schedules.get(accountId2).get(year).get(month).containsKey(day)){ + schedules.get(accountId2).get(year).get(month).put(day, new HashMap<>()); + } + + String accountSchedule2 = accountId2 + year + month + day;// + if(!nextScheduleId.containsKey(accountSchedule2)){ + nextScheduleId.put(accountSchedule2, 0); + } + + int newScheduleId2 = nextScheduleId.get(accountSchedule2); + Schedule newSchedule21 = new Schedule(title1, startTime1, endTime1 , bookId1, newScheduleId2); + Schedule newSchedule22 = new Schedule(title2, startTime2, endTime2 , bookId2, newScheduleId2); + + schedules.get(accountId2).get(year).get(month).get(day).put(newScheduleId2, newSchedule21); + nextScheduleId.put(accountSchedule2, newScheduleId2 + 1); + + schedules.get(accountId2).get(year).get(month).get(day).put(newScheduleId2, newSchedule22); + nextScheduleId.put(accountSchedule2, newScheduleId2 + 1); + } }