From b5fa81a73fd34ba76b90aa61b94b3efe95d88879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=8A=B9=EC=A7=84?= Date: Sat, 13 Jan 2024 21:14:03 +0900 Subject: [PATCH] [HOTFIX] dto mapping failing issue --- .../backend/domain/member/entity/Member.java | 7 ++---- .../domain/place/mapper/PlaceMapper.java | 8 +++--- .../domain/place/service/PlaceService.java | 2 +- .../twtw/backend/domain/plan/entity/Plan.java | 7 +++++- .../domain/plan/mapper/PlanMapper.java | 16 +----------- .../domain/plan/service/PlanService.java | 25 ++++--------------- 6 files changed, 18 insertions(+), 47 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java index 0cd7d92c..7571b1cc 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java @@ -7,11 +7,7 @@ import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.hibernate.annotations.Where; @@ -21,6 +17,7 @@ @Entity @Getter +@EqualsAndHashCode(of = "nickname") @Where(clause = "deleted_at is null") @EntityListeners(AuditListener.class) @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/src/main/java/com/twtw/backend/domain/place/mapper/PlaceMapper.java b/backend/src/main/java/com/twtw/backend/domain/place/mapper/PlaceMapper.java index 4bb3760a..5b5cb1d6 100644 --- a/backend/src/main/java/com/twtw/backend/domain/place/mapper/PlaceMapper.java +++ b/backend/src/main/java/com/twtw/backend/domain/place/mapper/PlaceMapper.java @@ -1,9 +1,7 @@ package com.twtw.backend.domain.place.mapper; import com.twtw.backend.domain.place.entity.Place; -import com.twtw.backend.domain.plan.dto.client.PlaceClientDetails; import com.twtw.backend.domain.plan.dto.response.PlaceDetails; - import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingConstants; @@ -13,7 +11,7 @@ public interface PlaceMapper { Place toEntity(PlaceDetails detail); - @Mapping(target = "x", source = "coordinate.longitude") - @Mapping(target = "y", source = "coordinate.latitude") - PlaceClientDetails toPlaceResponse(Place place); + @Mapping(target = "longitude", source = "coordinate.longitude") + @Mapping(target = "latitude", source = "coordinate.latitude") + PlaceDetails toPlaceResponse(Place place); } diff --git a/backend/src/main/java/com/twtw/backend/domain/place/service/PlaceService.java b/backend/src/main/java/com/twtw/backend/domain/place/service/PlaceService.java index cb0ff6d6..25538e4b 100644 --- a/backend/src/main/java/com/twtw/backend/domain/place/service/PlaceService.java +++ b/backend/src/main/java/com/twtw/backend/domain/place/service/PlaceService.java @@ -30,7 +30,7 @@ public PlaceResponse searchSurroundPlace(final SurroundPlaceRequest surroundPlac return new PlaceResponse(response.getDocuments(), response.getMeta().getIsEnd()); } - public PlaceClientDetails getPlaceDetails(Place place) { + public PlaceDetails getPlaceDetails(Place place) { return placeMapper.toPlaceResponse(place); } diff --git a/backend/src/main/java/com/twtw/backend/domain/plan/entity/Plan.java b/backend/src/main/java/com/twtw/backend/domain/plan/entity/Plan.java index f118ef20..699d2b1b 100644 --- a/backend/src/main/java/com/twtw/backend/domain/plan/entity/Plan.java +++ b/backend/src/main/java/com/twtw/backend/domain/plan/entity/Plan.java @@ -145,11 +145,16 @@ public void deleteInvite(final Member member) { public List getNotJoinedMembers() { return this.group.getGroupMembers().stream() + .filter(GroupMember::isAccepted) .map(GroupMember::getMember) - .filter(member -> !hasSameMember(member)) + .filter(this::isNotJoined) .toList(); } + private boolean isNotJoined(Member member) { + return this.planMembers.stream().noneMatch(planMember -> planMember.isSameMember(member) && planMember.isAccepted()); + } + public void addMembers(final List membersByIds) { membersByIds.forEach(this::addMember); } diff --git a/backend/src/main/java/com/twtw/backend/domain/plan/mapper/PlanMapper.java b/backend/src/main/java/com/twtw/backend/domain/plan/mapper/PlanMapper.java index 74ab26a5..358842ec 100644 --- a/backend/src/main/java/com/twtw/backend/domain/plan/mapper/PlanMapper.java +++ b/backend/src/main/java/com/twtw/backend/domain/plan/mapper/PlanMapper.java @@ -42,26 +42,12 @@ public interface PlanMapper { @Mapping(target = "planDay", source = "planDay") PlanInfoResponse toPlanInfoResponse( Plan plan, - PlaceClientDetails placeDetails, + PlaceDetails placeDetails, String planDay, GroupInfoResponse groupInfoResponse, List memberResponses, List notJoinedMembers); - @Mapping(target = "planId", source = "plan.id") - @Mapping(target = "name", source = "plan.name") - @Mapping(target = "placeId", source = "plan.place.id") - @Mapping(target = "planMakerId", source = "plan.planMakerId") - @Mapping(target = "groupInfo", source = "groupInfoResponse") - @Mapping(target = "members", source = "memberResponses") - @Mapping(target = "planDay", source = "planDay") - PlanInfoResponse toPlanInfoResponse( - Plan plan, - PlaceClientDetails placeDetails, - String planDay, - GroupInfoResponse groupInfoResponse, - List memberResponses); - @IterableMapping(qualifiedByName = "toPlaceDetail") List toPlaceDetails(List placeClientDetails); diff --git a/backend/src/main/java/com/twtw/backend/domain/plan/service/PlanService.java b/backend/src/main/java/com/twtw/backend/domain/plan/service/PlanService.java index e8c6d138..0d3d0d0d 100644 --- a/backend/src/main/java/com/twtw/backend/domain/plan/service/PlanService.java +++ b/backend/src/main/java/com/twtw/backend/domain/plan/service/PlanService.java @@ -18,6 +18,7 @@ import com.twtw.backend.domain.plan.dto.request.SavePlanRequest; import com.twtw.backend.domain.plan.dto.request.UpdatePlanDayRequest; import com.twtw.backend.domain.plan.dto.request.UpdatePlanRequest; +import com.twtw.backend.domain.plan.dto.response.PlaceDetails; import com.twtw.backend.domain.plan.dto.response.PlanDestinationResponse; import com.twtw.backend.domain.plan.dto.response.PlanInfoResponse; import com.twtw.backend.domain.plan.dto.response.PlanResponse; @@ -28,9 +29,7 @@ import com.twtw.backend.global.constant.NotificationBody; import com.twtw.backend.global.constant.NotificationTitle; import com.twtw.backend.global.exception.EntityNotFoundException; - import lombok.RequiredArgsConstructor; - import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -125,39 +124,25 @@ public void outPlan(PlanMemberRequest request) { public PlanInfoResponse getPlanById(UUID id) { Plan plan = getPlanEntity(id); - return getPlanInfoResponseWithNotJoinedMembers(plan); + return getPlanInfoResponse(plan); } - private PlanInfoResponse getPlanInfoResponseWithNotJoinedMembers(final Plan plan) { + private PlanInfoResponse getPlanInfoResponse(final Plan plan) { GroupInfoResponse groupInfo = groupService.getGroupInfoResponse(plan.getGroup()); - PlaceClientDetails placeDetails = placeService.getPlaceDetails(plan.getPlace()); + PlaceDetails placeDetails = placeService.getPlaceDetails(plan.getPlace()); List notJoinedMembers = memberService.getResponsesByMembers(plan.getNotJoinedMembers()); String planDay = plan.getPlanDay().format(DATE_TIME_FORMATTER); - List memberResponses = toMemberResponse(plan); + List memberResponses = memberService.getMemberResponses(plan); return planMapper.toPlanInfoResponse( plan, placeDetails, planDay, groupInfo, memberResponses, notJoinedMembers); } - private PlanInfoResponse getPlanInfoResponse(final Plan plan) { - GroupInfoResponse groupInfo = groupService.getGroupInfoResponse(plan.getGroup()); - PlaceClientDetails placeDetails = placeService.getPlaceDetails(plan.getPlace()); - String planDay = plan.getPlanDay().format(DATE_TIME_FORMATTER); - List memberResponses = toMemberResponse(plan); - - return planMapper.toPlanInfoResponse( - plan, placeDetails, planDay, groupInfo, memberResponses); - } - public void deletePlan(UUID id) { planRepository.deleteById(id); } - private List toMemberResponse(Plan plan) { - return memberService.getMemberResponses(plan); - } - public Plan getPlanEntity(UUID id) { return planRepository.findById(id).orElseThrow(EntityNotFoundException::new); }