From e872df80c49e4d5e95698269259150ed61a02ae0 Mon Sep 17 00:00:00 2001 From: juha Date: Thu, 5 Sep 2024 17:13:37 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20action=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 3juhwan <13selfesteem91@naver.com> Co-authored-by: Arachneee Co-authored-by: kunsanglee --- .../haengdong/application/ActionService.java | 39 ------ .../application/BillActionDetailService.java | 14 +- .../application/BillActionService.java | 41 +++--- .../haengdong/application/EventService.java | 27 +++- .../application/MemberActionFactory.java | 14 +- .../application/MemberActionService.java | 36 ++--- .../request/BillActionAppRequest.java | 7 +- .../request/MemberActionSaveAppRequest.java | 7 +- .../response/ActionAppResponse.java | 8 +- .../haengdong/domain/action/Action.java | 42 ------ .../domain/action/ActionRepository.java | 23 ---- .../haengdong/domain/action/BillAction.java | 35 ++--- .../action/BillActionDetailRepository.java | 2 +- .../domain/action/BillActionRepository.java | 20 +-- .../haengdong/domain/action/MemberAction.java | 29 ++-- .../domain/action/MemberActionRepository.java | 34 +++-- .../domain/action/MemberBillReport.java | 2 +- .../haengdong/domain/action/Sequence.java | 41 ++++++ .../presentation/EventController.java | 4 +- .../application/ActionServiceTest.java | 91 ------------- .../BillActionDetailServiceTest.java | 20 +-- .../application/BillActionServiceTest.java | 58 ++++---- .../application/EventServiceTest.java | 124 ++++++++++++------ .../application/MemberActionFactoryTest.java | 81 ++++++------ .../application/MemberActionServiceTest.java | 82 +++++------- .../docs/EventControllerDocsTest.java | 6 +- .../haengdong/domain/action/ActionTest.java | 31 ----- .../domain/action/BillActionTest.java | 23 ++-- .../domain/action/CurrentMembersTest.java | 14 +- .../domain/action/MemberBillReportTest.java | 12 +- .../haengdong/domain/action/SequenceTest.java | 27 ++++ .../presentation/ControllerTestSupport.java | 4 - .../presentation/EventControllerTest.java | 2 +- .../haengdong/support/fixture/Fixture.java | 17 ++- 34 files changed, 458 insertions(+), 559 deletions(-) delete mode 100644 server/src/main/java/server/haengdong/application/ActionService.java delete mode 100644 server/src/main/java/server/haengdong/domain/action/Action.java delete mode 100644 server/src/main/java/server/haengdong/domain/action/ActionRepository.java create mode 100644 server/src/main/java/server/haengdong/domain/action/Sequence.java delete mode 100644 server/src/test/java/server/haengdong/application/ActionServiceTest.java delete mode 100644 server/src/test/java/server/haengdong/domain/action/ActionTest.java create mode 100644 server/src/test/java/server/haengdong/domain/action/SequenceTest.java diff --git a/server/src/main/java/server/haengdong/application/ActionService.java b/server/src/main/java/server/haengdong/application/ActionService.java deleted file mode 100644 index bcf5e8b55..000000000 --- a/server/src/main/java/server/haengdong/application/ActionService.java +++ /dev/null @@ -1,39 +0,0 @@ -package server.haengdong.application; - -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import server.haengdong.application.response.MemberBillReportAppResponse; -import server.haengdong.domain.action.BillAction; -import server.haengdong.domain.action.BillActionRepository; -import server.haengdong.domain.action.MemberAction; -import server.haengdong.domain.action.MemberActionRepository; -import server.haengdong.domain.action.MemberBillReport; -import server.haengdong.domain.event.Event; -import server.haengdong.domain.event.EventRepository; -import server.haengdong.exception.HaengdongErrorCode; -import server.haengdong.exception.HaengdongException; - -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Service -public class ActionService { - - private final BillActionRepository billActionRepository; - private final MemberActionRepository memberActionRepository; - private final EventRepository eventRepository; - - public List getMemberBillReports(String token) { - Event event = eventRepository.findByToken(token) - .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.EVENT_NOT_FOUND)); - List billActions = billActionRepository.findByAction_Event(event); - List memberActions = memberActionRepository.findAllByEvent(event); - - MemberBillReport memberBillReport = MemberBillReport.createByActions(billActions, memberActions); - - return memberBillReport.getReports().entrySet().stream() - .map(entry -> new MemberBillReportAppResponse(entry.getKey(), entry.getValue())) - .toList(); - } -} diff --git a/server/src/main/java/server/haengdong/application/BillActionDetailService.java b/server/src/main/java/server/haengdong/application/BillActionDetailService.java index 55d39aac0..a4372c62d 100644 --- a/server/src/main/java/server/haengdong/application/BillActionDetailService.java +++ b/server/src/main/java/server/haengdong/application/BillActionDetailService.java @@ -21,8 +21,8 @@ public class BillActionDetailService { private final BillActionRepository billActionRepository; - public BillActionDetailsAppResponse findBillActionDetails(String token, Long actionId) { - BillAction billAction = billActionRepository.findByAction_Id(actionId) + public BillActionDetailsAppResponse findBillActionDetails(String token, Long billActionId) { + BillAction billAction = billActionRepository.findById(billActionId) .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.BILL_ACTION_NOT_FOUND)); validateToken(token, billAction); @@ -31,8 +31,8 @@ public BillActionDetailsAppResponse findBillActionDetails(String token, Long act } @Transactional - public void updateBillActionDetails(String token, Long actionId, BillActionDetailsUpdateAppRequest request) { - BillAction billAction = billActionRepository.findByAction_Id(actionId) + public void updateBillActionDetails(String token, Long billActionId, BillActionDetailsUpdateAppRequest request) { + BillAction billAction = billActionRepository.findById(billActionId) .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.BILL_ACTION_NOT_FOUND)); List billActionDetailUpdateAppRequests = request.billActionDetailUpdateAppRequests(); @@ -60,8 +60,10 @@ private void validateToken(String token, BillAction billAction) { } } - private void validateTotalPrice(List billActionDetailUpdateAppRequests, - BillAction billAction) { + private void validateTotalPrice( + List billActionDetailUpdateAppRequests, + BillAction billAction + ) { Long requestsPriceSum = calculateUpdatePriceSum(billActionDetailUpdateAppRequests); if (!billAction.isSamePrice(requestsPriceSum)) { throw new HaengdongException(HaengdongErrorCode.BILL_ACTION_PRICE_NOT_MATCHED); diff --git a/server/src/main/java/server/haengdong/application/BillActionService.java b/server/src/main/java/server/haengdong/application/BillActionService.java index dae36a2e7..9453a2d5f 100644 --- a/server/src/main/java/server/haengdong/application/BillActionService.java +++ b/server/src/main/java/server/haengdong/application/BillActionService.java @@ -6,13 +6,12 @@ import org.springframework.transaction.annotation.Transactional; import server.haengdong.application.request.BillActionAppRequest; import server.haengdong.application.request.BillActionUpdateAppRequest; -import server.haengdong.domain.action.Action; -import server.haengdong.domain.action.ActionRepository; import server.haengdong.domain.action.BillAction; import server.haengdong.domain.action.BillActionRepository; import server.haengdong.domain.action.CurrentMembers; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionRepository; +import server.haengdong.domain.action.Sequence; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.exception.HaengdongErrorCode; @@ -25,33 +24,35 @@ public class BillActionService { private final BillActionRepository billActionRepository; private final MemberActionRepository memberActionRepository; - private final ActionRepository actionRepository; private final EventRepository eventRepository; @Transactional public void saveAllBillAction(String eventToken, List requests) { Event event = getEvent(eventToken); - Action action = createStartAction(event); + Sequence sequence = createStartSequence(event); List findMemberActions = memberActionRepository.findAllByEvent(event); CurrentMembers currentMembers = CurrentMembers.of(findMemberActions); for (BillActionAppRequest request : requests) { - BillAction billAction = request.toBillAction(action, currentMembers); + BillAction billAction = request.toBillAction(event, sequence, currentMembers); billActionRepository.save(billAction); - action = action.next(); + sequence = sequence.next(); } } - private Action createStartAction(Event event) { - return actionRepository.findLastByEvent(event) - .map(Action::next) - .orElse(Action.createFirst(event)); + private Sequence createStartSequence(Event event) { + Sequence memberActionSequence = memberActionRepository.findLastByEvent(event) + .map(MemberAction::getSequence) + .orElseGet(Sequence::createFirst); + Sequence billActionSequence = billActionRepository.findLastByEvent(event) + .map(BillAction::getSequence) + .orElseGet(Sequence::createFirst); + return Sequence.getGreater(memberActionSequence, billActionSequence).next(); } @Transactional - public void updateBillAction(String token, Long actionId, BillActionUpdateAppRequest request) { - BillAction billAction = billActionRepository.findByAction_Id(actionId) - .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.BILL_ACTION_NOT_FOUND)); + public void updateBillAction(String token, Long billActionId, BillActionUpdateAppRequest request) { + BillAction billAction = getBillAction(billActionId); validateToken(token, billAction); @@ -66,15 +67,19 @@ private void validateToken(String token, BillAction billAction) { } @Transactional - public void deleteBillAction(String token, Long actionId) { - Event event = eventRepository.findByToken(token) - .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.EVENT_NOT_FOUND)); - - billActionRepository.deleteByAction_EventAndActionId(event, actionId); + public void deleteBillAction(String token, Long billActionId) { + BillAction billAction = getBillAction(billActionId); + validateToken(token, billAction); + billActionRepository.deleteById(billActionId); } private Event getEvent(String eventToken) { return eventRepository.findByToken(eventToken) .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.EVENT_NOT_FOUND)); } + + private BillAction getBillAction(Long billActionId) { + return billActionRepository.findById(billActionId) + .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.BILL_ACTION_NOT_FOUND)); + } } diff --git a/server/src/main/java/server/haengdong/application/EventService.java b/server/src/main/java/server/haengdong/application/EventService.java index 1aaddd0f9..106186af3 100644 --- a/server/src/main/java/server/haengdong/application/EventService.java +++ b/server/src/main/java/server/haengdong/application/EventService.java @@ -14,12 +14,14 @@ import server.haengdong.application.response.ActionAppResponse; import server.haengdong.application.response.EventAppResponse; import server.haengdong.application.response.EventDetailAppResponse; +import server.haengdong.application.response.MemberBillReportAppResponse; import server.haengdong.application.response.MembersAppResponse; import server.haengdong.domain.action.BillAction; import server.haengdong.domain.action.BillActionDetailRepository; import server.haengdong.domain.action.BillActionRepository; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionRepository; +import server.haengdong.domain.action.MemberBillReport; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.domain.event.EventTokenProvider; @@ -57,7 +59,7 @@ public EventDetailAppResponse findEvent(String token) { public List findActions(String token) { Event event = getEvent(token); - List billActions = billActionRepository.findByAction_Event(event).stream() + List billActions = billActionRepository.findByEvent(event).stream() .sorted(Comparator.comparing(BillAction::getSequence)).toList(); List memberActions = memberActionRepository.findAllByEvent(event).stream() .sorted(Comparator.comparing(MemberAction::getSequence)).toList(); @@ -76,7 +78,7 @@ private List getActionAppResponses( while (billActionIndex < billActions.size() && memberActionIndex < memberActions.size()) { BillAction billAction = billActions.get(billActionIndex); MemberAction memberAction = memberActions.get(memberActionIndex); - if (billAction.getSequence() < memberAction.getSequence()) { + if (billAction.getSequence().getValue() < memberAction.getSequence().getValue()) { actionAppResponses.add(ActionAppResponse.of(billAction)); billActionIndex++; } else { @@ -126,7 +128,7 @@ private void validateBeforeNames(List members, Event } private void validateBeforeMemberNameExist(Event event, String beforeName) { - boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, beforeName); + boolean isMemberNameExist = memberActionRepository.existsByEventAndMemberName(event, beforeName); if (!isMemberNameExist) { throw new HaengdongException(HaengdongErrorCode.MEMBER_NOT_EXIST); } @@ -143,16 +145,16 @@ private void validateAfterNames(List members, Event } private void validateAfterMemberNameNotExist(Event event, String afterName) { - boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, afterName); + boolean isMemberNameExist = memberActionRepository.existsByEventAndMemberName(event, afterName); if (isMemberNameExist) { throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_DUPLICATE); } } private void updateMemberName(Event event, String beforeName, String afterName) { - memberActionRepository.findAllByAction_EventAndMemberName(event, beforeName) + memberActionRepository.findAllByEventAndMemberName(event, beforeName) .forEach(memberAction -> memberAction.updateMemberName(afterName)); - billActionDetailRepository.findAllByBillAction_Action_EventAndMemberName(event, beforeName) + billActionDetailRepository.findAllByBillAction_EventAndMemberName(event, beforeName) .forEach(billActionDetail -> billActionDetail.updateMemberName(afterName)); } @@ -167,4 +169,17 @@ private Event getEvent(String token) { return eventRepository.findByToken(token) .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.EVENT_NOT_FOUND)); } + + public List getMemberBillReports(String token) { + Event event = eventRepository.findByToken(token) + .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.EVENT_NOT_FOUND)); + List billActions = billActionRepository.findByEvent(event); + List memberActions = memberActionRepository.findAllByEvent(event); + + MemberBillReport memberBillReport = MemberBillReport.createByActions(billActions, memberActions); + + return memberBillReport.getReports().entrySet().stream() + .map(entry -> new MemberBillReportAppResponse(entry.getKey(), entry.getValue())) + .toList(); + } } diff --git a/server/src/main/java/server/haengdong/application/MemberActionFactory.java b/server/src/main/java/server/haengdong/application/MemberActionFactory.java index c0a171642..97fa1038c 100644 --- a/server/src/main/java/server/haengdong/application/MemberActionFactory.java +++ b/server/src/main/java/server/haengdong/application/MemberActionFactory.java @@ -6,11 +6,11 @@ import org.springframework.stereotype.Component; import server.haengdong.application.request.MemberActionSaveAppRequest; import server.haengdong.application.request.MemberActionsSaveAppRequest; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.CurrentMembers; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionStatus; -import server.haengdong.domain.action.MemberGroupIdProvider; +import server.haengdong.domain.action.Sequence; +import server.haengdong.domain.event.Event; import server.haengdong.exception.HaengdongErrorCode; import server.haengdong.exception.HaengdongException; @@ -18,23 +18,21 @@ @Component public class MemberActionFactory { - private final MemberGroupIdProvider memberGroupIdProvider; - public List createMemberActions( + Event event, MemberActionsSaveAppRequest request, CurrentMembers currentMembers, - Action action + Sequence sequence ) { validateMemberNames(request); validateActions(request, currentMembers); - Long memberGroupId = memberGroupIdProvider.createGroupId(); List createdMemberActions = new ArrayList<>(); List actions = request.actions(); for (MemberActionSaveAppRequest appRequest : actions) { - MemberAction memberAction = appRequest.toMemberAction(action, memberGroupId); + MemberAction memberAction = appRequest.toMemberAction(event, sequence); createdMemberActions.add(memberAction); - action = action.next(); + sequence = sequence.next(); } return createdMemberActions; diff --git a/server/src/main/java/server/haengdong/application/MemberActionService.java b/server/src/main/java/server/haengdong/application/MemberActionService.java index 245de8cef..26186c08a 100644 --- a/server/src/main/java/server/haengdong/application/MemberActionService.java +++ b/server/src/main/java/server/haengdong/application/MemberActionService.java @@ -6,13 +6,12 @@ import org.springframework.transaction.annotation.Transactional; import server.haengdong.application.request.MemberActionsSaveAppRequest; import server.haengdong.application.response.CurrentMemberAppResponse; -import server.haengdong.domain.action.Action; -import server.haengdong.domain.action.ActionRepository; import server.haengdong.domain.action.BillAction; import server.haengdong.domain.action.BillActionRepository; import server.haengdong.domain.action.CurrentMembers; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionRepository; +import server.haengdong.domain.action.Sequence; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.exception.HaengdongErrorCode; @@ -26,7 +25,6 @@ public class MemberActionService { private final MemberActionFactory memberActionFactory; private final MemberActionRepository memberActionRepository; private final EventRepository eventRepository; - private final ActionRepository actionRepository; private final BillActionRepository billActionRepository; @Transactional @@ -35,15 +33,20 @@ public void saveMemberAction(String token, MemberActionsSaveAppRequest request) List findMemberActions = memberActionRepository.findAllByEvent(event); CurrentMembers currentMembers = CurrentMembers.of(findMemberActions); - Action action = createStartAction(event); - List memberActions = memberActionFactory.createMemberActions(request, currentMembers, action); + Sequence sequence = createStartSequence(event); + List memberActions = memberActionFactory.createMemberActions(event, request, currentMembers, + sequence); memberActionRepository.saveAll(memberActions); } - private Action createStartAction(Event event) { - return actionRepository.findLastByEvent(event) - .map(Action::next) - .orElse(Action.createFirst(event)); + private Sequence createStartSequence(Event event) { + Sequence memberActionSequence = memberActionRepository.findLastByEvent(event) + .map(MemberAction::getSequence) + .orElseGet(Sequence::createFirst); + Sequence billActionSequence = billActionRepository.findLastByEvent(event) + .map(BillAction::getSequence) + .orElseGet(Sequence::createFirst); + return Sequence.getGreater(memberActionSequence, billActionSequence).next(); } public List getCurrentMembers(String token) { @@ -69,30 +72,27 @@ public void deleteMember(String token, String memberName) { memberActionRepository.deleteAllByEventAndMemberName(event, memberName); - List billActions = billActionRepository.findByAction_Event(event); + List billActions = billActionRepository.findByEvent(event); billActions.forEach(billAction -> resetBillAction(event, billAction)); } @Transactional - public void deleteMemberAction(String token, Long actionId) { + public void deleteMemberAction(String token, Long id) { Event event = eventRepository.findByToken(token) .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.EVENT_NOT_FOUND)); - Action action = actionRepository.findByIdAndEvent(actionId, event) - .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.ACTION_NOT_FOUND)); - MemberAction memberAction = memberActionRepository.findByAction(action) - .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.MEMBER_ACTION_NOT_FOUND)); + MemberAction memberAction = memberActionRepository.findByIdAndEvent(id, event); memberActionRepository.deleteAllByMemberNameAndMinSequence(memberAction.getMemberName(), - memberAction.getSequence()); + memberAction.getSequence().getValue()); List billActions = billActionRepository.findByEventAndGreaterThanSequence(event, - action.getSequence()); + memberAction.getSequence().getValue()); billActions.forEach(billAction -> resetBillAction(event, billAction)); } private void resetBillAction(Event event, BillAction billAction) { List memberActions = memberActionRepository.findByEventAndSequence(event, - billAction.getSequence()); + billAction.getSequence().getValue()); CurrentMembers currentMembers = CurrentMembers.of(memberActions); billAction.resetBillActionDetails(currentMembers); diff --git a/server/src/main/java/server/haengdong/application/request/BillActionAppRequest.java b/server/src/main/java/server/haengdong/application/request/BillActionAppRequest.java index 21eb17d4a..c702fd0be 100644 --- a/server/src/main/java/server/haengdong/application/request/BillActionAppRequest.java +++ b/server/src/main/java/server/haengdong/application/request/BillActionAppRequest.java @@ -1,15 +1,16 @@ package server.haengdong.application.request; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.BillAction; import server.haengdong.domain.action.CurrentMembers; +import server.haengdong.domain.action.Sequence; +import server.haengdong.domain.event.Event; public record BillActionAppRequest( String title, Long price ) { - public BillAction toBillAction(Action action, CurrentMembers currentMembers) { - return BillAction.create(action, title, price, currentMembers); + public BillAction toBillAction(Event event, Sequence sequence, CurrentMembers currentMembers) { + return BillAction.create(event, sequence, title, price, currentMembers); } } diff --git a/server/src/main/java/server/haengdong/application/request/MemberActionSaveAppRequest.java b/server/src/main/java/server/haengdong/application/request/MemberActionSaveAppRequest.java index f7f8d8fc2..f56b89517 100644 --- a/server/src/main/java/server/haengdong/application/request/MemberActionSaveAppRequest.java +++ b/server/src/main/java/server/haengdong/application/request/MemberActionSaveAppRequest.java @@ -1,12 +1,13 @@ package server.haengdong.application.request; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionStatus; +import server.haengdong.domain.action.Sequence; +import server.haengdong.domain.event.Event; public record MemberActionSaveAppRequest(String name, String status) { - public MemberAction toMemberAction(Action action, Long memberGroupId) { - return new MemberAction(action, name, MemberActionStatus.of(status), memberGroupId); + public MemberAction toMemberAction(Event event, Sequence sequence) { + return new MemberAction(event, sequence, name, MemberActionStatus.of(status)); } } diff --git a/server/src/main/java/server/haengdong/application/response/ActionAppResponse.java b/server/src/main/java/server/haengdong/application/response/ActionAppResponse.java index 0c2c12611..931a5c6ba 100644 --- a/server/src/main/java/server/haengdong/application/response/ActionAppResponse.java +++ b/server/src/main/java/server/haengdong/application/response/ActionAppResponse.java @@ -19,10 +19,10 @@ public ActionAppResponse(Long actionId, String name, Long price, Long sequence, public static ActionAppResponse of(BillAction billAction) { return new ActionAppResponse( - billAction.getAction().getId(), + billAction.getId(), billAction.getTitle(), billAction.getPrice(), - billAction.getSequence(), + billAction.getSequence().getValue(), billAction.isFixed(), ActionAppResponse.ActionType.BILL ); @@ -32,10 +32,10 @@ public static ActionAppResponse of(MemberAction memberAction) { MemberActionStatus status = memberAction.getStatus(); return new ActionAppResponse( - memberAction.getAction().getId(), + memberAction.getId(), memberAction.getMemberName(), null, - memberAction.getSequence(), + memberAction.getSequence().getValue(), false, ActionAppResponse.ActionType.of(status) ); diff --git a/server/src/main/java/server/haengdong/domain/action/Action.java b/server/src/main/java/server/haengdong/domain/action/Action.java deleted file mode 100644 index 11f91fc38..000000000 --- a/server/src/main/java/server/haengdong/domain/action/Action.java +++ /dev/null @@ -1,42 +0,0 @@ -package server.haengdong.domain.action; - -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import server.haengdong.domain.event.Event; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Entity -public class Action { - - private static final long FIRST_SEQUENCE = 1L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - private Event event; - - private Long sequence; - - public Action(Event event, Long sequence) { - this.event = event; - this.sequence = sequence; - } - - public static Action createFirst(Event event) { - return new Action(event, FIRST_SEQUENCE); - } - - public Action next() { - return new Action(event, sequence + 1); - } -} diff --git a/server/src/main/java/server/haengdong/domain/action/ActionRepository.java b/server/src/main/java/server/haengdong/domain/action/ActionRepository.java deleted file mode 100644 index 2fde0ffa6..000000000 --- a/server/src/main/java/server/haengdong/domain/action/ActionRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -package server.haengdong.domain.action; - -import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; -import server.haengdong.domain.event.Event; - -@Repository -public interface ActionRepository extends JpaRepository { - - @Query(""" - SELECT a - FROM Action a - WHERE a.event = :event - ORDER BY a.sequence DESC - LIMIT 1 - """) - Optional findLastByEvent(@Param("event") Event event); - - Optional findByIdAndEvent(Long id, Event event); -} diff --git a/server/src/main/java/server/haengdong/domain/action/BillAction.java b/server/src/main/java/server/haengdong/domain/action/BillAction.java index 943b40ce5..d92d112d7 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillAction.java +++ b/server/src/main/java/server/haengdong/domain/action/BillAction.java @@ -1,14 +1,16 @@ package server.haengdong.domain.action; +import jakarta.persistence.AttributeOverride; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; +import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -36,8 +38,12 @@ public class BillAction implements Comparable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - private Action action; + @ManyToOne(fetch = FetchType.LAZY) + private Event event; + + @AttributeOverride(name = "value", column = @Column(name = "sequence")) + @Embedded + private Sequence sequence; @Column(length = MAX_TITLE_LENGTH) private String title; @@ -47,10 +53,11 @@ public class BillAction implements Comparable { @OneToMany(mappedBy = "billAction", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List billActionDetails = new ArrayList<>(); - public BillAction(Action action, String title, Long price) { + public BillAction(Event event, Sequence sequence, String title, Long price) { validateTitle(title); validatePrice(price); - this.action = action; + this.event = event; + this.sequence = sequence; this.title = title.trim(); this.price = price; } @@ -68,8 +75,10 @@ private void validatePrice(Long price) { } } - public static BillAction create(Action action, String title, Long price, CurrentMembers currentMembers) { - BillAction billAction = new BillAction(action, title, price); + public static BillAction create( + Event event, Sequence sequence, String title, Long price, CurrentMembers currentMembers + ) { + BillAction billAction = new BillAction(event, sequence, title, price); billAction.resetBillActionDetails(currentMembers); return billAction; } @@ -138,19 +147,11 @@ public Long findPriceByMemberName(String memberName) { .filter(billActionDetail -> billActionDetail.hasMemberName(memberName)) .map(BillActionDetail::getPrice) .findFirst() - .orElse(DEFAULT_PRICE); - } - - public Long getSequence() { - return action.getSequence(); - } - - public Event getEvent() { - return action.getEvent(); + .orElseGet(() -> DEFAULT_PRICE); } @Override public int compareTo(BillAction o) { - return Long.compare(this.getSequence(), o.getSequence()); + return sequence.compareTo(o.sequence); } } diff --git a/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java b/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java index 05de55304..47d5d83e5 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java +++ b/server/src/main/java/server/haengdong/domain/action/BillActionDetailRepository.java @@ -16,5 +16,5 @@ public interface BillActionDetailRepository extends JpaRepository findAllByBillAction(BillAction billAction); - List findAllByBillAction_Action_EventAndMemberName(Event event, String memberName); + List findAllByBillAction_EventAndMemberName(Event event, String memberName); } diff --git a/server/src/main/java/server/haengdong/domain/action/BillActionRepository.java b/server/src/main/java/server/haengdong/domain/action/BillActionRepository.java index 817a63bf8..d05451882 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillActionRepository.java +++ b/server/src/main/java/server/haengdong/domain/action/BillActionRepository.java @@ -2,26 +2,30 @@ import java.util.List; import java.util.Optional; -import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import server.haengdong.domain.event.Event; @Repository public interface BillActionRepository extends JpaRepository { - @EntityGraph(attributePaths = {"action"}) - List findByAction_Event(Event event); - - void deleteByAction_EventAndActionId(Event event, Long actionId); - - Optional findByAction_Id(Long actionId); + List findByEvent(Event event); @Query(""" select ba from BillAction ba - where ba.action.event = :event and ba.action.sequence > :sequence + where ba.event = :event and ba.sequence.value > :sequence """) List findByEventAndGreaterThanSequence(Event event, Long sequence); + + @Query(""" + select ba + from BillAction ba + WHERE ba.event = :event + ORDER BY ba.sequence DESC + LIMIT 1 + """) + Optional findLastByEvent(@Param("event") Event event); } diff --git a/server/src/main/java/server/haengdong/domain/action/MemberAction.java b/server/src/main/java/server/haengdong/domain/action/MemberAction.java index 3faf65bde..97824b1f7 100644 --- a/server/src/main/java/server/haengdong/domain/action/MemberAction.java +++ b/server/src/main/java/server/haengdong/domain/action/MemberAction.java @@ -1,6 +1,8 @@ package server.haengdong.domain.action; -import jakarta.persistence.CascadeType; +import jakarta.persistence.AttributeOverride; +import jakarta.persistence.Column; +import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -8,10 +10,11 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; +import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import server.haengdong.domain.event.Event; import server.haengdong.exception.HaengdongErrorCode; import server.haengdong.exception.HaengdongException; @@ -27,22 +30,24 @@ public class MemberAction implements Comparable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) - private Action action; + @ManyToOne(fetch = FetchType.LAZY) + private Event event; + + @AttributeOverride(name = "value", column = @Column(name = "sequence")) + @Embedded + private Sequence sequence; private String memberName; @Enumerated(EnumType.STRING) private MemberActionStatus status; - private Long memberGroupId; - - public MemberAction(Action action, String memberName, MemberActionStatus status, Long memberGroupId) { + public MemberAction(Event event, Sequence sequence, String memberName, MemberActionStatus status) { validateMemberName(memberName); - this.action = action; + this.event = event; + this.sequence = sequence; this.memberName = memberName; this.status = status; - this.memberGroupId = memberGroupId; } private void validateMemberName(String memberName) { @@ -65,12 +70,8 @@ public boolean isSameStatus(MemberActionStatus memberActionStatus) { return status == memberActionStatus; } - public Long getSequence() { - return action.getSequence(); - } - @Override public int compareTo(MemberAction o) { - return Long.compare(this.getSequence(), o.getSequence()); + return sequence.compareTo(o.sequence); } } diff --git a/server/src/main/java/server/haengdong/domain/action/MemberActionRepository.java b/server/src/main/java/server/haengdong/domain/action/MemberActionRepository.java index 324ff9797..9aceed477 100644 --- a/server/src/main/java/server/haengdong/domain/action/MemberActionRepository.java +++ b/server/src/main/java/server/haengdong/domain/action/MemberActionRepository.java @@ -12,42 +12,50 @@ @Repository public interface MemberActionRepository extends JpaRepository { - @Query("select m from MemberAction m join fetch m.action where m.action.event = :event") List findAllByEvent(@Param("event") Event event); @Query(""" - select distinct m.memberName - from MemberAction m - where m.action.event = :event + select distinct ma.memberName + from MemberAction ma + where ma.event = :event """) List findAllUniqueMemberByEvent(Event event); @Modifying @Query(""" delete - from MemberAction m - where m.memberName = :memberName and m.action.event = :event + from MemberAction ma + where ma.memberName = :memberName and ma.event = :event """) void deleteAllByEventAndMemberName(Event event, String memberName); - Optional findByAction(Action action); - @Modifying @Query(""" delete - from MemberAction m - where m.memberName = :memberName and m.action.sequence >= :sequence + from MemberAction ma + where ma.memberName = :memberName and ma.sequence.value >= :sequence """) void deleteAllByMemberNameAndMinSequence(String memberName, Long sequence); - List findAllByAction_EventAndMemberName(Event event, String memberName); + List findAllByEventAndMemberName(Event event, String memberName); - boolean existsByAction_EventAndMemberName(Event event, String updatedMemberName); + boolean existsByEventAndMemberName(Event event, String updatedMemberName); @Query(""" select ma from MemberAction ma - where ma.action.event = :event and ma.action.sequence < :sequence + where ma.event = :event and ma.sequence.value < :sequence """) List findByEventAndSequence(Event event, Long sequence); + + @Query(""" + select ma + from MemberAction ma + WHERE ma.event = :event + ORDER BY ma.sequence.value DESC + LIMIT 1 + """) + Optional findLastByEvent(@Param("event") Event event); + + MemberAction findByIdAndEvent(Long actionId, Event event); } diff --git a/server/src/main/java/server/haengdong/domain/action/MemberBillReport.java b/server/src/main/java/server/haengdong/domain/action/MemberBillReport.java index 7a707b9d8..5fcb6ebd3 100644 --- a/server/src/main/java/server/haengdong/domain/action/MemberBillReport.java +++ b/server/src/main/java/server/haengdong/domain/action/MemberBillReport.java @@ -53,7 +53,7 @@ private static boolean isMemberActionTurn( MemberAction memberAction = memberActions.peek(); BillAction billAction = billActions.peek(); - return memberAction.getSequence() < billAction.getSequence(); + return memberAction.getSequence().getValue() < billAction.getSequence().getValue(); } private static void addBillAction( diff --git a/server/src/main/java/server/haengdong/domain/action/Sequence.java b/server/src/main/java/server/haengdong/domain/action/Sequence.java new file mode 100644 index 000000000..39a99d063 --- /dev/null +++ b/server/src/main/java/server/haengdong/domain/action/Sequence.java @@ -0,0 +1,41 @@ +package server.haengdong.domain.action; + +import jakarta.persistence.Embeddable; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@EqualsAndHashCode +@Getter +@NoArgsConstructor +@Embeddable +public class Sequence implements Comparable { + + private static final long FIRST_SEQUENCE = 1L; + + private Long value; + + public Sequence(Long value) { + this.value = value; + } + + public static Sequence createFirst() { + return new Sequence(FIRST_SEQUENCE); + } + + public static Sequence getGreater(Sequence first, Sequence second) { + if (first.compareTo(second) > 0) { + return first; + } + return second; + } + + public Sequence next() { + return new Sequence(value + 1); + } + + @Override + public int compareTo(Sequence o) { + return Long.compare(value, o.value); + } +} diff --git a/server/src/main/java/server/haengdong/presentation/EventController.java b/server/src/main/java/server/haengdong/presentation/EventController.java index 57d0515e7..af725864d 100644 --- a/server/src/main/java/server/haengdong/presentation/EventController.java +++ b/server/src/main/java/server/haengdong/presentation/EventController.java @@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import server.haengdong.application.ActionService; import server.haengdong.application.AuthService; import server.haengdong.application.EventService; import server.haengdong.application.response.ActionAppResponse; @@ -37,7 +36,6 @@ public class EventController { private final EventService eventService; private final AuthService authService; private final CookieProperties cookieProperties; - private final ActionService actionService; @GetMapping("/api/events/{eventId}") public ResponseEntity findEvent(@PathVariable("eventId") String token) { @@ -70,7 +68,7 @@ public ResponseEntity findAllMembers(@PathVariable("eventId") S @GetMapping("/api/events/{eventId}/reports") public ResponseEntity getMemberBillReports(@PathVariable("eventId") String token) { - List memberBillReports = actionService.getMemberBillReports(token); + List memberBillReports = eventService.getMemberBillReports(token); return ResponseEntity.ok() .body(MemberBillReportsResponse.of(memberBillReports)); diff --git a/server/src/test/java/server/haengdong/application/ActionServiceTest.java b/server/src/test/java/server/haengdong/application/ActionServiceTest.java deleted file mode 100644 index ee979b278..000000000 --- a/server/src/test/java/server/haengdong/application/ActionServiceTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package server.haengdong.application; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.Assertions.tuple; -import static server.haengdong.domain.action.MemberActionStatus.IN; -import static server.haengdong.domain.action.MemberActionStatus.OUT; -import static server.haengdong.support.fixture.Fixture.BILL_ACTION; - -import java.util.List; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import server.haengdong.application.response.MemberBillReportAppResponse; -import server.haengdong.domain.action.Action; -import server.haengdong.domain.action.BillAction; -import server.haengdong.domain.action.BillActionDetail; -import server.haengdong.domain.action.BillActionRepository; -import server.haengdong.domain.action.MemberAction; -import server.haengdong.domain.action.MemberActionRepository; -import server.haengdong.domain.event.Event; -import server.haengdong.domain.event.EventRepository; -import server.haengdong.exception.HaengdongErrorCode; -import server.haengdong.exception.HaengdongException; -import server.haengdong.support.fixture.Fixture; - -class ActionServiceTest extends ServiceTestSupport { - - @Autowired - private ActionService actionService; - - @Autowired - private EventRepository eventRepository; - - @Autowired - private BillActionRepository billActionRepository; - - @Autowired - private MemberActionRepository memberActionRepository; - - @DisplayName("참여자별 정산 현황을 조회한다.") - @Test - void getMemberBillReports() { - Event event = Fixture.EVENT1; - Event savedEvent = eventRepository.save(event); - List memberActions = List.of( - new MemberAction(new Action(savedEvent, 1L), "소하", IN, 1L), - new MemberAction(new Action(savedEvent, 2L), "감자", IN, 1L), - new MemberAction(new Action(savedEvent, 3L), "쿠키", IN, 1L), - new MemberAction(new Action(savedEvent, 5L), "감자", OUT, 2L) - ); - List billActions = List.of( - new BillAction(new Action(savedEvent, 4L), "뽕족", 60_000L), - new BillAction(new Action(savedEvent, 7L), "인생네컷", 20_000L) - ); - billActions.get(0).addDetails( - List.of( - new BillActionDetail(BILL_ACTION, "소하", 10_000L, false), - new BillActionDetail(BILL_ACTION, "감자", 40_000L, true), - new BillActionDetail(BILL_ACTION, "쿠키", 10_000L, false) - ) - ); - billActions.get(1).addDetails( - List.of( - new BillActionDetail(BILL_ACTION, "소하", 5_000L, true), - new BillActionDetail(BILL_ACTION, "쿠키", 15_000L, true) - ) - ); - memberActionRepository.saveAll(memberActions); - billActionRepository.saveAll(billActions); - - List responses = actionService.getMemberBillReports(event.getToken()); - - assertThat(responses) - .hasSize(3) - .extracting(MemberBillReportAppResponse::name, MemberBillReportAppResponse::price) - .containsExactlyInAnyOrder( - tuple("감자", 40_000L), - tuple("쿠키", 25_000L), - tuple("소하", 15_000L) - ); - } - - @DisplayName("존재하지 않는 이벤트의 참여자별 정산 현황을 조회하는 경우 예외가 발생한다.") - @Test - void getMemberBillReports1() { - assertThatThrownBy(() -> actionService.getMemberBillReports("invalid token")) - .isInstanceOf(HaengdongException.class) - .hasMessage(HaengdongErrorCode.EVENT_NOT_FOUND.getMessage()); - } -} diff --git a/server/src/test/java/server/haengdong/application/BillActionDetailServiceTest.java b/server/src/test/java/server/haengdong/application/BillActionDetailServiceTest.java index 7074ce846..c89d057eb 100644 --- a/server/src/test/java/server/haengdong/application/BillActionDetailServiceTest.java +++ b/server/src/test/java/server/haengdong/application/BillActionDetailServiceTest.java @@ -12,11 +12,11 @@ import server.haengdong.application.request.BillActionDetailsUpdateAppRequest; import server.haengdong.application.response.BillActionDetailAppResponse; import server.haengdong.application.response.BillActionDetailsAppResponse; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.BillAction; import server.haengdong.domain.action.BillActionDetail; import server.haengdong.domain.action.BillActionDetailRepository; import server.haengdong.domain.action.BillActionRepository; +import server.haengdong.domain.action.Sequence; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.exception.HaengdongException; @@ -41,15 +41,15 @@ class BillActionDetailServiceTest extends ServiceTestSupport { void findBillActionDetailsTest() { Event event1 = Fixture.EVENT1; eventRepository.save(event1); - Action action = new Action(event1, 1L); - BillAction billAction = new BillAction(action, "뽕족", 10000L); + Sequence sequence = Sequence.createFirst(); + BillAction billAction = new BillAction(event1, sequence, "뽕족", 10000L); billActionRepository.save(billAction); BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "토다리", 6000L, true); BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "쿠키", 4000L, true); billActionDetailRepository.saveAll(List.of(billActionDetail1, billActionDetail2)); BillActionDetailsAppResponse response = billActionDetailService.findBillActionDetails( - event1.getToken(), action.getId()); + event1.getToken(), billAction.getId()); assertThat(response.billActionDetailAppResponses()).hasSize(2) .extracting(BillActionDetailAppResponse::name, BillActionDetailAppResponse::price) @@ -64,8 +64,8 @@ void findBillActionDetailsTest() { void updateBillActionDetailsTest1() { Event event1 = Fixture.EVENT1; eventRepository.save(event1); - Action action = new Action(event1, 1L); - BillAction billAction = new BillAction(action, "뽕족", 10000L); + Sequence sequence = Sequence.createFirst(); + BillAction billAction = new BillAction(event1, sequence, "뽕족", 10000L); billActionRepository.save(billAction); BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "토다리", 5000L, false); BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "쿠키", 5000L, false); @@ -76,7 +76,7 @@ void updateBillActionDetailsTest1() { new BillActionDetailUpdateAppRequest("쿠키", 4000L, true) )); assertThatCode( - () -> billActionDetailService.updateBillActionDetails(event1.getToken(), action.getId(), request)) + () -> billActionDetailService.updateBillActionDetails(event1.getToken(), billAction.getId(), request)) .isInstanceOf(HaengdongException.class) .hasMessage("지출 총액이 일치하지 않습니다."); } @@ -86,8 +86,8 @@ void updateBillActionDetailsTest1() { void updateBillActionDetailsTest2() { Event event1 = Fixture.EVENT1; eventRepository.save(event1); - Action action = new Action(event1, 1L); - BillAction billAction = new BillAction(action, "뽕족", 10000L); + Sequence sequence = Sequence.createFirst(); + BillAction billAction = new BillAction(event1, sequence, "뽕족", 10000L); billActionRepository.save(billAction); BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "토다리", 5000L, false); BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "쿠키", 5000L, false); @@ -97,7 +97,7 @@ void updateBillActionDetailsTest2() { new BillActionDetailUpdateAppRequest("토다리", 3000L, true), new BillActionDetailUpdateAppRequest("쿠키", 7000L, true) )); - billActionDetailService.updateBillActionDetails(event1.getToken(), action.getId(), request); + billActionDetailService.updateBillActionDetails(event1.getToken(), billAction.getId(), request); List results = billActionDetailRepository.findAll(); diff --git a/server/src/test/java/server/haengdong/application/BillActionServiceTest.java b/server/src/test/java/server/haengdong/application/BillActionServiceTest.java index 39e52f80c..30675acdd 100644 --- a/server/src/test/java/server/haengdong/application/BillActionServiceTest.java +++ b/server/src/test/java/server/haengdong/application/BillActionServiceTest.java @@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; import server.haengdong.application.request.BillActionAppRequest; import server.haengdong.application.request.BillActionUpdateAppRequest; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.BillAction; import server.haengdong.domain.action.BillActionDetail; import server.haengdong.domain.action.BillActionDetailRepository; @@ -19,6 +18,7 @@ import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionRepository; import server.haengdong.domain.action.MemberActionStatus; +import server.haengdong.domain.action.Sequence; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.exception.HaengdongException; @@ -46,10 +46,10 @@ class BillActionServiceTest extends ServiceTestSupport { void saveAllBillAction() { Event event = Fixture.EVENT1; Event savedEvent = eventRepository.save(event); - Action action1 = new Action(event, 1L); - Action action2 = new Action(event, 2L); - MemberAction memberAction1 = new MemberAction(action1, "백호", MemberActionStatus.IN, 1L); - MemberAction memberAction2 = new MemberAction(action2, "망쵸", MemberActionStatus.IN, 2L); + Sequence sequence1 = Sequence.createFirst(); + Sequence sequence2 = sequence1.next(); + MemberAction memberAction1 = new MemberAction(event, sequence1, "백호", MemberActionStatus.IN); + MemberAction memberAction2 = new MemberAction(event, sequence2, "망쵸", MemberActionStatus.IN); memberActionRepository.saveAll(List.of(memberAction1, memberAction2)); List requests = List.of( @@ -59,12 +59,12 @@ void saveAllBillAction() { billActionService.saveAllBillAction(event.getToken(), requests); - List actions = billActionRepository.findByAction_Event(savedEvent); + List actions = billActionRepository.findByEvent(savedEvent); assertThat(actions).extracting(BillAction::getTitle, BillAction::getPrice, BillAction::getSequence) .containsExactlyInAnyOrder( - tuple("뽕족", 10_000L, 3L), - tuple("인생맥주", 15_000L, 4L) + tuple("뽕족", 10_000L, new Sequence(3L)), + tuple("인생맥주", 15_000L, new Sequence(4L)) ); } @@ -73,10 +73,10 @@ void saveAllBillAction() { void saveAllBillActionTest1() { Event event = Fixture.EVENT1; Event savedEvent = eventRepository.save(event); - Action action1 = new Action(event, 1L); - Action action2 = new Action(event, 2L); - MemberAction memberAction1 = new MemberAction(action1, "백호", MemberActionStatus.IN, 1L); - MemberAction memberAction2 = new MemberAction(action2, "망쵸", MemberActionStatus.IN, 2L); + Sequence sequence1 = Sequence.createFirst(); + Sequence sequence2 = sequence1.next(); + MemberAction memberAction1 = new MemberAction(event, sequence1, "백호", MemberActionStatus.IN); + MemberAction memberAction2 = new MemberAction(event, sequence2, "망쵸", MemberActionStatus.IN); memberActionRepository.saveAll(List.of(memberAction1, memberAction2)); List request = List.of( @@ -116,11 +116,11 @@ void saveAllBillAction1() { void updateBillAction() { Event event = Fixture.EVENT1; Event savedEvent = eventRepository.save(event); - Action action = Action.createFirst(savedEvent); - BillAction billAction = new BillAction(action, "뽕족", 10_000L); + Sequence sequence = Sequence.createFirst(); + BillAction billAction = new BillAction(event, sequence, "뽕족", 10_000L); BillAction savedBillAction = billActionRepository.save(billAction); - Long actionId = savedBillAction.getAction().getId(); + Long actionId = savedBillAction.getId(); BillActionUpdateAppRequest request = new BillActionUpdateAppRequest("인생맥주", 20_000L); billActionService.updateBillAction(event.getToken(), actionId, request); @@ -140,14 +140,14 @@ void updateBillAction1() { Event event2 = Fixture.EVENT2; Event savedEvent1 = eventRepository.save(event1); Event savedEvent2 = eventRepository.save(event2); - Action action1 = Action.createFirst(savedEvent1); - Action action2 = Action.createFirst(savedEvent2); - BillAction billAction1 = new BillAction(action1, "뽕족", 10_000L); - BillAction billAction2 = new BillAction(action2, "뽕족", 10_000L); + Sequence sequence1 = Sequence.createFirst(); + Sequence sequence2 = Sequence.createFirst(); + BillAction billAction1 = new BillAction(event1, sequence1, "뽕족", 10_000L); + BillAction billAction2 = new BillAction(event2, sequence2, "뽕족", 10_000L); BillAction savedBillAction1 = billActionRepository.save(billAction1); billActionRepository.save(billAction2); - Long actionId = savedBillAction1.getAction().getId(); + Long actionId = savedBillAction1.getId(); BillActionUpdateAppRequest request = new BillActionUpdateAppRequest("인생맥주", 20_000L); assertThatThrownBy(() -> billActionService.updateBillAction(event2.getToken(), actionId, request)) @@ -159,8 +159,8 @@ void updateBillAction1() { void updateBillAction2() { Event event = Fixture.EVENT1; Event savedEvent = eventRepository.save(event); - Action action = Action.createFirst(savedEvent); - BillAction billAction = new BillAction(action, "뽕족", 10_000L); + Sequence sequence = Sequence.createFirst(); + BillAction billAction = new BillAction(event, sequence, "뽕족", 10_000L); BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "감자", 3000L, true); BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "고구마", 2000L, true); BillActionDetail billActionDetail3 = new BillActionDetail(billAction, "당근", 3000L, true); @@ -168,7 +168,7 @@ void updateBillAction2() { billAction.addDetails(List.of(billActionDetail1, billActionDetail2, billActionDetail3, billActionDetail4)); BillAction savedBillAction = billActionRepository.save(billAction); - Long actionId = savedBillAction.getAction().getId(); + Long actionId = savedBillAction.getId(); BillActionUpdateAppRequest request = new BillActionUpdateAppRequest("인생맥주", 20_000L); billActionService.updateBillAction(event.getToken(), actionId, request); @@ -191,9 +191,9 @@ void updateBillAction2() { void deleteBillAction() { Event event = Fixture.EVENT1; eventRepository.save(event); - BillAction billAction = new BillAction(new Action(event, 1L), "커피", 50_900L); + BillAction billAction = Fixture.createBillAction(event, 1L, "커피", 50_900L); billActionRepository.save(billAction); - Long actionId = billAction.getAction().getId(); + Long actionId = billAction.getId(); billActionService.deleteBillAction(event.getToken(), actionId); @@ -205,15 +205,15 @@ void deleteBillAction() { void deleteBillActionTest1() { Event event = Fixture.EVENT1; eventRepository.save(event); - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "백호", MemberActionStatus.IN, 1L); - MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "망쵸", MemberActionStatus.IN, 2L); - BillAction billAction = new BillAction(new Action(event, 3L), "커피", 50_900L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "백호", MemberActionStatus.IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "망쵸", MemberActionStatus.IN); + BillAction billAction = Fixture.createBillAction(event, 3L, "커피", 50_900L); BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "백호", 25_450L, false); BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "망쵸", 25_450L, false); memberActionRepository.saveAll(List.of(memberAction1, memberAction2)); billActionRepository.save(billAction); billActionDetailRepository.saveAll(List.of(billActionDetail1, billActionDetail2)); - Long actionId = billAction.getAction().getId(); + Long actionId = billAction.getId(); billActionService.deleteBillAction(event.getToken(), actionId); diff --git a/server/src/test/java/server/haengdong/application/EventServiceTest.java b/server/src/test/java/server/haengdong/application/EventServiceTest.java index 407fa1457..37e6372a8 100644 --- a/server/src/test/java/server/haengdong/application/EventServiceTest.java +++ b/server/src/test/java/server/haengdong/application/EventServiceTest.java @@ -7,6 +7,7 @@ import static org.mockito.BDDMockito.given; import static server.haengdong.domain.action.MemberActionStatus.IN; import static server.haengdong.domain.action.MemberActionStatus.OUT; +import static server.haengdong.support.fixture.Fixture.BILL_ACTION; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -19,15 +20,18 @@ import server.haengdong.application.response.ActionAppResponse; import server.haengdong.application.response.EventAppResponse; import server.haengdong.application.response.EventDetailAppResponse; +import server.haengdong.application.response.MemberBillReportAppResponse; import server.haengdong.application.response.MembersAppResponse; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.BillAction; +import server.haengdong.domain.action.BillActionDetail; import server.haengdong.domain.action.BillActionRepository; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionRepository; +import server.haengdong.domain.action.Sequence; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.domain.event.EventTokenProvider; +import server.haengdong.exception.HaengdongErrorCode; import server.haengdong.exception.HaengdongException; import server.haengdong.support.fixture.Fixture; @@ -74,12 +78,9 @@ void findEventTest() { @Test void findActionsTest() { Event event = Fixture.EVENT1; - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "토다리", IN, 1L); - Action action1 = new Action(event, 2L); - MemberAction memberAction1 = new MemberAction(action1, "쿠키", IN, 1L); - Action action2 = new Action(event, 3L); - BillAction billAction = new BillAction(action2, "뽕나무쟁이족발", 30000L); + MemberAction memberAction = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction1 = Fixture.createMemberAction(event, 2L, "쿠키", IN); + BillAction billAction = Fixture.createBillAction(event, 3L, "뽕나무쟁이족발", 30000L); eventRepository.save(event); memberActionRepository.saveAll(List.of(memberAction, memberAction1)); billActionRepository.save(billAction); @@ -88,14 +89,14 @@ void findActionsTest() { assertThat(actionAppResponses).hasSize(3) .extracting(ActionAppResponse::actionId, - ActionAppResponse::name, - ActionAppResponse::price, - ActionAppResponse::sequence, - ActionAppResponse::actionTypeName) + ActionAppResponse::name, + ActionAppResponse::price, + ActionAppResponse::sequence, + ActionAppResponse::actionTypeName) .containsExactly( tuple(1L, "토다리", null, 1L, "IN"), tuple(2L, "쿠키", null, 2L, "IN"), - tuple(3L, "뽕나무쟁이족발", 30000L, 3L, "BILL") + tuple(1L, "뽕나무쟁이족발", 30000L, 3L, "BILL") ); } @@ -103,14 +104,10 @@ void findActionsTest() { @Test void findAllMembersTest() { Event event = Fixture.EVENT1; - Action action1 = new Action(event, 1L); - Action action2 = new Action(event, 2L); - Action action3 = new Action(event, 3L); - Action action4 = new Action(event, 4L); - BillAction billAction = new BillAction(action3, "뽕나무쟁이족발", 30000L); - MemberAction memberAction1 = new MemberAction(action1, "토다리", IN, 1L); - MemberAction memberAction2 = new MemberAction(action2, "쿠키", IN, 1L); - MemberAction memberAction3 = new MemberAction(action4, "쿠키", OUT, 1L); + BillAction billAction = Fixture.createBillAction(event, 3L, "뽕나무쟁이족발", 30000L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "쿠키", IN); + MemberAction memberAction3 = Fixture.createMemberAction(event, 4L, "쿠키", OUT); eventRepository.save(event); billActionRepository.save(billAction); memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); @@ -124,12 +121,12 @@ void findAllMembersTest() { @Test void updateMember() { Event event = Fixture.EVENT1; - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); - MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); - MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); - MemberAction memberAction4 = new MemberAction(new Action(event, 4L), "쿠키", OUT, 3L); - MemberAction memberAction5 = new MemberAction(new Action(event, 5L), "쿠키", IN, 4L); - MemberAction memberAction6 = new MemberAction(new Action(event, 6L), "쿠키", OUT, 5L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "쿠키", IN); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "웨디", IN); + MemberAction memberAction4 = Fixture.createMemberAction(event, 4L, "쿠키", OUT); + MemberAction memberAction5 = Fixture.createMemberAction(event, 5L, "쿠키", IN); + MemberAction memberAction6 = Fixture.createMemberAction(event, 6L, "쿠키", OUT); eventRepository.save(event); memberActionRepository.saveAll(List.of( memberAction1, memberAction2, memberAction3, memberAction4, memberAction5, memberAction6 @@ -157,9 +154,9 @@ void updateMember() { @Test void updateMember1() { Event event = Fixture.EVENT1; - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); - MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); - MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "쿠키", IN); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "웨디", IN); eventRepository.save(event); memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); @@ -176,9 +173,9 @@ void updateMember1() { @Test void updateMember2() { Event event = Fixture.EVENT1; - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); - MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); - MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "쿠키", IN); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "웨디", IN); eventRepository.save(event); memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); @@ -195,9 +192,9 @@ void updateMember2() { @Test void updateMember3() { Event event = Fixture.EVENT1; - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); - MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); - MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "쿠키", IN); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "웨디", IN); eventRepository.save(event); memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); @@ -214,9 +211,9 @@ void updateMember3() { @Test void updateMember4() { Event event = Fixture.EVENT1; - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); - MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); - MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "쿠키", IN); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "웨디", IN); eventRepository.save(event); memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); @@ -228,4 +225,55 @@ void updateMember4() { assertThatThrownBy(() -> eventService.updateMember(event.getToken(), appRequest)) .isInstanceOf(HaengdongException.class); } + + @DisplayName("참여자별 정산 현황을 조회한다.") + @Test + void getMemberBillReports() { + Event event = Fixture.EVENT1; + Event savedEvent = eventRepository.save(event); + List memberActions = List.of( + new MemberAction(savedEvent, new Sequence(1L), "소하", IN), + new MemberAction(savedEvent, new Sequence(2L), "감자", IN), + new MemberAction(savedEvent, new Sequence(3L), "쿠키", IN), + new MemberAction(savedEvent, new Sequence(5L), "감자", OUT) + ); + List billActions = List.of( + new BillAction(savedEvent, new Sequence(4L), "뽕족", 60_000L), + new BillAction(savedEvent, new Sequence(7L), "인생네컷", 20_000L) + ); + billActions.get(0).addDetails( + List.of( + new BillActionDetail(BILL_ACTION, "소하", 10_000L, false), + new BillActionDetail(BILL_ACTION, "감자", 40_000L, true), + new BillActionDetail(BILL_ACTION, "쿠키", 10_000L, false) + ) + ); + billActions.get(1).addDetails( + List.of( + new BillActionDetail(BILL_ACTION, "소하", 5_000L, true), + new BillActionDetail(BILL_ACTION, "쿠키", 15_000L, true) + ) + ); + memberActionRepository.saveAll(memberActions); + billActionRepository.saveAll(billActions); + + List responses = eventService.getMemberBillReports(event.getToken()); + + assertThat(responses) + .hasSize(3) + .extracting(MemberBillReportAppResponse::name, MemberBillReportAppResponse::price) + .containsExactlyInAnyOrder( + tuple("감자", 40_000L), + tuple("쿠키", 25_000L), + tuple("소하", 15_000L) + ); + } + + @DisplayName("존재하지 않는 이벤트의 참여자별 정산 현황을 조회하는 경우 예외가 발생한다.") + @Test + void getMemberBillReports1() { + assertThatThrownBy(() -> eventService.getMemberBillReports("invalid token")) + .isInstanceOf(HaengdongException.class) + .hasMessage(HaengdongErrorCode.EVENT_NOT_FOUND.getMessage()); + } } diff --git a/server/src/test/java/server/haengdong/application/MemberActionFactoryTest.java b/server/src/test/java/server/haengdong/application/MemberActionFactoryTest.java index c04f06026..4f1156714 100644 --- a/server/src/test/java/server/haengdong/application/MemberActionFactoryTest.java +++ b/server/src/test/java/server/haengdong/application/MemberActionFactoryTest.java @@ -11,11 +11,11 @@ import org.springframework.beans.factory.annotation.Autowired; import server.haengdong.application.request.MemberActionSaveAppRequest; import server.haengdong.application.request.MemberActionsSaveAppRequest; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.CurrentMembers; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionRepository; import server.haengdong.domain.action.MemberActionStatus; +import server.haengdong.domain.action.Sequence; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.exception.HaengdongException; @@ -36,10 +36,8 @@ class MemberActionFactoryTest extends ServiceTestSupport { @Test void createMemberActionsTest() { Event event = eventRepository.save(Fixture.EVENT1); - Action action1 = new Action(event, 1L); - Action action2 = new Action(event, 2L); - MemberAction memberAction1 = new MemberAction(action1, "토다리", MemberActionStatus.IN, 1L); - MemberAction memberAction2 = new MemberAction(action2, "토다리", MemberActionStatus.OUT, 2L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", MemberActionStatus.IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "토다리", MemberActionStatus.OUT); memberActionRepository.saveAll(List.of(memberAction1, memberAction2)); MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( @@ -47,9 +45,9 @@ void createMemberActionsTest() { List unorderedMemberActions = List.of(memberAction2, memberAction1); CurrentMembers currentMembers = CurrentMembers.of(unorderedMemberActions); - Action startAction = new Action(event, 3L); + Sequence sequence = new Sequence(3L); - assertThatThrownBy(() -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + assertThatThrownBy(() -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence)) .isInstanceOf(HaengdongException.class); } @@ -57,23 +55,23 @@ void createMemberActionsTest() { @Test void createMemberActionsTest1() { Event event = eventRepository.save(Fixture.EVENT1); - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "토다리", MemberActionStatus.IN, 1L); + MemberAction memberAction = Fixture.createMemberAction(event, 1L, "토다리", MemberActionStatus.IN); memberActionRepository.save(memberAction); MemberActionsSaveAppRequest memberActionsSaveAppRequest = new MemberActionsSaveAppRequest( List.of(new MemberActionSaveAppRequest("토다리", "OUT"))); - Action startAction = new Action(event, 2L); + Sequence sequence = new Sequence(2L); CurrentMembers currentMembers = CurrentMembers.of(List.of(memberAction)); - List memberActions = memberActionFactory.createMemberActions(memberActionsSaveAppRequest, - currentMembers, startAction + List memberActions = memberActionFactory.createMemberActions(event, memberActionsSaveAppRequest, + currentMembers, sequence ); assertThat(memberActions).hasSize(1) - .extracting(MemberAction::getAction, MemberAction::getMemberName, MemberAction::getStatus) + .extracting(MemberAction::getEvent, MemberAction::getSequence, MemberAction::getMemberName, + MemberAction::getStatus) .containsExactly( - tuple(startAction, "토다리", MemberActionStatus.OUT) + tuple(event, sequence, "토다리", MemberActionStatus.OUT) ); } @@ -81,16 +79,15 @@ void createMemberActionsTest1() { @Test void createMemberActionsTest2() { Event event = eventRepository.save(Fixture.EVENT1); - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "토다리", MemberActionStatus.IN, 1L); + MemberAction memberAction = Fixture.createMemberAction(event, 1L, "토다리", MemberActionStatus.IN); memberActionRepository.save(memberAction); MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( List.of(new MemberActionSaveAppRequest("토다리", "OUT"))); - Action startAction = new Action(event, 2L); + Sequence sequence = new Sequence(2L); CurrentMembers currentMembers = CurrentMembers.of(List.of(memberAction)); - assertThatCode(() -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + assertThatCode(() -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence)) .doesNotThrowAnyException(); } @@ -98,19 +95,17 @@ void createMemberActionsTest2() { @Test void createMemberActionsTest3() { Event event = eventRepository.save(Fixture.EVENT1); - Action action1 = new Action(event, 1L); - MemberAction memberAction1 = new MemberAction(action1, "토다리", MemberActionStatus.IN, 1L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", MemberActionStatus.IN); memberActionRepository.save(memberAction1); - Action action2 = new Action(event, 2L); - MemberAction memberAction2 = new MemberAction(action2, "토다리", MemberActionStatus.OUT, 2L); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "토다리", MemberActionStatus.OUT); memberActionRepository.save(memberAction2); MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( List.of(new MemberActionSaveAppRequest("토다리", "IN"))); - Action startAction = new Action(event, 3L); + Sequence sequence = new Sequence(3L); CurrentMembers currentMembers = CurrentMembers.of(List.of(memberAction1, memberAction2)); - assertThatCode(() -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + assertThatCode(() -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence)) .doesNotThrowAnyException(); } @@ -118,16 +113,15 @@ void createMemberActionsTest3() { @Test void createMemberActionsTest4() { Event event = eventRepository.save(Fixture.EVENT1); - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "토다리", MemberActionStatus.IN, 1L); + MemberAction memberAction = Fixture.createMemberAction(event, 1L, "토다리", MemberActionStatus.IN); memberActionRepository.save(memberAction); MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( List.of(new MemberActionSaveAppRequest("쿠키", "IN"))); - Action startAction = new Action(event, 2L); + Sequence sequence = new Sequence(2L); CurrentMembers currentMembers = CurrentMembers.of(List.of(memberAction)); - assertThatCode(() -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + assertThatCode(() -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence)) .doesNotThrowAnyException(); } @@ -138,11 +132,11 @@ void createMemberActionTest5() { MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( List.of(new MemberActionSaveAppRequest("쿠키", "OUT"))); - Action startAction = new Action(event, 2L); + Sequence sequence = new Sequence(2L); CurrentMembers currentMembers = CurrentMembers.of(List.of()); assertThatCode( - () -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + () -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence)) .isInstanceOf(HaengdongException.class); } @@ -150,16 +144,15 @@ void createMemberActionTest5() { @Test void createMemberActionTest6() { Event event = eventRepository.save(Fixture.EVENT1); - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "쿠키", MemberActionStatus.IN, 1L); + MemberAction memberAction = Fixture.createMemberAction(event, 1L, "쿠키", MemberActionStatus.IN); memberActionRepository.save(memberAction); MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( List.of(new MemberActionSaveAppRequest("쿠키", "IN"))); - Action startAction = new Action(event, 2L); + Sequence sequence = new Sequence(2L); CurrentMembers currentMembers = CurrentMembers.of(List.of(memberAction)); - assertThatCode(() -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + assertThatCode(() -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence)) .isInstanceOf(HaengdongException.class); } @@ -173,11 +166,11 @@ void createMemberActionTest7() { new MemberActionSaveAppRequest("쿠키", "IN"), new MemberActionSaveAppRequest("쿠키", "IN") )); - Action startAction = new Action(event, 1L); + Sequence sequence = new Sequence(1L); CurrentMembers currentMembers = CurrentMembers.of(List.of()); assertThatCode( - () -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + () -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence)) .isInstanceOf(HaengdongException.class); } @@ -185,8 +178,8 @@ void createMemberActionTest7() { @Test void createMemberActionTest8() { Event event = eventRepository.save(Fixture.EVENT1); - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "쿠키", MemberActionStatus.IN, 1L); + Sequence sequence1 = new Sequence(1L); + MemberAction memberAction = new MemberAction(event, sequence1, "쿠키", MemberActionStatus.IN); memberActionRepository.save(memberAction); MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( @@ -194,10 +187,10 @@ void createMemberActionTest8() { new MemberActionSaveAppRequest("쿠키", "OUT"), new MemberActionSaveAppRequest("쿠키", "OUT") )); - Action startAction = new Action(event, 2L); + Sequence sequence2 = new Sequence(2L); CurrentMembers currentMembers = CurrentMembers.of(List.of(memberAction)); - assertThatCode(() -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + assertThatCode(() -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence2)) .isInstanceOf(HaengdongException.class); } @@ -205,8 +198,8 @@ void createMemberActionTest8() { @Test void createMemberActionTest9() { Event event = eventRepository.save(Fixture.EVENT1); - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "쿠키", MemberActionStatus.IN, 1L); + Sequence sequence = new Sequence(1L); + MemberAction memberAction = new MemberAction(event, sequence, "쿠키", MemberActionStatus.IN); memberActionRepository.save(memberAction); MemberActionsSaveAppRequest request = new MemberActionsSaveAppRequest( @@ -214,10 +207,10 @@ void createMemberActionTest9() { new MemberActionSaveAppRequest("쿠키", "IN"), new MemberActionSaveAppRequest("쿠키", "OUT") )); - Action startAction = new Action(event, 2L); + Sequence sequence2 = new Sequence(2L); CurrentMembers currentMembers = CurrentMembers.of(List.of(memberAction)); - assertThatCode(() -> memberActionFactory.createMemberActions(request, currentMembers, startAction)) + assertThatCode(() -> memberActionFactory.createMemberActions(event, request, currentMembers, sequence2)) .isInstanceOf(HaengdongException.class); } } diff --git a/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java b/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java index b6d29444c..51f5428f0 100644 --- a/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java +++ b/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java @@ -13,14 +13,12 @@ import org.springframework.beans.factory.annotation.Autowired; import server.haengdong.application.request.MemberActionSaveAppRequest; import server.haengdong.application.request.MemberActionsSaveAppRequest; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.BillAction; import server.haengdong.domain.action.BillActionDetail; import server.haengdong.domain.action.BillActionDetailRepository; import server.haengdong.domain.action.BillActionRepository; import server.haengdong.domain.action.MemberAction; import server.haengdong.domain.action.MemberActionRepository; -import server.haengdong.domain.action.MemberActionStatus; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; import server.haengdong.exception.HaengdongException; @@ -47,8 +45,7 @@ class MemberActionServiceTest extends ServiceTestSupport { @Test void saveMemberActionTest() { Event event = eventRepository.save(Fixture.EVENT1); - Action action = new Action(event, 1L); - MemberAction memberAction = new MemberAction(action, "망쵸", IN, 1L); + MemberAction memberAction = Fixture.createMemberAction(event, 1L, "망쵸", IN); memberActionRepository.save(memberAction); assertThatCode(() -> memberActionService.saveMemberAction(event.getToken(), new MemberActionsSaveAppRequest( @@ -60,12 +57,10 @@ void saveMemberActionTest() { @Test void saveMemberActionTest1() { Event event = eventRepository.save(Fixture.EVENT1); - Action actionOne = new Action(event, 1L); - MemberAction memberActionOne = new MemberAction(actionOne, "망쵸", IN, 1L); + MemberAction memberActionOne = Fixture.createMemberAction(event, 1L, "망쵸", IN); memberActionRepository.save(memberActionOne); - Action actionTwo = new Action(event, 2L); - MemberAction memberActionTwo = new MemberAction(actionTwo, "망쵸", OUT, 1L); + MemberAction memberActionTwo = Fixture.createMemberAction(event, 2L, "망쵸", OUT); memberActionRepository.save(memberActionTwo); assertThatCode(() -> memberActionService.saveMemberAction(event.getToken(), new MemberActionsSaveAppRequest( @@ -95,19 +90,18 @@ void getCurrentMembers() { void deleteMember() { Event event = Fixture.EVENT1; eventRepository.save(event); - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "참여자", IN, 1L); - MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "토다리", IN, 1L); - MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "쿠키", IN, 1L); - MemberAction memberAction4 = new MemberAction(new Action(event, 4L), "소하", IN, 1L); - MemberAction memberAction5 = new MemberAction(new Action(event, 5L), "웨디", IN, 1L); - MemberAction memberAction6 = new MemberAction(new Action(event, 6L), "참여자", OUT, 1L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "참여자", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "토다리", IN); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "쿠키", IN); + MemberAction memberAction4 = Fixture.createMemberAction(event, 4L, "소하", IN); + MemberAction memberAction5 = Fixture.createMemberAction(event, 5L, "웨디", IN); + MemberAction memberAction6 = Fixture.createMemberAction(event, 6L, "참여자", OUT); memberActionRepository.saveAll( List.of(memberAction1, memberAction2, memberAction3, memberAction4, memberAction5, memberAction6)); Event event2 = Fixture.EVENT2; eventRepository.save(event2); - Action action2 = Action.createFirst(event2); - MemberAction anotherMemberAction = new MemberAction(action2, "참여자", IN, 1L); + MemberAction anotherMemberAction = Fixture.createMemberAction(event2, 1L, "참여자", IN); memberActionRepository.save(anotherMemberAction); memberActionService.deleteMember(event.getToken(), "참여자"); @@ -130,12 +124,11 @@ void deleteMember() { void deleteMember1() { Event event = Fixture.EVENT1; eventRepository.save(event); - MemberAction memberAction1 = createMemberAction(new Action(event, 1L), "토다리", IN, 1L); - Action targetAction = new Action(event, 2L); - MemberAction memberAction2 = createMemberAction(targetAction, "토다리", OUT, 2L); - MemberAction memberAction3 = createMemberAction(new Action(event, 3L), "쿠키", IN, 3L); - MemberAction memberAction4 = createMemberAction(new Action(event, 4L), "웨디", IN, 4L); - MemberAction memberAction5 = createMemberAction(new Action(event, 5L), "감자", IN, 5L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "토다리", OUT); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "쿠키", IN); + MemberAction memberAction4 = Fixture.createMemberAction(event, 4L, "웨디", IN); + MemberAction memberAction5 = Fixture.createMemberAction(event, 5L, "감자", IN); memberActionRepository.saveAll( List.of(memberAction1, memberAction2, @@ -144,14 +137,12 @@ void deleteMember1() { memberAction5 ) ); - BillAction billAction = new BillAction(new Action(event, 6L), "뽕족", 100_000L); + BillAction billAction = Fixture.createBillAction(event, 6L, "뽕족", 100_000L); billActionRepository.save(billAction); BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "쿠키", 40_000L, true); BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "웨디", 30_000L, false); BillActionDetail billActionDetail3 = new BillActionDetail(billAction, "감자", 30_000L, false); billActionDetailRepository.saveAll(List.of(billActionDetail1, billActionDetail2, billActionDetail3)); - List allByBillAction = billActionDetailRepository.findAllByBillAction(billAction); - System.out.println("allByBillAction = " + allByBillAction.isEmpty()); memberActionService.deleteMember(event.getToken(), "쿠키"); @@ -170,14 +161,13 @@ void deleteMember1() { void deleteMemberAction() { Event event = Fixture.EVENT1; eventRepository.save(event); - MemberAction memberAction1 = createMemberAction(new Action(event, 1L), "토다리", IN, 1L); - Action targetAction = new Action(event, 2L); - MemberAction memberAction2 = createMemberAction(targetAction, "토다리", OUT, 2L); - MemberAction memberAction3 = createMemberAction(new Action(event, 3L), "쿠키", IN, 3L); - MemberAction memberAction4 = createMemberAction(new Action(event, 4L), "웨디", IN, 4L); - MemberAction memberAction5 = createMemberAction(new Action(event, 5L), "토다리", IN, 5L); - MemberAction memberAction6 = createMemberAction(new Action(event, 6L), "토다리", OUT, 6L); - MemberAction memberAction7 = createMemberAction(new Action(event, 7L), "쿠키", OUT, 7L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "토다리", OUT); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "쿠키", IN); + MemberAction memberAction4 = Fixture.createMemberAction(event, 4L, "웨디", IN); + MemberAction memberAction5 = Fixture.createMemberAction(event, 5L, "토다리", IN); + MemberAction memberAction6 = Fixture.createMemberAction(event, 6L, "토다리", OUT); + MemberAction memberAction7 = Fixture.createMemberAction(event, 7L, "쿠키", OUT); memberActionRepository.saveAll( List.of(memberAction1, memberAction2, @@ -188,7 +178,7 @@ void deleteMemberAction() { memberAction7) ); - memberActionService.deleteMemberAction(event.getToken(), targetAction.getId()); + memberActionService.deleteMemberAction(event.getToken(), memberAction2.getId()); List memberActions = memberActionRepository.findAll(); assertThat(memberActions).hasSize(4) @@ -206,12 +196,11 @@ void deleteMemberAction() { void deleteMemberAction1() { Event event = Fixture.EVENT1; eventRepository.save(event); - MemberAction memberAction1 = createMemberAction(new Action(event, 1L), "토다리", IN, 1L); - Action targetAction = new Action(event, 2L); - MemberAction memberAction2 = createMemberAction(targetAction, "토다리", OUT, 2L); - MemberAction memberAction3 = createMemberAction(new Action(event, 3L), "쿠키", IN, 3L); - MemberAction memberAction4 = createMemberAction(new Action(event, 4L), "웨디", IN, 4L); - MemberAction memberAction5 = createMemberAction(new Action(event, 5L), "감자", IN, 5L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "토다리", IN); + MemberAction memberAction2 = Fixture.createMemberAction(event, 2L, "토다리", OUT); + MemberAction memberAction3 = Fixture.createMemberAction(event, 3L, "쿠키", IN); + MemberAction memberAction4 = Fixture.createMemberAction(event, 4L, "웨디", IN); + MemberAction memberAction5 = Fixture.createMemberAction(event, 5L, "감자", IN); memberActionRepository.saveAll( List.of(memberAction1, memberAction2, @@ -220,14 +209,14 @@ void deleteMemberAction1() { memberAction5 ) ); - BillAction billAction = new BillAction(new Action(event, 6L), "뽕족", 100_000L); + BillAction billAction = Fixture.createBillAction(event, 6L, "뽕족", 100_000L); billActionRepository.save(billAction); BillActionDetail billActionDetail1 = new BillActionDetail(billAction, "쿠키", 40_000L, true); BillActionDetail billActionDetail2 = new BillActionDetail(billAction, "웨디", 30_000L, false); BillActionDetail billActionDetail3 = new BillActionDetail(billAction, "감자", 30_000L, false); billActionDetailRepository.saveAll(List.of(billActionDetail1, billActionDetail2, billActionDetail3)); - memberActionService.deleteMemberAction(event.getToken(), targetAction.getId()); + memberActionService.deleteMemberAction(event.getToken(), memberAction2.getId()); List billActionDetails = billActionDetailRepository.findAllByBillAction(billAction); assertThat(billActionDetails).hasSize(4) @@ -239,13 +228,4 @@ void deleteMemberAction1() { tuple("감자", 25_000L) ); } - - private MemberAction createMemberAction( - Action action, - String memberName, - MemberActionStatus memberActionStatus, - long memberGroupId - ) { - return new MemberAction(action, memberName, memberActionStatus, memberGroupId); - } } diff --git a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java index 202b64fcf..6950f3d23 100644 --- a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java +++ b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java @@ -30,7 +30,6 @@ import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import server.haengdong.application.ActionService; import server.haengdong.application.AuthService; import server.haengdong.application.EventService; import server.haengdong.application.request.EventAppRequest; @@ -49,14 +48,13 @@ public class EventControllerDocsTest extends RestDocsSupport { private final EventService eventService = mock(EventService.class); private final AuthService authService = mock(AuthService.class); - private final ActionService actionService = mock(ActionService.class); private final CookieProperties cookieProperties = new CookieProperties( true, true, "domain", "path", "none", Duration.ofDays(7) ); @Override protected Object initController() { - return new EventController(eventService, authService, cookieProperties, actionService); + return new EventController(eventService, authService, cookieProperties); } @DisplayName("토큰으로 행사를 조회한다.") @@ -253,7 +251,7 @@ void getMemberBillReports() throws Exception { List memberBillReportAppResponses = List.of( new MemberBillReportAppResponse("소하", 20_000L), new MemberBillReportAppResponse("토다리", 200_000L)); - given(actionService.getMemberBillReports(any())).willReturn(memberBillReportAppResponses); + given(eventService.getMemberBillReports(any())).willReturn(memberBillReportAppResponses); mockMvc.perform(get("/api/events/{eventId}/reports", "망쵸토큰") .accept(MediaType.APPLICATION_JSON)) diff --git a/server/src/test/java/server/haengdong/domain/action/ActionTest.java b/server/src/test/java/server/haengdong/domain/action/ActionTest.java deleted file mode 100644 index 6ff25479c..000000000 --- a/server/src/test/java/server/haengdong/domain/action/ActionTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package server.haengdong.domain.action; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import server.haengdong.domain.event.Event; -import server.haengdong.support.fixture.Fixture; - -class ActionTest { - - @DisplayName("액션의 초기 순서번호는 1이다.") - @Test - void createFirst() { - Event event = Fixture.EVENT1; - Action action = Action.createFirst(event); - - assertThat(action.getSequence()).isOne(); - } - - @DisplayName("현재 액션의 다음 액션의 순서는 1만큼 증가한다.") - @Test - void next() { - Event event = Fixture.EVENT1; - Action action = new Action(event, 2L); - - Action nextAction = action.next(); - - assertThat(nextAction.getSequence()).isEqualTo(3L); - } -} diff --git a/server/src/test/java/server/haengdong/domain/action/BillActionTest.java b/server/src/test/java/server/haengdong/domain/action/BillActionTest.java index ba1ab36f2..d66202663 100644 --- a/server/src/test/java/server/haengdong/domain/action/BillActionTest.java +++ b/server/src/test/java/server/haengdong/domain/action/BillActionTest.java @@ -11,8 +11,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import server.haengdong.domain.event.Event; import server.haengdong.exception.HaengdongException; +import server.haengdong.support.fixture.Fixture; class BillActionTest { @@ -20,11 +20,10 @@ class BillActionTest { @ParameterizedTest @ValueSource(strings = {"", " ", "1234567890123456789012345678901"}) void validateTitle(String title) { - Event event = EVENT1; - Action action = new Action(event, 1L); + Sequence sequence = new Sequence(1L); Long price = 100L; - assertThatThrownBy(() -> new BillAction(action, title, price)) + assertThatThrownBy(() -> new BillAction(EVENT1, sequence, title, price)) .isInstanceOf(HaengdongException.class) .hasMessage("앞뒤 공백을 제거한 지출 내역 제목은 1 ~ 30자여야 합니다."); } @@ -33,11 +32,10 @@ void validateTitle(String title) { @ParameterizedTest @ValueSource(longs = {0, 10_000_001, 20_000_000}) void validatePrice(long price) { - Event event = EVENT1; - Action action = new Action(event, 1L); + Sequence sequence = new Sequence(1L); String title = "title"; - assertThatThrownBy(() -> new BillAction(action, title, price)) + assertThatThrownBy(() -> new BillAction(EVENT1, sequence, title, price)) .isInstanceOf(HaengdongException.class) .hasMessage("지출 금액은 10,000,000 이하의 자연수여야 합니다."); } @@ -45,15 +43,14 @@ void validatePrice(long price) { @DisplayName("지출 내역을 올바르게 생성한다.") @Test void createBillAction() { - Event event = EVENT1; - Action action = new Action(event, 1L); + Sequence sequence = new Sequence(1L); String title = "title"; Long price = 1_000L; - BillAction billAction = new BillAction(action, title, price); + BillAction billAction = new BillAction(EVENT1, sequence, title, price); assertAll( - () -> assertThat(billAction.getAction()).isEqualTo(action), + () -> assertThat(billAction.getSequence().getValue()).isEqualTo(1L), () -> assertThat(billAction.getTitle()).isEqualTo(title), () -> assertThat(billAction.getPrice()).isEqualTo(price) ); @@ -62,7 +59,7 @@ void createBillAction() { @DisplayName("지출 액션에 멤버별 고정 금액이 설정되어 있는지 확인한다.") @Test void isFixed1() { - BillAction fixedBillAction = new BillAction(new Action(EVENT1, 1L), "인생네컷", 2_000L); + BillAction fixedBillAction = Fixture.createBillAction(EVENT1, 1L, "인생네컷", 2_000L); List unfixedBillActionDetails = List.of( new BillActionDetail(BILL_ACTION, "감자", 1_000L, false), @@ -76,7 +73,7 @@ void isFixed1() { @DisplayName("지출 액션에 멤버별 고정 금액이 설정되어 있는지 확인한다.") @Test void isFixed2() { - BillAction fixedBillAction = new BillAction(new Action(EVENT1, 1L), "인생네컷", 5_000L); + BillAction fixedBillAction = Fixture.createBillAction(EVENT1, 1L, "인생네컷", 5_000L); List unfixedBillActionDetails = List.of( new BillActionDetail(BILL_ACTION, "감자", 4_000L, true), diff --git a/server/src/test/java/server/haengdong/domain/action/CurrentMembersTest.java b/server/src/test/java/server/haengdong/domain/action/CurrentMembersTest.java index 93148abd3..95eab19cc 100644 --- a/server/src/test/java/server/haengdong/domain/action/CurrentMembersTest.java +++ b/server/src/test/java/server/haengdong/domain/action/CurrentMembersTest.java @@ -20,10 +20,10 @@ class CurrentMembersTest { void of() { Event event = Fixture.EVENT1; List memberActions = List.of( - new MemberAction(new Action(event, 1L), "망쵸", IN, 1L), - new MemberAction(new Action(event, 2L), "백호", IN, 1L), - new MemberAction(new Action(event, 3L), "백호", OUT, 1L), - new MemberAction(new Action(event, 4L), "웨디", IN, 1L) + Fixture.createMemberAction(event, 1L, "망쵸", IN), + Fixture.createMemberAction(event, 2L, "백호", IN), + Fixture.createMemberAction(event, 3L, "백호", OUT), + Fixture.createMemberAction(event, 4L, "웨디", IN) ); CurrentMembers currentMembers = CurrentMembers.of(memberActions); @@ -37,7 +37,7 @@ void of() { void addMemberAction1() { CurrentMembers currentMembers = new CurrentMembers(); Event event = Fixture.EVENT1; - MemberAction memberAction = new MemberAction(new Action(event, 1L), "웨디", IN, 1L); + MemberAction memberAction = Fixture.createMemberAction(event, 1L, "웨디", IN); CurrentMembers addedCurrentMembers = currentMembers.addMemberAction(memberAction); Set members = addedCurrentMembers.getMembers(); @@ -50,9 +50,9 @@ void addMemberAction1() { @Test void addMemberAction2() { Event event = Fixture.EVENT1; - MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "웨디", IN, 1L); + MemberAction memberAction1 = Fixture.createMemberAction(event, 1L, "웨디", IN); CurrentMembers currentMembers = new CurrentMembers().addMemberAction(memberAction1); - MemberAction memberAction2 = new MemberAction(new Action(event, 1L), "웨디", OUT, 1L); + MemberAction memberAction2 = Fixture.createMemberAction(event, 1L, "웨디", OUT); CurrentMembers addedCurrentMembers = currentMembers.addMemberAction(memberAction2); diff --git a/server/src/test/java/server/haengdong/domain/action/MemberBillReportTest.java b/server/src/test/java/server/haengdong/domain/action/MemberBillReportTest.java index 02070a537..4a009d2df 100644 --- a/server/src/test/java/server/haengdong/domain/action/MemberBillReportTest.java +++ b/server/src/test/java/server/haengdong/domain/action/MemberBillReportTest.java @@ -19,8 +19,8 @@ class MemberBillReportTest { void createByActions() { Event event = Fixture.EVENT1; List billActions = List.of( - new BillAction(new Action(event, 4L), "뽕족", 60_000L), - new BillAction(new Action(event, 7L), "인생네컷", 20_000L) + Fixture.createBillAction(event, 4L, "뽕족", 60_000L), + Fixture.createBillAction(event, 7L, "인생네컷", 20_000L) ); billActions.get(0).addDetails( List.of( @@ -36,10 +36,10 @@ void createByActions() { ) ); List memberActions = List.of( - new MemberAction(new Action(event, 1L), "소하", IN, 1L), - new MemberAction(new Action(event, 2L), "감자", IN, 1L), - new MemberAction(new Action(event, 3L), "쿠키", IN, 1L), - new MemberAction(new Action(event, 5L), "감자", OUT, 2L) + Fixture.createMemberAction(event, 1L, "소하", IN), + Fixture.createMemberAction(event, 2L, "감자", IN), + Fixture.createMemberAction(event, 3L, "쿠키", IN), + Fixture.createMemberAction(event, 5L, "감자", OUT) ); MemberBillReport memberBillReport = MemberBillReport.createByActions(billActions, memberActions); diff --git a/server/src/test/java/server/haengdong/domain/action/SequenceTest.java b/server/src/test/java/server/haengdong/domain/action/SequenceTest.java new file mode 100644 index 000000000..d2277d593 --- /dev/null +++ b/server/src/test/java/server/haengdong/domain/action/SequenceTest.java @@ -0,0 +1,27 @@ +package server.haengdong.domain.action; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class SequenceTest { + + @DisplayName("액션의 초기 순서번호는 1이다.") + @Test + void createFirst() { + Sequence sequence = Sequence.createFirst(); + + assertThat(sequence.getValue()).isOne(); + } + + @DisplayName("현재 액션의 다음 액션의 순서는 1만큼 증가한다.") + @Test + void next() { + Sequence sequence = new Sequence(2L); + + Sequence nextAction = sequence.next(); + + assertThat(nextAction.getValue()).isEqualTo(3L); + } +} diff --git a/server/src/test/java/server/haengdong/presentation/ControllerTestSupport.java b/server/src/test/java/server/haengdong/presentation/ControllerTestSupport.java index c20043381..f5964e897 100644 --- a/server/src/test/java/server/haengdong/presentation/ControllerTestSupport.java +++ b/server/src/test/java/server/haengdong/presentation/ControllerTestSupport.java @@ -8,7 +8,6 @@ import org.springframework.context.annotation.FilterType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import server.haengdong.application.ActionService; import server.haengdong.application.AuthService; import server.haengdong.application.BillActionDetailService; import server.haengdong.application.BillActionService; @@ -43,9 +42,6 @@ public abstract class ControllerTestSupport { @MockBean protected AuthService authService; - @MockBean - protected ActionService actionService; - @MockBean protected MemberActionService memberActionService; diff --git a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java index a45c73230..a58924a32 100644 --- a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java +++ b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java @@ -60,7 +60,7 @@ void getMemberBillReports() throws Exception { List memberBillReportAppResponses = List.of( new MemberBillReportAppResponse("소하", 20_000L), new MemberBillReportAppResponse("토다리", 200_000L)); - given(actionService.getMemberBillReports(any())).willReturn(memberBillReportAppResponses); + given(eventService.getMemberBillReports(any())).willReturn(memberBillReportAppResponses); mockMvc.perform(get("/api/events/{eventId}/reports", "망쵸토큰") .accept(MediaType.APPLICATION_JSON)) diff --git a/server/src/test/java/server/haengdong/support/fixture/Fixture.java b/server/src/test/java/server/haengdong/support/fixture/Fixture.java index 6844915d9..b8d736d4b 100644 --- a/server/src/test/java/server/haengdong/support/fixture/Fixture.java +++ b/server/src/test/java/server/haengdong/support/fixture/Fixture.java @@ -1,8 +1,10 @@ package server.haengdong.support.fixture; import jakarta.servlet.http.Cookie; -import server.haengdong.domain.action.Action; import server.haengdong.domain.action.BillAction; +import server.haengdong.domain.action.MemberAction; +import server.haengdong.domain.action.MemberActionStatus; +import server.haengdong.domain.action.Sequence; import server.haengdong.domain.event.Event; public class Fixture { @@ -10,6 +12,15 @@ public class Fixture { public static final Event EVENT1 = new Event("쿠키", "1234", "TOKEN1"); public static final Event EVENT2 = new Event("웨디", "1234", "TOKEN2"); public static final Cookie EVENT_COOKIE = new Cookie("eventToken", "토큰토큰"); - public static final Action ACTION = new Action(EVENT1, 1L); - public static final BillAction BILL_ACTION = new BillAction(ACTION, "뽕족", 30_000L); + public static final BillAction BILL_ACTION = new BillAction(EVENT1, new Sequence(1L), "뽕족", 30_000L); + + public static BillAction createBillAction(Event event, Long sequence, String title, Long price) { + return new BillAction(event, new Sequence(sequence), title, price); + } + + public static MemberAction createMemberAction( + Event event, Long sequence, String memberName, MemberActionStatus status + ) { + return new MemberAction(event, new Sequence(sequence), memberName, status); + } }