Skip to content

Commit

Permalink
[HOTFIX] dto mapping failing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Jan 13, 2024
1 parent 3d823bb commit b5fa81a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,6 +17,7 @@

@Entity
@Getter
@EqualsAndHashCode(of = "nickname")
@Where(clause = "deleted_at is null")
@EntityListeners(AuditListener.class)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,16 @@ public void deleteInvite(final Member member) {

public List<Member> 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<Member> membersByIds) {
membersByIds.forEach(this::addMember);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberResponse> memberResponses,
List<MemberResponse> 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<MemberResponse> memberResponses);

@IterableMapping(qualifiedByName = "toPlaceDetail")
List<PlaceDetails> toPlaceDetails(List<PlaceClientDetails> placeClientDetails);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<MemberResponse> notJoinedMembers =
memberService.getResponsesByMembers(plan.getNotJoinedMembers());
String planDay = plan.getPlanDay().format(DATE_TIME_FORMATTER);
List<MemberResponse> memberResponses = toMemberResponse(plan);
List<MemberResponse> 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<MemberResponse> memberResponses = toMemberResponse(plan);

return planMapper.toPlanInfoResponse(
plan, placeDetails, planDay, groupInfo, memberResponses);
}

public void deletePlan(UUID id) {
planRepository.deleteById(id);
}

private List<MemberResponse> toMemberResponse(Plan plan) {
return memberService.getMemberResponses(plan);
}

public Plan getPlanEntity(UUID id) {
return planRepository.findById(id).orElseThrow(EntityNotFoundException::new);
}
Expand Down

0 comments on commit b5fa81a

Please sign in to comment.