Skip to content

Commit

Permalink
Merge pull request #44 from Team-Umbba/fix/#43-change_onboard_dto
Browse files Browse the repository at this point in the history
[FIX] 온보딩 dto 관련 버그 수정
  • Loading branch information
ddongseop authored Jul 15, 2023
2 parents d82436a + a25b8ae commit 4796c6b
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import sopt.org.umbbaServer.domain.qna.model.OnboardingAnswer;
import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalTime;
import java.util.List;
Expand All @@ -34,5 +34,6 @@ public class OnboardingInviteRequestDto {
@JsonFormat(pattern = "kk:mm")
private LocalTime pushTime;

private List<OnboardingAnswer> onboardingAnswerList;
@NotEmpty // TODO 여기서 걸러지게 만들어야함
private List<String> onboardingAnswerList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import sopt.org.umbbaServer.domain.qna.model.OnboardingAnswer;
import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

Expand All @@ -18,12 +17,10 @@
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class OnboardingReceiveRequestDto {

@NonNull
private Long parentChildId;

@NotNull
@Valid
private UserInfoDto userInfo;

private List<OnboardingAnswer> onboardingAnswerList;
@NotEmpty
private List<String> onboardingAnswerList;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sopt.org.umbbaServer.domain.parentchild.controller.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Builder;
Expand All @@ -21,6 +22,7 @@ public class OnboardingInviteResponseDto {

private String parentchildRelation;

@JsonFormat(pattern = "kk:mm")
private LocalTime pushTime;

private String inviteCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sopt.org.umbbaServer.domain.parentchild.controller.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Builder;
Expand All @@ -20,6 +21,7 @@ public class OnboardingReceiveResponseDto {

private InviteResultResponseDto parentchildInfo;

@JsonFormat(pattern = "kk:mm")
private LocalTime pushTime;

public static OnboardingReceiveResponseDto of(Parentchild parentchild, User user, List<User> parentChildUsers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Optional<Parentchild> findByUserId(Long userId) {
.setParameter("id", userId)
.getSingleResult();
return Optional.ofNullable(parentchild);

} catch (NoResultException e) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void changeParentOnboardingAnswerList(List<OnboardingAnswer> onboardingAn
@Column(nullable = false)
private LocalTime pushTime; // default: 오후 11시(클라이언트)

public void initQnA() {
qnaList = new ArrayList<>();
}

public void addQnA(QnA qnA) {
qnaList.add(qnA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
@Transactional(readOnly = true)
public class ParentchildService {

private final ParentchildDao parentchildDao;
private final ParentchildRepository parentchildRepository;
private final UserRepository userRepository;
private final QnADao qnADao;
private final ParentchildDao parentchildDao;

// [발신] 초대하는 측의 온보딩 정보 입력
@Transactional
Expand Down Expand Up @@ -72,9 +71,7 @@ public OnboardingReceiveResponseDto onboardReceive(Long userId, OnboardingReceiv
request.getUserInfo().getBornYear()
);

// TODO 추가 질문 답변 저장
Parentchild parentchild = getParentchildById(request.getParentChildId());

Parentchild parentchild = getParentchildByUserId(userId);
// parentchild.updateInfo();
List<User> parentChildUsers = getParentChildUsers(parentchild);

Expand Down Expand Up @@ -153,7 +150,7 @@ private List<User> getParentChildUsers(Parentchild newMatchRelation) {
log.info("성립된 부모자식: {} X {}, 관계: {}", parentChildUsers.get(0).getUsername(), parentChildUsers.get(1).getUsername(), newMatchRelation.getRelation());

// 부모자식 관계에 대한 예외처리
if (parentChildUsers.isEmpty() || parentChildUsers == null) {
if (parentChildUsers.isEmpty()) {
throw new CustomException(ErrorType.NOT_EXIST_PARENT_CHILD_USER);
}

Expand All @@ -167,18 +164,18 @@ private List<User> getParentChildUsers(Parentchild newMatchRelation) {

}

private Parentchild getParentchildByUserId(Long userId) {

private Parentchild getParentchildById(Long parentchildId) {
return parentchildRepository.findById(parentchildId).orElseThrow(
() -> new CustomException(ErrorType.NOT_EXIST_PARENT_CHILD_RELATION)
return parentchildDao.findByUserId(userId).orElseThrow(
() -> new CustomException(ErrorType.USER_HAVE_NO_PARENTCHILD)
);
}

private User getUserById(Long userId) {
User user = userRepository.findById(userId).orElseThrow(

return userRepository.findById(userId).orElseThrow(
() -> new CustomException(ErrorType.INVALID_USER)
);
return user;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sopt.org.umbbaServer.domain.qna.controller.dto.request;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -8,6 +10,7 @@

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class TodayAnswerRequestDto {

@NotBlank // null, "", " "을 모두 허용하지 X
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public class QnAListResponseDto {

private Long qnaId;
private Integer index;
private String question;
private String topic;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import sopt.org.umbbaServer.global.exception.CustomException;
import sopt.org.umbbaServer.global.exception.ErrorType;

@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum OnboardingAnswer {

YES("응"),
NO("아니"),
SKIP("잘 모르겠어");
SKIP("애매해");

private final String value;

public static OnboardingAnswer of(String value) {
for (OnboardingAnswer answer : OnboardingAnswer.values()) {
if (answer.getValue().equals(value)) {
return answer;
}
}
throw new CustomException(ErrorType.INVALID_ONBOARDING_ANSWER);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sopt.org.umbbaServer.global.exception.CustomException;
import sopt.org.umbbaServer.global.exception.ErrorType;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -89,11 +90,10 @@ public List<QnAListResponseDto> getQnaList(Long userId, Long sectionId) {
return qnaList.stream()
.filter(qna -> Objects.equals(qna.getQuestion().getSection().getSectionId(), sectionId))
.map(qna -> {
String question = myUser.isMeChild() ? qna.getQuestion().getChildQuestion() : qna.getQuestion().getParentQuestion();
return QnAListResponseDto.builder()
.qnaId(qna.getId())
.index(qnaList.indexOf(qna) + 1)
.question(question)
.topic(qna.getQuestion().getTopic())
.build();
})
.collect(Collectors.toList());
Expand All @@ -110,10 +110,15 @@ public SingleQnAResponseDto getSingleQna(Long userId, Long qnaId) {
}

@Transactional
public void filterFirstQuestion(Long userId, List<OnboardingAnswer> onboardingAnswerList) {
public void filterFirstQuestion(Long userId, List<String> onboardingAnswerStringList) {

Parentchild parentchild = getParentchildByUserId(userId);

// String을 Enum으로 변경
List<OnboardingAnswer> onboardingAnswerList = onboardingAnswerStringList.stream()
.map(OnboardingAnswer::of)
.collect(Collectors.toList());

if (getUserById(userId).isMeChild()) {
parentchild.changeChildOnboardingAnswerList(onboardingAnswerList);
} else {
Expand All @@ -128,14 +133,20 @@ public void filterFirstQuestion(Long userId, List<OnboardingAnswer> onboardingAn
.build();
qnARepository.save(newQnA);

parentchild.initQnA();
parentchild.addQnA(newQnA);
}

@Transactional
public void filterAllQuestion(Long userId, List<OnboardingAnswer> onboardingAnswerList) {
public void filterAllQuestion(Long userId, List<String> onboardingAnswerStringList) {

Parentchild parentchild = getParentchildByUserId(userId);

// String을 Enum으로 변경
List<OnboardingAnswer> onboardingAnswerList = onboardingAnswerStringList.stream()
.map(OnboardingAnswer::of)
.collect(Collectors.toList());

if (getUserById(userId).isMeChild()) {
parentchild.changeChildOnboardingAnswerList(onboardingAnswerList);
} else {
Expand All @@ -145,7 +156,9 @@ public void filterAllQuestion(Long userId, List<OnboardingAnswer> onboardingAnsw
List<OnboardingAnswer> childList = parentchild.getChildOnboardingAnswerList();
List<OnboardingAnswer> parentList = parentchild.getParentOnboardingAnswerList();

// 질문 그룹을 선택
QuestionGroup selectedGroup = selectGroup(childList, parentList);
System.out.println("선택된 그룹: " + selectedGroup);

for (QuestionSection section : QuestionSection.values()) {
if (section == YOUNG) continue;
Expand Down Expand Up @@ -182,8 +195,10 @@ private Parentchild getParentchildByUser(User user) {
}

private Parentchild getParentchildByUserId(Long userId) {
return parentchildDao.findByUserId(userId)
.orElseThrow(() -> new CustomException(ErrorType.USER_HAVE_NO_PARENTCHILD));

return parentchildDao.findByUserId(userId).orElseThrow(
() -> new CustomException(ErrorType.USER_HAVE_NO_PARENTCHILD)
);
}

private List<QnA> getQnAListByParentchild(Parentchild parentchild) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package sopt.org.umbbaServer.domain.user.controller.dto.request;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class RefreshRequestDto {

private Long userId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package sopt.org.umbbaServer.domain.user.controller.dto.request;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import sopt.org.umbbaServer.domain.user.social.SocialPlatform;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class SocialLoginRequestDto {

private SocialPlatform socialPlatform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private boolean isUserBySocialAndSocialId(SocialPlatform socialPlatform, String
return userRepository.existsBySocialPlatformAndSocialId(socialPlatform, socialId);
}

private String login(SocialPlatform socialPlatform, String socialAccessToken) throws NoSuchAlgorithmException, InvalidKeySpecException {
private String login(SocialPlatform socialPlatform, String socialAccessToken) {

try {
switch (socialPlatform.toString()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ErrorType {
HEADER_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청에 필요한 헤더값이 존재하지 않습니다."),
VALIDATION_WRONG_ENUM_EXCEPTION(HttpStatus.BAD_REQUEST, "허용되지 않는 문자열이 입력되었습니다."),
INVALID_SOCIAL_PLATFORM(HttpStatus.BAD_REQUEST, "유효하지 않은 소셜 플랫폼입니다."),
INVALID_ONBOARDING_ANSWER(HttpStatus.BAD_REQUEST, "유효하지 않은 선택질문 응답값입니다."),

// ParentChild - Onboarding
INVALID_PARENT_CHILD_RELATION_INFO(HttpStatus.BAD_REQUEST, "부모자식 관계를 정의할 수 없는 요청값입니다."),
Expand Down

0 comments on commit 4796c6b

Please sign in to comment.