From b137d110043b1d8d27c0a092c126c8c59798a7ec Mon Sep 17 00:00:00 2001 From: Arachneee Date: Sat, 27 Jul 2024 00:09:57 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20=EC=95=A1=EC=85=98=20?= =?UTF-8?q?=EC=9D=B4=EB=A0=A5=20=EC=A1=B0=ED=9A=8C=20response=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/EventController.java | 8 +-- .../response/ActionsResponse.java | 28 -------- .../presentation/response/StepResponse.java | 60 +++++------------ .../response/StepResponseTest.java | 57 ---------------- .../response/StepsResponseTest.java | 65 +++++++++++++++++++ 5 files changed, 84 insertions(+), 134 deletions(-) delete mode 100644 server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java delete mode 100644 server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java create mode 100644 server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java diff --git a/server/src/main/java/server/haengdong/presentation/EventController.java b/server/src/main/java/server/haengdong/presentation/EventController.java index 9fbe098c..816e7ed2 100644 --- a/server/src/main/java/server/haengdong/presentation/EventController.java +++ b/server/src/main/java/server/haengdong/presentation/EventController.java @@ -12,7 +12,7 @@ import server.haengdong.presentation.request.EventSaveRequest; import server.haengdong.presentation.response.EventDetailResponse; import server.haengdong.presentation.response.EventResponse; -import server.haengdong.presentation.response.StepResponse; +import server.haengdong.presentation.response.StepsResponse; @RequiredArgsConstructor @RestController @@ -35,9 +35,9 @@ public ResponseEntity findEvent(@PathVariable("eventId") St } @GetMapping("/api/events/{eventId}/actions") - public ResponseEntity findActions(@PathVariable("eventId") String token) { - StepResponse stepResponse = StepResponse.of(eventService.findActions(token)); + public ResponseEntity findActions(@PathVariable("eventId") String token) { + StepsResponse stepsResponse = StepsResponse.of(eventService.findActions(token)); - return ResponseEntity.ok(stepResponse); + return ResponseEntity.ok(stepsResponse); } } diff --git a/server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java b/server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java deleted file mode 100644 index 188c48dc..00000000 --- a/server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package server.haengdong.presentation.response; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import server.haengdong.application.response.ActionAppResponse; - -public record ActionsResponse( - String type, - String stepName, - Set members, - List actions -) { - - public static ActionsResponse of(List actions, Set members) { - List actionResponses = actions.stream() - .map(ActionResponse::of) - .toList(); - - String actionType = actions.get(0).actionTypeName(); - return new ActionsResponse( - actionType, - null, - new HashSet<>(members), - actionResponses - ); - } -} diff --git a/server/src/main/java/server/haengdong/presentation/response/StepResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepResponse.java index a8f3877e..0883bb77 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepResponse.java @@ -1,57 +1,27 @@ package server.haengdong.presentation.response; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import server.haengdong.application.response.ActionAppResponse; public record StepResponse( - List steps + String type, + String stepName, + List members, + List actions ) { - - public static StepResponse of(List actions) { - if (actions.isEmpty()) { - return new StepResponse(List.of()); - } - List actionsResponse = new ArrayList<>(); - Set members = new HashSet<>(); - ActionAppResponse firstAction = getFirstAction(actions); - List group = new ArrayList<>(); - group.add(firstAction); - String currentActionType = firstAction.actionTypeName(); - members.add(firstAction.name()); - - for (int i = 1; i < actions.size(); i++) { - ActionAppResponse action = actions.get(i); - String typeName = action.actionTypeName(); - if (currentActionType.equals(typeName)) { - if (typeName.equals("IN")) { - members.add(action.name()); - } - if (typeName.equals("OUT")) { - members.remove(action.name()); - } - group.add(action); - continue; - } - actionsResponse.add(ActionsResponse.of(group, members)); - currentActionType = typeName; - group.clear(); - if (typeName.equals("IN")) { - members.add(action.name()); - } - if (typeName.equals("OUT")) { - members.remove(action.name()); - } - group.add(action); - } - actionsResponse.add(ActionsResponse.of(group, members)); - - return new StepResponse(actionsResponse); + public static StepResponse of(List actions, List members, String stepName) { + return new StepResponse( + actions.get(0).actionTypeName(), + stepName, + new ArrayList<>(members), + toActionsResponse(actions) + ); } - private static ActionAppResponse getFirstAction(List actions) { - return actions.get(0); + private static List toActionsResponse(List actions) { + return actions.stream() + .map(ActionResponse::of) + .toList(); } } diff --git a/server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java b/server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java deleted file mode 100644 index aac78691..00000000 --- a/server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package server.haengdong.presentation.response; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.ArrayList; -import java.util.List; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import server.haengdong.application.response.ActionAppResponse; -import server.haengdong.application.response.ActionAppResponse.ActionType; - -@SpringBootTest -class StepResponseTest { - - @Autowired - private ObjectMapper objectMapper; - - @DisplayName("") - @Test - void test() throws JsonProcessingException { - List actionAppResponse = new ArrayList<>(); - - // IN actions - ActionAppResponse actionAppResponse1 = new ActionAppResponse(3L, "망쵸", null, 3L, ActionType.IN); - actionAppResponse.add(actionAppResponse1); - ActionAppResponse actionAppResponse2 = new ActionAppResponse(4L, "백호", null, 4L, ActionType.IN); - actionAppResponse.add(actionAppResponse2); - - // BILL step 1 - ActionAppResponse actionAppResponse3 = new ActionAppResponse(1L, "감자탕", 10000L, 1L, ActionType.BILL); - actionAppResponse.add(actionAppResponse3); - ActionAppResponse actionAppResponse4 = new ActionAppResponse(2L, "인생네컷", 10000L, 2L, ActionType.BILL); - actionAppResponse.add(actionAppResponse4); - - // IN actions - ActionAppResponse actionAppResponse5 = new ActionAppResponse(5L, "소하", null, 5L, ActionType.IN); - actionAppResponse.add(actionAppResponse5); - ActionAppResponse actionAppResponse6 = new ActionAppResponse(6L, "웨디", null, 6L, ActionType.IN); - actionAppResponse.add(actionAppResponse6); - - // OUT actions - ActionAppResponse actionAppResponse7 = new ActionAppResponse(7L, "망쵸", null, 7L, ActionType.OUT); - actionAppResponse.add(actionAppResponse7); - ActionAppResponse actionAppResponse8 = new ActionAppResponse(8L, "백호", null, 8L, ActionType.OUT); - actionAppResponse.add(actionAppResponse8); - - // BILL step 2 - ActionAppResponse actionAppResponse9 = new ActionAppResponse(9L, "노래방", 20000L, 10L, ActionType.BILL); - actionAppResponse.add(actionAppResponse9); - - // StepResponse creation - StepResponse stepResponse = StepResponse.of(actionAppResponse); - System.out.println("stepResponse = " + stepResponse); - } -} diff --git a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java new file mode 100644 index 00000000..539332ae --- /dev/null +++ b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java @@ -0,0 +1,65 @@ +package server.haengdong.presentation.response; + + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import server.haengdong.application.response.ActionAppResponse; +import server.haengdong.application.response.ActionAppResponse.ActionType; + +class StepsResponseTest { + + @DisplayName("액션들로 액션을 그룹화 한다.") + @Test + void of() { + List actions = List.of( + new ActionAppResponse(1L, "망쵸", null, 1L, ActionType.IN), + new ActionAppResponse(2L, "백호", null, 2L, ActionType.IN), + new ActionAppResponse(3L, "감자탕", 10_000L, 3L, ActionType.BILL), + new ActionAppResponse(4L, "인생네컷", 10_000L, 4L, ActionType.BILL), + new ActionAppResponse(5L, "소하", null, 5L, ActionType.IN), + new ActionAppResponse(6L, "웨디", null, 6L, ActionType.IN), + new ActionAppResponse(7L, "망쵸", null, 7L, ActionType.OUT), + new ActionAppResponse(8L, "백호", null, 8L, ActionType.OUT), + new ActionAppResponse(9L, "노래방", 20_000L, 9L, ActionType.BILL) + ); + + StepsResponse stepsResponse = StepsResponse.of(actions); + + StepsResponse expected = new StepsResponse( + List.of( + new StepResponse("IN", "0차", List.of("망쵸", "백호"), List.of( + new ActionResponse(1L, "망쵸", null, 1L), + new ActionResponse(2L, "백호", null, 2L) + )), + new StepResponse("BILL", "1차", List.of("망쵸", "백호"), List.of( + new ActionResponse(3L, "감자탕", 10_000L, 3L), + new ActionResponse(4L, "인생네컷", 10_000L, 4L) + )), + new StepResponse("IN", "1차", List.of("망쵸", "백호", "소하", "웨디"), List.of( + new ActionResponse(5L, "소하", null, 5L), + new ActionResponse(6L, "웨디", null, 6L) + )), + new StepResponse("OUT", "1차", List.of("소하", "웨디"), List.of( + new ActionResponse(7L, "망쵸", null, 7L), + new ActionResponse(8L, "백호", null, 8L) + )), + new StepResponse("BILL", "2차", List.of("소하", "웨디"), List.of( + new ActionResponse(9L, "노래방", 20_000L, 9L) + )) + ) + ); + + assertThat(stepsResponse).isEqualTo(expected); + } + + @DisplayName("액션이 없으면 빈 스탭들이 만들어진다.") + @Test + void ofEmpty() { + StepsResponse stepsResponse = StepsResponse.of(List.of()); + + assertThat(stepsResponse.steps()).isEmpty(); + } +} From 0bd9b88cf7e31b7cd2a1fcda7f4c522d18cfb36d Mon Sep 17 00:00:00 2001 From: Arachneee Date: Sat, 27 Jul 2024 00:09:57 +0900 Subject: [PATCH 02/10] =?UTF-8?q?refactor:=20=EC=95=A1=EC=85=98=20?= =?UTF-8?q?=EC=9D=B4=EB=A0=A5=20=EC=A1=B0=ED=9A=8C=20response=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/EventController.java | 8 +-- .../response/ActionsResponse.java | 28 -------- .../presentation/response/StepResponse.java | 60 +++++------------ .../presentation/response/StepsResponse.java | 55 ++++++++++++++++ .../response/StepResponseTest.java | 57 ---------------- .../response/StepsResponseTest.java | 65 +++++++++++++++++++ 6 files changed, 139 insertions(+), 134 deletions(-) delete mode 100644 server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java create mode 100644 server/src/main/java/server/haengdong/presentation/response/StepsResponse.java delete mode 100644 server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java create mode 100644 server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java diff --git a/server/src/main/java/server/haengdong/presentation/EventController.java b/server/src/main/java/server/haengdong/presentation/EventController.java index 9fbe098c..816e7ed2 100644 --- a/server/src/main/java/server/haengdong/presentation/EventController.java +++ b/server/src/main/java/server/haengdong/presentation/EventController.java @@ -12,7 +12,7 @@ import server.haengdong.presentation.request.EventSaveRequest; import server.haengdong.presentation.response.EventDetailResponse; import server.haengdong.presentation.response.EventResponse; -import server.haengdong.presentation.response.StepResponse; +import server.haengdong.presentation.response.StepsResponse; @RequiredArgsConstructor @RestController @@ -35,9 +35,9 @@ public ResponseEntity findEvent(@PathVariable("eventId") St } @GetMapping("/api/events/{eventId}/actions") - public ResponseEntity findActions(@PathVariable("eventId") String token) { - StepResponse stepResponse = StepResponse.of(eventService.findActions(token)); + public ResponseEntity findActions(@PathVariable("eventId") String token) { + StepsResponse stepsResponse = StepsResponse.of(eventService.findActions(token)); - return ResponseEntity.ok(stepResponse); + return ResponseEntity.ok(stepsResponse); } } diff --git a/server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java b/server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java deleted file mode 100644 index 188c48dc..00000000 --- a/server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package server.haengdong.presentation.response; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import server.haengdong.application.response.ActionAppResponse; - -public record ActionsResponse( - String type, - String stepName, - Set members, - List actions -) { - - public static ActionsResponse of(List actions, Set members) { - List actionResponses = actions.stream() - .map(ActionResponse::of) - .toList(); - - String actionType = actions.get(0).actionTypeName(); - return new ActionsResponse( - actionType, - null, - new HashSet<>(members), - actionResponses - ); - } -} diff --git a/server/src/main/java/server/haengdong/presentation/response/StepResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepResponse.java index a8f3877e..0883bb77 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepResponse.java @@ -1,57 +1,27 @@ package server.haengdong.presentation.response; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import server.haengdong.application.response.ActionAppResponse; public record StepResponse( - List steps + String type, + String stepName, + List members, + List actions ) { - - public static StepResponse of(List actions) { - if (actions.isEmpty()) { - return new StepResponse(List.of()); - } - List actionsResponse = new ArrayList<>(); - Set members = new HashSet<>(); - ActionAppResponse firstAction = getFirstAction(actions); - List group = new ArrayList<>(); - group.add(firstAction); - String currentActionType = firstAction.actionTypeName(); - members.add(firstAction.name()); - - for (int i = 1; i < actions.size(); i++) { - ActionAppResponse action = actions.get(i); - String typeName = action.actionTypeName(); - if (currentActionType.equals(typeName)) { - if (typeName.equals("IN")) { - members.add(action.name()); - } - if (typeName.equals("OUT")) { - members.remove(action.name()); - } - group.add(action); - continue; - } - actionsResponse.add(ActionsResponse.of(group, members)); - currentActionType = typeName; - group.clear(); - if (typeName.equals("IN")) { - members.add(action.name()); - } - if (typeName.equals("OUT")) { - members.remove(action.name()); - } - group.add(action); - } - actionsResponse.add(ActionsResponse.of(group, members)); - - return new StepResponse(actionsResponse); + public static StepResponse of(List actions, List members, String stepName) { + return new StepResponse( + actions.get(0).actionTypeName(), + stepName, + new ArrayList<>(members), + toActionsResponse(actions) + ); } - private static ActionAppResponse getFirstAction(List actions) { - return actions.get(0); + private static List toActionsResponse(List actions) { + return actions.stream() + .map(ActionResponse::of) + .toList(); } } diff --git a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java new file mode 100644 index 00000000..567980d9 --- /dev/null +++ b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java @@ -0,0 +1,55 @@ +package server.haengdong.presentation.response; + +import java.util.ArrayList; +import java.util.List; +import server.haengdong.application.response.ActionAppResponse; +import server.haengdong.application.response.ActionAppResponse.ActionType; + +public record StepsResponse(List steps) { + + public static StepsResponse of(List actions) { + List steps = new ArrayList<>(); + List currentMembers = new ArrayList<>(); + List> groups = createGroups(actions); + + int billGroupCount = 0; + for (List group : groups) { + changeCurrentMembers(group, currentMembers); + if (group.get(0).actionType() == ActionType.BILL) { + billGroupCount++; + } + StepResponse stepResponse = StepResponse.of(group, currentMembers, billGroupCount + "차"); + steps.add(stepResponse); + } + return new StepsResponse(steps); + } + + private static List> createGroups(List actions) { + List> groups = new ArrayList<>(); + + for (ActionAppResponse action : actions) { + if (groups.isEmpty() || isActionTypeChange(action, groups)) { + groups.add(new ArrayList<>()); + } + groups.get(groups.size() - 1).add(action); + } + return groups; + } + + private static boolean isActionTypeChange(ActionAppResponse action, List> groups) { + List currentGroup = groups.get(groups.size() - 1); + return currentGroup.get(0).actionType() != action.actionType(); + } + + private static void changeCurrentMembers(List group, List currentMembers) { + for (ActionAppResponse action : group) { + if (action.actionType() == ActionType.IN) { + currentMembers.add(action.name()); + continue; + } + if (action.actionType() == ActionType.OUT) { + currentMembers.remove(action.name()); + } + } + } +} diff --git a/server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java b/server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java deleted file mode 100644 index aac78691..00000000 --- a/server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package server.haengdong.presentation.response; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.ArrayList; -import java.util.List; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import server.haengdong.application.response.ActionAppResponse; -import server.haengdong.application.response.ActionAppResponse.ActionType; - -@SpringBootTest -class StepResponseTest { - - @Autowired - private ObjectMapper objectMapper; - - @DisplayName("") - @Test - void test() throws JsonProcessingException { - List actionAppResponse = new ArrayList<>(); - - // IN actions - ActionAppResponse actionAppResponse1 = new ActionAppResponse(3L, "망쵸", null, 3L, ActionType.IN); - actionAppResponse.add(actionAppResponse1); - ActionAppResponse actionAppResponse2 = new ActionAppResponse(4L, "백호", null, 4L, ActionType.IN); - actionAppResponse.add(actionAppResponse2); - - // BILL step 1 - ActionAppResponse actionAppResponse3 = new ActionAppResponse(1L, "감자탕", 10000L, 1L, ActionType.BILL); - actionAppResponse.add(actionAppResponse3); - ActionAppResponse actionAppResponse4 = new ActionAppResponse(2L, "인생네컷", 10000L, 2L, ActionType.BILL); - actionAppResponse.add(actionAppResponse4); - - // IN actions - ActionAppResponse actionAppResponse5 = new ActionAppResponse(5L, "소하", null, 5L, ActionType.IN); - actionAppResponse.add(actionAppResponse5); - ActionAppResponse actionAppResponse6 = new ActionAppResponse(6L, "웨디", null, 6L, ActionType.IN); - actionAppResponse.add(actionAppResponse6); - - // OUT actions - ActionAppResponse actionAppResponse7 = new ActionAppResponse(7L, "망쵸", null, 7L, ActionType.OUT); - actionAppResponse.add(actionAppResponse7); - ActionAppResponse actionAppResponse8 = new ActionAppResponse(8L, "백호", null, 8L, ActionType.OUT); - actionAppResponse.add(actionAppResponse8); - - // BILL step 2 - ActionAppResponse actionAppResponse9 = new ActionAppResponse(9L, "노래방", 20000L, 10L, ActionType.BILL); - actionAppResponse.add(actionAppResponse9); - - // StepResponse creation - StepResponse stepResponse = StepResponse.of(actionAppResponse); - System.out.println("stepResponse = " + stepResponse); - } -} diff --git a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java new file mode 100644 index 00000000..539332ae --- /dev/null +++ b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java @@ -0,0 +1,65 @@ +package server.haengdong.presentation.response; + + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import server.haengdong.application.response.ActionAppResponse; +import server.haengdong.application.response.ActionAppResponse.ActionType; + +class StepsResponseTest { + + @DisplayName("액션들로 액션을 그룹화 한다.") + @Test + void of() { + List actions = List.of( + new ActionAppResponse(1L, "망쵸", null, 1L, ActionType.IN), + new ActionAppResponse(2L, "백호", null, 2L, ActionType.IN), + new ActionAppResponse(3L, "감자탕", 10_000L, 3L, ActionType.BILL), + new ActionAppResponse(4L, "인생네컷", 10_000L, 4L, ActionType.BILL), + new ActionAppResponse(5L, "소하", null, 5L, ActionType.IN), + new ActionAppResponse(6L, "웨디", null, 6L, ActionType.IN), + new ActionAppResponse(7L, "망쵸", null, 7L, ActionType.OUT), + new ActionAppResponse(8L, "백호", null, 8L, ActionType.OUT), + new ActionAppResponse(9L, "노래방", 20_000L, 9L, ActionType.BILL) + ); + + StepsResponse stepsResponse = StepsResponse.of(actions); + + StepsResponse expected = new StepsResponse( + List.of( + new StepResponse("IN", "0차", List.of("망쵸", "백호"), List.of( + new ActionResponse(1L, "망쵸", null, 1L), + new ActionResponse(2L, "백호", null, 2L) + )), + new StepResponse("BILL", "1차", List.of("망쵸", "백호"), List.of( + new ActionResponse(3L, "감자탕", 10_000L, 3L), + new ActionResponse(4L, "인생네컷", 10_000L, 4L) + )), + new StepResponse("IN", "1차", List.of("망쵸", "백호", "소하", "웨디"), List.of( + new ActionResponse(5L, "소하", null, 5L), + new ActionResponse(6L, "웨디", null, 6L) + )), + new StepResponse("OUT", "1차", List.of("소하", "웨디"), List.of( + new ActionResponse(7L, "망쵸", null, 7L), + new ActionResponse(8L, "백호", null, 8L) + )), + new StepResponse("BILL", "2차", List.of("소하", "웨디"), List.of( + new ActionResponse(9L, "노래방", 20_000L, 9L) + )) + ) + ); + + assertThat(stepsResponse).isEqualTo(expected); + } + + @DisplayName("액션이 없으면 빈 스탭들이 만들어진다.") + @Test + void ofEmpty() { + StepsResponse stepsResponse = StepsResponse.of(List.of()); + + assertThat(stepsResponse.steps()).isEmpty(); + } +} From ba0d49fde2253ac2a161b249ff8afe98fbd38517 Mon Sep 17 00:00:00 2001 From: Arachneee Date: Sun, 28 Jul 2024 16:32:17 +0900 Subject: [PATCH 03/10] =?UTF-8?q?test:=20DisplayName=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haengdong/presentation/response/StepsResponseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java index 539332ae..3f221d66 100644 --- a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java +++ b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java @@ -11,7 +11,7 @@ class StepsResponseTest { - @DisplayName("액션들로 액션을 그룹화 한다.") + @DisplayName("이웃한 같은 타입의 액션들을 그룹화 하여 응답객체를 생성한다.") @Test void of() { List actions = List.of( From 772fe4772c9ab58682388bfdf409866b8a1b256d Mon Sep 17 00:00:00 2001 From: Arachneee Date: Mon, 29 Jul 2024 19:38:48 +0900 Subject: [PATCH 04/10] =?UTF-8?q?test:=20=EB=B6=88=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=EA=B3=B5=EB=B0=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haengdong/presentation/response/StepsResponseTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java index 3f221d66..4bba38ef 100644 --- a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java +++ b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java @@ -51,7 +51,6 @@ void of() { )) ) ); - assertThat(stepsResponse).isEqualTo(expected); } @@ -59,7 +58,6 @@ void of() { @Test void ofEmpty() { StepsResponse stepsResponse = StepsResponse.of(List.of()); - assertThat(stepsResponse.steps()).isEmpty(); } } From 938f24e5d114689cac9e82a004318fe1f87f2afd Mon Sep 17 00:00:00 2001 From: Arachneee Date: Mon, 29 Jul 2024 19:58:07 +0900 Subject: [PATCH 05/10] =?UTF-8?q?style:=20=EA=B0=9C=ED=96=89=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/haengdong/presentation/response/StepsResponse.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java index 567980d9..801dae3a 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java @@ -21,6 +21,7 @@ public static StepsResponse of(List actions) { StepResponse stepResponse = StepResponse.of(group, currentMembers, billGroupCount + "차"); steps.add(stepResponse); } + return new StepsResponse(steps); } From 12f39e07a7c18877bebaf8848c0111a00beee3b9 Mon Sep 17 00:00:00 2001 From: Arachneee Date: Mon, 29 Jul 2024 20:00:35 +0900 Subject: [PATCH 06/10] =?UTF-8?q?style:=20=EA=B0=9C=ED=96=89=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/haengdong/presentation/response/StepsResponse.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java index 801dae3a..567980d9 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java @@ -21,7 +21,6 @@ public static StepsResponse of(List actions) { StepResponse stepResponse = StepResponse.of(group, currentMembers, billGroupCount + "차"); steps.add(stepResponse); } - return new StepsResponse(steps); } From 3b6076c2728c6acb5906ed774d0a9a110ad10e8b Mon Sep 17 00:00:00 2001 From: Arachneee Date: Mon, 29 Jul 2024 20:01:38 +0900 Subject: [PATCH 07/10] =?UTF-8?q?style:=20=EA=B0=9C=ED=96=89=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/haengdong/presentation/response/StepsResponse.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java index 567980d9..3a636fe8 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java @@ -33,6 +33,7 @@ private static List> createGroups(List Date: Tue, 30 Jul 2024 00:26:17 +0900 Subject: [PATCH 08/10] =?UTF-8?q?style:=20=EA=B0=9C=ED=96=89=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=EB=8B=A4=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/haengdong/presentation/response/StepsResponse.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java index 3a636fe8..a5adf0cd 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java @@ -21,6 +21,7 @@ public static StepsResponse of(List actions) { StepResponse stepResponse = StepResponse.of(group, currentMembers, billGroupCount + "차"); steps.add(stepResponse); } + return new StepsResponse(steps); } From 5ae22e2abb9ed81b358968ed7ed0a553481a0e0d Mon Sep 17 00:00:00 2001 From: Arachneee Date: Tue, 30 Jul 2024 00:34:39 +0900 Subject: [PATCH 09/10] =?UTF-8?q?style:=20=EA=B0=9C=ED=96=89=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=EB=8B=A4=EC=8B=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/haengdong/presentation/response/StepsResponse.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java index a5adf0cd..3a636fe8 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java @@ -21,7 +21,6 @@ public static StepsResponse of(List actions) { StepResponse stepResponse = StepResponse.of(group, currentMembers, billGroupCount + "차"); steps.add(stepResponse); } - return new StepsResponse(steps); } From d5a2180485251fc57f3017a4215ebe611fcd8e8d Mon Sep 17 00:00:00 2001 From: Arachneee Date: Tue, 30 Jul 2024 19:10:23 +0900 Subject: [PATCH 10/10] =?UTF-8?q?refactor:=20stepName=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haengdong/presentation/response/StepResponse.java | 4 +--- .../haengdong/presentation/response/StepsResponse.java | 6 +----- .../presentation/response/StepsResponseTest.java | 10 +++++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/server/haengdong/presentation/response/StepResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepResponse.java index 0883bb77..c3e854f4 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepResponse.java @@ -6,14 +6,12 @@ public record StepResponse( String type, - String stepName, List members, List actions ) { - public static StepResponse of(List actions, List members, String stepName) { + public static StepResponse of(List members, List actions) { return new StepResponse( actions.get(0).actionTypeName(), - stepName, new ArrayList<>(members), toActionsResponse(actions) ); diff --git a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java index 3a636fe8..ac147387 100644 --- a/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java +++ b/server/src/main/java/server/haengdong/presentation/response/StepsResponse.java @@ -12,13 +12,9 @@ public static StepsResponse of(List actions) { List currentMembers = new ArrayList<>(); List> groups = createGroups(actions); - int billGroupCount = 0; for (List group : groups) { changeCurrentMembers(group, currentMembers); - if (group.get(0).actionType() == ActionType.BILL) { - billGroupCount++; - } - StepResponse stepResponse = StepResponse.of(group, currentMembers, billGroupCount + "차"); + StepResponse stepResponse = StepResponse.of(currentMembers, group); steps.add(stepResponse); } return new StepsResponse(steps); diff --git a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java index 4bba38ef..f8fdb6e7 100644 --- a/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java +++ b/server/src/test/java/server/haengdong/presentation/response/StepsResponseTest.java @@ -30,23 +30,23 @@ void of() { StepsResponse expected = new StepsResponse( List.of( - new StepResponse("IN", "0차", List.of("망쵸", "백호"), List.of( + new StepResponse("IN", List.of("망쵸", "백호"), List.of( new ActionResponse(1L, "망쵸", null, 1L), new ActionResponse(2L, "백호", null, 2L) )), - new StepResponse("BILL", "1차", List.of("망쵸", "백호"), List.of( + new StepResponse("BILL", List.of("망쵸", "백호"), List.of( new ActionResponse(3L, "감자탕", 10_000L, 3L), new ActionResponse(4L, "인생네컷", 10_000L, 4L) )), - new StepResponse("IN", "1차", List.of("망쵸", "백호", "소하", "웨디"), List.of( + new StepResponse("IN", List.of("망쵸", "백호", "소하", "웨디"), List.of( new ActionResponse(5L, "소하", null, 5L), new ActionResponse(6L, "웨디", null, 6L) )), - new StepResponse("OUT", "1차", List.of("소하", "웨디"), List.of( + new StepResponse("OUT", List.of("소하", "웨디"), List.of( new ActionResponse(7L, "망쵸", null, 7L), new ActionResponse(8L, "백호", null, 8L) )), - new StepResponse("BILL", "2차", List.of("소하", "웨디"), List.of( + new StepResponse("BILL", List.of("소하", "웨디"), List.of( new ActionResponse(9L, "노래방", 20_000L, 9L) )) )