Skip to content

Commit

Permalink
[HOTFIX] dto mapping error
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Jan 19, 2024
1 parent 9f307d8 commit e3cc308
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.twtw.backend.domain.group.dto.request.*;
import com.twtw.backend.domain.group.dto.response.GroupInfoResponse;
import com.twtw.backend.domain.group.dto.response.GroupResponse;
import com.twtw.backend.domain.group.service.GroupService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -62,7 +62,7 @@ public ResponseEntity<Void> unShareLocation(@PathVariable UUID id) {
}

@GetMapping
public ResponseEntity<List<GroupInfoResponse>> getMyGroups() {
public ResponseEntity<List<GroupResponse>> getMyGroups() {
return ResponseEntity.ok(groupService.getMyGroups());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.twtw.backend.domain.group.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GroupResponse {
private UUID groupId;
private UUID leaderId;
private String name;
private String groupImage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.twtw.backend.domain.group.dto.request.MakeGroupRequest;
import com.twtw.backend.domain.group.dto.response.GroupInfoResponse;
import com.twtw.backend.domain.group.dto.response.GroupMemberResponse;
import com.twtw.backend.domain.group.dto.response.GroupResponse;
import com.twtw.backend.domain.group.entity.Group;
import com.twtw.backend.domain.group.entity.GroupMember;
import com.twtw.backend.domain.member.entity.Member;

import org.mapstruct.*;

import java.util.List;
Expand All @@ -30,13 +30,13 @@ public interface GroupMapper {
@Mapping(target = "groupMembers", source = "groupMembers")
GroupInfoResponse toGroupInfo(Group group, List<GroupMemberResponse> groupMembers);

@Named("groupMemberToGroupInfoResponse")
@Named("groupMemberToGroupResponse")
@Mapping(target = "groupId", source = "groupMember.group.id")
@Mapping(target = "leaderId", source = "groupMember.group.leaderId")
@Mapping(target = "name", source = "groupMember.group.name")
@Mapping(target = "groupImage", source = "groupMember.group.groupImage")
GroupInfoResponse toGroupInfoResponse(GroupMember groupMember);
GroupResponse toGroupResponse(GroupMember groupMember);

@IterableMapping(qualifiedByName = "groupMemberToGroupInfoResponse")
List<GroupInfoResponse> toMyGroupsInfo(List<GroupMember> groupMembers);
@IterableMapping(qualifiedByName = "groupMemberToGroupResponse")
List<GroupResponse> toGroupResponses(List<GroupMember> groupMembers);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.twtw.backend.domain.group.dto.request.*;
import com.twtw.backend.domain.group.dto.response.GroupInfoResponse;
import com.twtw.backend.domain.group.dto.response.GroupMemberResponse;
import com.twtw.backend.domain.group.dto.response.GroupResponse;
import com.twtw.backend.domain.group.entity.Group;
import com.twtw.backend.domain.group.entity.GroupMember;
import com.twtw.backend.domain.group.mapper.GroupMapper;
Expand All @@ -15,7 +16,6 @@
import com.twtw.backend.global.constant.NotificationBody;
import com.twtw.backend.global.constant.NotificationTitle;
import com.twtw.backend.global.exception.EntityNotFoundException;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -127,14 +127,14 @@ public GroupInfoResponse getGroupInfoResponse(Group group) {
}

@Transactional(readOnly = true)
public List<GroupInfoResponse> getMyGroups() {
public List<GroupResponse> getMyGroups() {
Member loginMember = authService.getMemberByJwt();

if (loginMember.hasNoGroupMember()) {
return List.of();
}

return groupMapper.toMyGroupsInfo(loginMember.getGroupMembers());
return groupMapper.toGroupResponses(loginMember.getGroupMembers());
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class Place implements Auditable {

private String placeUrl;

private CategoryGroupCode categoryGroupCode;

private String roadAddressName;

@Embedded private Coordinate coordinate;
Expand All @@ -52,27 +50,23 @@ public class Place implements Auditable {
public Place(
final String placeName,
final String placeUrl,
final CategoryGroupCode categoryGroupCode,
final String roadAddressName,
final Double longitude,
final Double latitude) {
this.placeName = placeName;
this.placeUrl = placeUrl;
this.categoryGroupCode = categoryGroupCode;
this.roadAddressName = roadAddressName;
this.coordinate = new Coordinate(longitude, latitude);
}

public void update(
final String placeName,
final String placeUrl,
final CategoryGroupCode categoryGroupCode,
final String roadAddressName,
final Double longitude,
final Double latitude) {
this.placeName = placeName;
this.placeUrl = placeUrl;
this.categoryGroupCode = categoryGroupCode;
this.roadAddressName = roadAddressName;
this.coordinate = new Coordinate(longitude, latitude);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@
import com.twtw.backend.domain.plan.dto.client.SearchDestinationRequest;
import com.twtw.backend.domain.plan.dto.request.PlanMemberRequest;
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.PlanDestinationResponse;
import com.twtw.backend.domain.plan.dto.response.PlanInfoResponse;
import com.twtw.backend.domain.plan.dto.response.PlanResponse;
import com.twtw.backend.domain.plan.service.PlanService;

import lombok.RequiredArgsConstructor;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -76,12 +66,6 @@ public ResponseEntity<Void> outPlan(@RequestBody PlanMemberRequest request) {
return ResponseEntity.noContent().build();
}

@PostMapping("/day")
public ResponseEntity<Void> updatePlanDay(@RequestBody final UpdatePlanDayRequest request) {
planService.updatePlanDay(request);
return ResponseEntity.noContent().build();
}

@GetMapping
public ResponseEntity<List<PlanInfoResponse>> getPlans() {
return ResponseEntity.ok(planService.getPlans());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
import com.twtw.backend.domain.group.entity.Group;
import com.twtw.backend.domain.group.entity.GroupMember;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;
import com.twtw.backend.domain.place.entity.Place;
import com.twtw.backend.domain.plan.exception.PlanMakerNotExistsException;
import com.twtw.backend.global.audit.AuditListener;
import com.twtw.backend.global.audit.Auditable;
import com.twtw.backend.global.audit.BaseTime;

import jakarta.persistence.*;

import lombok.*;

import org.hibernate.annotations.Where;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -104,14 +100,13 @@ public void updatePlace(
final LocalDateTime planDay,
final String placeName,
final String placeUrl,
final CategoryGroupCode categoryGroupCode,
final String roadAddressName,
final Double longitude,
final Double latitude) {
this.name = name;
this.planDay = planDay;
this.place.update(
placeName, placeUrl, categoryGroupCode, roadAddressName, longitude, latitude);
placeName, placeUrl, roadAddressName, longitude, latitude);
}

public void updateMemberLocation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.twtw.backend.domain.plan.dto.client.SearchDestinationResponse;
import com.twtw.backend.domain.plan.dto.request.PlanMemberRequest;
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;
Expand All @@ -29,9 +28,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 @@ -167,7 +164,6 @@ public void updatePlan(final UpdatePlanRequest updatePlanRequest) {
updatePlanRequest.getPlanDay(),
placeName,
updatePlanRequest.getPlaceUrl(),
updatePlanRequest.getCategoryGroupCode(),
updatePlanRequest.getRoadAddressName(),
updatePlanRequest.getLongitude(),
updatePlanRequest.getLatitude());
Expand All @@ -192,12 +188,6 @@ private void sendDestinationNotification(
id.toString()));
}

@Transactional
public void updatePlanDay(final UpdatePlanDayRequest request) {
final Plan plan = getPlanEntity(request.getPlanId());
plan.updatePlanDay(request.getChangeDay());
}

@Transactional
public void joinPlan(final PlanMemberRequest request) {
Member member = authService.getMemberByJwt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
package com.twtw.backend.domain.group.controller;

import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest;
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.twtw.backend.domain.group.dto.request.*;
import com.twtw.backend.domain.group.dto.response.GroupInfoResponse;
import com.twtw.backend.domain.group.dto.response.GroupMemberResponse;
import com.twtw.backend.domain.group.dto.response.GroupResponse;
import com.twtw.backend.domain.group.service.GroupService;
import com.twtw.backend.support.docs.RestDocsTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -29,6 +17,17 @@
import java.util.List;
import java.util.UUID;

import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest;
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@DisplayName("GroupController의")
@WebMvcTest(GroupController.class)
class GroupControllerTest extends RestDocsTest {
Expand Down Expand Up @@ -259,36 +258,20 @@ void getMyGroups() throws Exception {
// given
final UUID leaderId = UUID.randomUUID();

List<GroupInfoResponse> responseList = new ArrayList<>();
List<GroupResponse> responseList = new ArrayList<>();

GroupInfoResponse response1 =
new GroupInfoResponse(
GroupResponse response1 =
new GroupResponse(
UUID.randomUUID(),
leaderId,
"BLACK_PINK",
"I_LOVE_YOU_LOSE",
List.of(
new GroupMemberResponse(
UUID.randomUUID(), "DEAN", "http://hojiniSelfie", true),
new GroupMemberResponse(
UUID.randomUUID(),
"ZION-T",
"http://hojiniSelfie",
false)));
GroupInfoResponse response2 =
new GroupInfoResponse(
"I_LOVE_YOU_LOSE");
GroupResponse response2 =
new GroupResponse(
UUID.randomUUID(),
leaderId,
"LE_SSERAFIM",
"I_LOVE_YOU_채원",
List.of(
new GroupMemberResponse(
UUID.randomUUID(), "DEAN", "http://hojiniSelfie", true),
new GroupMemberResponse(
UUID.randomUUID(),
"ZION-T",
"http://hojiniSelfie",
false)));
"I_LOVE_YOU_채원");

responseList.add(response1);
responseList.add(response2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.twtw.backend.domain.group.service;

import static org.assertj.core.api.Assertions.assertThat;

import com.twtw.backend.domain.group.dto.request.InviteGroupRequest;
import com.twtw.backend.domain.group.dto.request.JoinGroupRequest;
import com.twtw.backend.domain.group.dto.request.MakeGroupRequest;
import com.twtw.backend.domain.group.dto.response.GroupInfoResponse;
import com.twtw.backend.domain.group.dto.response.GroupResponse;
import com.twtw.backend.domain.group.entity.Group;
import com.twtw.backend.domain.group.entity.GroupMember;
import com.twtw.backend.domain.group.repository.GroupMemberRepository;
import com.twtw.backend.domain.group.repository.GroupRepository;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.fixture.member.MemberEntityFixture;
import com.twtw.backend.support.service.LoginTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@DisplayName("GroupService의")
class GroupServiceTest extends LoginTest {
@Autowired private GroupService groupService;
Expand Down Expand Up @@ -124,11 +124,11 @@ void getMyGroups() {
groupMember1.acceptInvite();
groupMember2.acceptInvite();

Group saveGroup1 = groupRepository.save(group1);
Group saveGroup2 = groupRepository.save(group2);
groupRepository.save(group1);
groupRepository.save(group2);

// when
List<GroupInfoResponse> responses = groupService.getMyGroups();
List<GroupResponse> responses = groupService.getMyGroups();

// then
assertThat(responses).hasSize(2);
Expand Down
Loading

0 comments on commit e3cc308

Please sign in to comment.