-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
962ede0
commit 7d624cc
Showing
8 changed files
with
168 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 20 additions & 4 deletions
24
server/src/main/java/server/haengdong/presentation/response/ActionsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
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(List<ActionResponse> actions) { | ||
public record ActionsResponse( | ||
String type, | ||
String stepName, | ||
Set<String> members, | ||
List<ActionResponse> actions | ||
) { | ||
|
||
public static ActionsResponse of(List<ActionAppResponse> actions) { | ||
List<ActionResponse> actionResponses = actions.stream().map(ActionResponse::of).toList(); | ||
return new ActionsResponse(actionResponses); | ||
public static ActionsResponse of(List<ActionAppResponse> actions, Set<String> members) { | ||
List<ActionResponse> actionResponses = actions.stream() | ||
.map(ActionResponse::of) | ||
.toList(); | ||
|
||
String actionType = actions.get(0).actionTypeName(); | ||
return new ActionsResponse( | ||
actionType, | ||
null, | ||
new HashSet<>(members), | ||
actionResponses | ||
); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
server/src/main/java/server/haengdong/presentation/response/StepResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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<ActionsResponse> steps | ||
) { | ||
|
||
public static StepResponse of(List<ActionAppResponse> actions) { | ||
List<ActionsResponse> actionsResponse = new ArrayList<>(); | ||
Set<String> members = new HashSet<>(); | ||
ActionAppResponse firstAction = getFirstAction(actions); | ||
List<ActionAppResponse> 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; | ||
} | ||
if (currentActionType.equals("BILL")) { | ||
actionsResponse.add(ActionsResponse.of(group, members)); | ||
} else { | ||
actionsResponse.add(ActionsResponse.of(group, Set.of())); | ||
} | ||
currentActionType = typeName; | ||
group.clear(); | ||
if (typeName.equals("IN")) { | ||
members.add(action.name()); | ||
} | ||
if (typeName.equals("OUT")) { | ||
members.remove(action.name()); | ||
} | ||
group.add(action); | ||
} | ||
|
||
if (currentActionType.equals("BILL")) { | ||
actionsResponse.add(ActionsResponse.of(group, members)); | ||
} else { | ||
actionsResponse.add(ActionsResponse.of(group, null)); | ||
} | ||
|
||
return new StepResponse(actionsResponse); | ||
} | ||
|
||
private static ActionAppResponse getFirstAction(List<ActionAppResponse> actions) { | ||
return actions.get(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
server/src/test/java/server/haengdong/presentation/response/StepResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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> 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); | ||
} | ||
} |