diff --git a/build.gradle b/build.gradle index 7634e8e0..92a21c84 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'hous' -version = '1.0.3-SNAPSHOT' +version = '1.0.4-SNAPSHOT' sourceCompatibility = '11' configurations { diff --git a/src/main/java/hous/server/config/swagger/SwaggerConfig.java b/src/main/java/hous/server/config/swagger/SwaggerConfig.java index 1ca01854..e17013cd 100644 --- a/src/main/java/hous/server/config/swagger/SwaggerConfig.java +++ b/src/main/java/hous/server/config/swagger/SwaggerConfig.java @@ -113,7 +113,7 @@ private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Hous- Release") .description("Server API Docs") - .version("1.0.3") + .version("1.0.4") .build(); } } diff --git a/src/main/java/hous/server/service/todo/TodoRetrieveService.java b/src/main/java/hous/server/service/todo/TodoRetrieveService.java index bd06bd44..06ff4f97 100644 --- a/src/main/java/hous/server/service/todo/TodoRetrieveService.java +++ b/src/main/java/hous/server/service/todo/TodoRetrieveService.java @@ -103,15 +103,14 @@ public TodoAllDayResponse getTodoAllDayInfo(Long userId) { User user = UserServiceUtils.findUserById(userRepository, userId); Onboarding onboarding = user.getOnboarding(); Room room = RoomServiceUtils.findParticipatingRoom(user); - List todos = room.getTodos(); // 이 방의 모든 요일의 todo list 조회 - List ourTodosList = TodoServiceUtils.filterAllDaysOurTodos(todos); - List myTodosList = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding); + List ourTodosList = room.getTodos(); + List myTodosList = TodoServiceUtils.filterAllDaysUserTodos(ourTodosList, onboarding); // 요일별(index) todo list 형태로 가공 - Map> allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToList(ourTodosList); - Map> allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToList(myTodosList); + Map> allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToOurTodosList(ourTodosList); + Map> allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToMyTodosList(onboarding, myTodosList); // List response dto 형태로 가공 List allDayTodosList = new ArrayList<>(); @@ -144,10 +143,10 @@ public TodoAllMemberResponse getTodoAllMemberInfo(Long userId) { room.getParticipates().stream() .sorted(Participate::compareTo) .forEach(participate -> { - List memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); - List memberUniqueTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding()); + Onboarding onboarding = participate.getOnboarding(); + List memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding); - Map> allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos); + Map> allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToMyTodosList(onboarding, memberTodos); List dayOfWeekTodos = new ArrayList<>(); for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.SUNDAY.getIndex(); day++) { @@ -159,13 +158,13 @@ public TodoAllMemberResponse getTodoAllMemberInfo(Long userId) { dayOfWeekTodos.add(DayOfWeekTodo.of(dayOfWeek, thisDayTodosName.size(), thisDayTodosName)); } - String userName = participate.getOnboarding().getNickname(); - PersonalityColor color = participate.getOnboarding().getPersonality().getColor(); + String userName = onboarding.getNickname(); + PersonalityColor color = onboarding.getPersonality().getColor(); - if (user.getOnboarding().equals(participate.getOnboarding())) { - allMemberTodos.add(TodoAllMemberInfo.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); + if (user.getOnboarding().equals(onboarding)) { + allMemberTodos.add(TodoAllMemberInfo.of(userName, color, memberTodos.size(), dayOfWeekTodos)); } else { - otherMemberTodos.add(TodoAllMemberInfo.of(userName, color, memberUniqueTodos.size(), dayOfWeekTodos)); + otherMemberTodos.add(TodoAllMemberInfo.of(userName, color, memberTodos.size(), dayOfWeekTodos)); } }); allMemberTodos.addAll(otherMemberTodos); diff --git a/src/main/java/hous/server/service/todo/TodoServiceUtils.java b/src/main/java/hous/server/service/todo/TodoServiceUtils.java index 1d172b59..00a5d72b 100644 --- a/src/main/java/hous/server/service/todo/TodoServiceUtils.java +++ b/src/main/java/hous/server/service/todo/TodoServiceUtils.java @@ -93,14 +93,6 @@ public static List filterDayOurTodosByIsPushNotification(LocalDate day, Li return new ArrayList<>(dayOurTodosSet); } - public static List filterAllDaysOurTodos(List todos) { - Set allDaysOurTodosSet = new HashSet<>(); - todos.forEach(todo -> todo.getTakes().forEach(take -> - take.getRedos().forEach(redo -> - allDaysOurTodosSet.add(todo)))); - return new ArrayList<>(allDaysOurTodosSet); - } - public static List filterAllDaysUserTodos(List todos, Onboarding onboarding) { Set userTodosSet = new HashSet<>(); todos.forEach(todo -> todo.getTakes().forEach(take -> { @@ -117,7 +109,7 @@ public static List filterAllDaysMyDones(Onboarding me, List dones) { .collect(Collectors.toList()); } - public static Map> mapByDayOfWeekToList(List todos) { + public static Map> mapByDayOfWeekToOurTodosList(List todos) { Map> todosMapByDayOfWeek = new HashMap<>(); for (int i = DayOfWeek.MONDAY.getIndex(); i <= DayOfWeek.SUNDAY.getIndex(); i++) { todosMapByDayOfWeek.put(i, new HashSet<>()); @@ -133,16 +125,37 @@ public static Map> mapByDayOfWeekToList(List todos) { return todosMapByDayOfWeek; } + public static Map> mapByDayOfWeekToMyTodosList(Onboarding me, List todos) { + Map> todosMapByDayOfWeek = new HashMap<>(); + for (int i = DayOfWeek.MONDAY.getIndex(); i <= DayOfWeek.SUNDAY.getIndex(); i++) { + todosMapByDayOfWeek.put(i, new HashSet<>()); + } + todos.forEach(todo -> todo.getTakes().forEach(take -> { + if (take.getOnboarding().getId().equals(me.getId())) { + take.getRedos().forEach(redo -> { + Set todosByDayOfWeek = todosMapByDayOfWeek.get(redo.getDayOfWeek().getIndex()); + todosByDayOfWeek.add(todo); + todosMapByDayOfWeek.put(redo.getDayOfWeek().getIndex(), todosByDayOfWeek); + }); + } + } + )); + return todosMapByDayOfWeek; + } + public static List filterDayMyTodos(LocalDate day, Onboarding me, List todos) { Set dayMyTodosSet = new HashSet<>(); List dayOurTodosList = filterDayOurTodos(day, todos); - dayOurTodosList.forEach(todo -> { - todo.getTakes().forEach(take -> { - if (take.getOnboarding().getId().equals(me.getId())) { - dayMyTodosSet.add(todo); - } - }); - }); + // TODO refatoring 필요 + dayOurTodosList.forEach(todo -> todo.getTakes().forEach(take -> { + if (take.getOnboarding().getId().equals(me.getId())) { + take.getRedos().forEach(redo -> { + if (redo.getDayOfWeek().toString().equals(DateUtils.nowDayOfWeek(day))) { + dayMyTodosSet.add(todo); + } + }); + } + })); return new ArrayList<>(dayMyTodosSet); }