Skip to content

Commit

Permalink
Merge pull request #288 from Hous-Release/develop
Browse files Browse the repository at this point in the history
release 1.0.4
  • Loading branch information
orijoon98 authored Dec 27, 2022
2 parents 00e8247 + e593fa6 commit 7648be3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'hous'
version = '1.0.3-SNAPSHOT'
version = '1.0.4-SNAPSHOT'
sourceCompatibility = '11'

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
25 changes: 12 additions & 13 deletions src/main/java/hous/server/service/todo/TodoRetrieveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Todo> todos = room.getTodos();

// 이 방의 모든 요일의 todo list 조회
List<Todo> ourTodosList = TodoServiceUtils.filterAllDaysOurTodos(todos);
List<Todo> myTodosList = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding);
List<Todo> ourTodosList = room.getTodos();
List<Todo> myTodosList = TodoServiceUtils.filterAllDaysUserTodos(ourTodosList, onboarding);

// 요일별(index) todo list 형태로 가공
Map<Integer, Set<Todo>> allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToList(ourTodosList);
Map<Integer, Set<Todo>> allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToList(myTodosList);
Map<Integer, Set<Todo>> allDayOurTodosList = TodoServiceUtils.mapByDayOfWeekToOurTodosList(ourTodosList);
Map<Integer, Set<Todo>> allDayMyTodosList = TodoServiceUtils.mapByDayOfWeekToMyTodosList(onboarding, myTodosList);

// List<TodoAllDayResponse> response dto 형태로 가공
List<TodoAllDayInfo> allDayTodosList = new ArrayList<>();
Expand Down Expand Up @@ -144,10 +143,10 @@ public TodoAllMemberResponse getTodoAllMemberInfo(Long userId) {
room.getParticipates().stream()
.sorted(Participate::compareTo)
.forEach(participate -> {
List<Todo> memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding());
List<Todo> memberUniqueTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, participate.getOnboarding());
Onboarding onboarding = participate.getOnboarding();
List<Todo> memberTodos = TodoServiceUtils.filterAllDaysUserTodos(todos, onboarding);

Map<Integer, Set<Todo>> allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToList(memberTodos);
Map<Integer, Set<Todo>> allDayMemberTodos = TodoServiceUtils.mapByDayOfWeekToMyTodosList(onboarding, memberTodos);

List<DayOfWeekTodo> dayOfWeekTodos = new ArrayList<>();
for (int day = DayOfWeek.MONDAY.getIndex(); day <= DayOfWeek.SUNDAY.getIndex(); day++) {
Expand All @@ -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);
Expand Down
45 changes: 29 additions & 16 deletions src/main/java/hous/server/service/todo/TodoServiceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ public static List<Todo> filterDayOurTodosByIsPushNotification(LocalDate day, Li
return new ArrayList<>(dayOurTodosSet);
}

public static List<Todo> filterAllDaysOurTodos(List<Todo> todos) {
Set<Todo> allDaysOurTodosSet = new HashSet<>();
todos.forEach(todo -> todo.getTakes().forEach(take ->
take.getRedos().forEach(redo ->
allDaysOurTodosSet.add(todo))));
return new ArrayList<>(allDaysOurTodosSet);
}

public static List<Todo> filterAllDaysUserTodos(List<Todo> todos, Onboarding onboarding) {
Set<Todo> userTodosSet = new HashSet<>();
todos.forEach(todo -> todo.getTakes().forEach(take -> {
Expand All @@ -117,7 +109,7 @@ public static List<Done> filterAllDaysMyDones(Onboarding me, List<Done> dones) {
.collect(Collectors.toList());
}

public static Map<Integer, Set<Todo>> mapByDayOfWeekToList(List<Todo> todos) {
public static Map<Integer, Set<Todo>> mapByDayOfWeekToOurTodosList(List<Todo> todos) {
Map<Integer, Set<Todo>> todosMapByDayOfWeek = new HashMap<>();
for (int i = DayOfWeek.MONDAY.getIndex(); i <= DayOfWeek.SUNDAY.getIndex(); i++) {
todosMapByDayOfWeek.put(i, new HashSet<>());
Expand All @@ -133,16 +125,37 @@ public static Map<Integer, Set<Todo>> mapByDayOfWeekToList(List<Todo> todos) {
return todosMapByDayOfWeek;
}

public static Map<Integer, Set<Todo>> mapByDayOfWeekToMyTodosList(Onboarding me, List<Todo> todos) {
Map<Integer, Set<Todo>> 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<Todo> todosByDayOfWeek = todosMapByDayOfWeek.get(redo.getDayOfWeek().getIndex());
todosByDayOfWeek.add(todo);
todosMapByDayOfWeek.put(redo.getDayOfWeek().getIndex(), todosByDayOfWeek);
});
}
}
));
return todosMapByDayOfWeek;
}

public static List<Todo> filterDayMyTodos(LocalDate day, Onboarding me, List<Todo> todos) {
Set<Todo> dayMyTodosSet = new HashSet<>();
List<Todo> 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);
}

Expand Down

0 comments on commit 7648be3

Please sign in to comment.