Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 가족 조회하기 API 리스폰스 수정 #246

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/main/java/com/ceos/bankids/mapper/FamilyMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -54,14 +55,19 @@ public FamilyDTO createFamily(User user) {

@Transactional(readOnly = true)
public FamilyDTO readFamily(User user) {
FamilyUser familyUser = familyUserService.findByUser(user);
Family family = familyUser.getFamily();
List<FamilyUser> familyUserList = familyUserService.getFamilyUserListExclude(family,
user);
Optional<FamilyUser> familyUser = familyUserService.findByUserNullable(user);

return new FamilyDTO(family, familyUserList.stream()
.map(FamilyUserDTO::new)
.collect(Collectors.toList()));
if (familyUser.isEmpty()) {
return new FamilyDTO(new Family(), List.of());
} else {
Family family = familyUser.get().getFamily();
List<FamilyUser> familyUserList = familyUserService.getFamilyUserListExclude(family,
user);

return new FamilyDTO(family, familyUserList.stream()
.map(FamilyUserDTO::new)
.collect(Collectors.toList()));
}
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.ceos.bankids.repository.ProgressRepository;
import com.ceos.bankids.repository.TargetItemRepository;
import com.ceos.bankids.service.ChallengeServiceImpl;
import com.ceos.bankids.service.FamilyServiceImpl;
import java.util.Optional;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -112,9 +111,7 @@ public void testIfPostChallengeReqSuccessResponse() {
mockProgressRepository,
mockCommentRepository
);
FamilyServiceImpl familyService = new FamilyServiceImpl()


// FamilyServiceImpl familyService = new FamilyServiceImpl()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ public void testIfFamilyExistThenReturnGetResult() {
}

@Test
@DisplayName("조회 시 기존 가족 있으나, 삭제되었을 때 에러 처리 하는지 확인")
public void testIfFamilyExistedButDeletedWhenGetThenThrowBadRequestException() {
@DisplayName("조회 시 기존 가족 없을 때, 빈 가족 정보 리턴 하는지 확인")
public void testIfFamilyNotExistThenReturnResult() {
// given
User user1 = User.builder()
.id(1L)
Expand Down Expand Up @@ -393,10 +393,13 @@ public void testIfFamilyExistedButDeletedWhenGetThenThrowBadRequestException() {
);
FamilyController familyController = new FamilyController(familyMapper);

CommonResponse<FamilyDTO> result = familyController.getFamily(user1);

// then
Assertions.assertThrows(BadRequestException.class, () -> {
familyController.getFamily(user1);
});
FamilyDTO familyDTO = FamilyDTO.builder()
.family(new Family())
.familyUserList(List.of()).build();
Assertions.assertEquals(CommonResponse.onSuccess(familyDTO), result);
}

@Test
Expand Down