-
Notifications
You must be signed in to change notification settings - Fork 1
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
[FEAT] 마이페이지 API 구현 #124
[FEAT] 마이페이지 API 구현 #124
Changes from 7 commits
d2cd9c9
72c97db
c46bf1a
932178d
94d61ce
7de77b0
7c05eee
02b85b7
924d3ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ public class SecurityConfig { | |
|
||
private static final String[] AUTH_WHITELIST = { | ||
"/kakao/**", "/login", "/reissue", | ||
"/qna/**", "onboard/**", "/home", "/dummy", | ||
"/qna/**", "onboard/**", "/home", "/dummy", "/user/me", | ||
// "/log-out", | ||
"/test", "/profile", "/health", "/actuator/health", | ||
"/alarm/qna", "/alarm/drink", | ||
Comment on lines
23
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생각해보니까 인증이 필요 없는 API들만 여기 추가되어야하는건데, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 맞아요 ,,ㅋㅋㅋㅋ 좋습니당 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package sopt.org.umbba.api.controller.qna.dto.response; | ||
|
||
import static sopt.org.umbba.domain.domain.parentchild.ParentchildRelation.*; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import sopt.org.umbba.domain.domain.parentchild.Parentchild; | ||
import sopt.org.umbba.domain.domain.parentchild.ParentchildRelation; | ||
import sopt.org.umbba.domain.domain.qna.QnA; | ||
import sopt.org.umbba.domain.domain.user.User; | ||
|
||
@Getter | ||
@Builder | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public class MyUserInfoResponseDto { | ||
|
||
private String myUsername; | ||
private String myUserType; | ||
private String opponentUsername; | ||
private String opponentUserType; | ||
|
||
private String parentchildRelation; | ||
private Boolean isMeChild; | ||
|
||
private String section; | ||
private Long matchedDate; | ||
private Integer qnaCnt; | ||
|
||
public static MyUserInfoResponseDto of(User myUser, User opponentUser, Parentchild parentchild, QnA qnA, long date, int qnaCnt) { | ||
|
||
return MyUserInfoResponseDto.builder() | ||
.myUsername(myUser.getUsername()) | ||
.myUserType(getUserType(parentchild.getRelation(), myUser.isMeChild())) | ||
.opponentUsername(opponentUser.getUsername()) | ||
.opponentUserType(getUserType(parentchild.getRelation(), opponentUser.isMeChild())) | ||
.parentchildRelation(parentchild.getRelation().getValue()) | ||
.isMeChild(myUser.isMeChild()) | ||
.section(qnA.getQuestion().getSection().getValue()) | ||
.matchedDate(date) // 일수와 문답 수는 다를 수 있음 | ||
.qnaCnt(qnaCnt).build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요건 무슨 용도의 파일인가요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어엇 잘못 들어간 파일 같네요 삭제하겠습니다 !! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import sopt.org.umbba.api.controller.qna.dto.response.MyUserInfoResponseDto; | ||
import sopt.org.umbba.api.controller.qna.dto.request.TodayAnswerRequestDto; | ||
import sopt.org.umbba.api.controller.qna.dto.response.*; | ||
import sopt.org.umbba.api.service.notification.NotificationService; | ||
|
@@ -19,6 +21,12 @@ | |
import sopt.org.umbba.domain.domain.user.repository.UserRepository; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -200,6 +208,35 @@ public void filterAllQuestion(Long userId) { | |
} | ||
} | ||
|
||
// 마이페이지 - 부모자식 관계 정보 조회 | ||
public MyUserInfoResponseDto getUserInfo(final Long userId) { | ||
|
||
User myUser = getUserById(userId); | ||
Parentchild parentchild = getParentchildByUser(myUser); | ||
User opponentUser = getOpponentByParentchild(parentchild, userId); | ||
// TODO 상대 미연결인 부분에 대한 반환값 추가 예정 | ||
/*List<User> opponentUserList = userRepository.findUserByParentChild(parentchild) | ||
.stream() | ||
.filter(user -> !user.getId().equals(userId)) | ||
.collect(Collectors.toList()); | ||
|
||
if (opponentUserList.isEmpty()) { | ||
return MyUserInfoResponseDto.of(myUser, opponentUser, parentchild, todayQnA, 0, 0); | ||
}*/ | ||
|
||
QnA todayQnA = getTodayQnAByParentchild(parentchild); | ||
List<QnA> qnaList = getQnAListByParentchild(parentchild); | ||
|
||
long qnaCnt = qnaList.stream() | ||
.filter(qnA -> qnA.isChildAnswer() && qnA.isParentAnswer()) | ||
.count(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DB 수정 완료해서 getCount만으로 처리해도 될것같습니다! |
||
|
||
LocalDateTime firstQnADate = parentchild.getQnaList().get(0).getCreatedAt(); | ||
long qnaDate = ChronoUnit.DAYS.between(firstQnADate, LocalDateTime.now()); | ||
|
||
return MyUserInfoResponseDto.of(myUser, opponentUser, parentchild, todayQnA, qnaDate, (int)qnaCnt); | ||
} | ||
|
||
/* | ||
리팩토링을 위해 아래로 뺀 메서드들 | ||
*/ | ||
|
@@ -227,7 +264,7 @@ private List<QnA> getQnAListByParentchild(Parentchild parentchild) { | |
return qnaList; | ||
} | ||
|
||
private QnA getTodayQnAByParentchild(Parentchild parentchild) { | ||
protected QnA getTodayQnAByParentchild(Parentchild parentchild) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 흠흠 이게 긴 사연이 있는데요!! 일단 잘못 들어간 게 맞구요 ㅎㅎ 바꾸게 된 과정에 대해 설명을 드려보자면,
|
||
List<QnA> qnaList = parentchild.getQnaList(); | ||
if (qnaList == null || qnaList.isEmpty()) { | ||
throw new CustomException(ErrorType.PARENTCHILD_HAVE_NO_QNALIST); | ||
|
@@ -305,10 +342,6 @@ else if (childList.get(3) != YES || parentList.get(3) != YES) { | |
} | ||
|
||
|
||
/* | ||
리팩토링을 위해 아래로 뺀 메서드들 끝 | ||
*/ | ||
|
||
// 메인페이지 정보 | ||
public GetMainViewResponseDto getMainInfo(Long userId) { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,17 @@ public static ParentchildRelation relation(String gender, String relationInfo, b | |
throw new CustomException(ErrorType.INVALID_PARENT_CHILD_RELATION_INFO); | ||
} | ||
|
||
// 아들 | 딸 | 엄마 | 아빠 구분 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아주 좋습니당! |
||
public static String getUserType(ParentchildRelation relation, boolean isChild) { | ||
if (relation.childGender.equals("여자")) { | ||
if (isChild) return "딸"; | ||
else return "엄마"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p5; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 의견 감사합니다 !!! |
||
} else { | ||
if (isChild) return "아들"; | ||
else return "아빠"; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지금 예시로 있는 DB가 딱 그런 케이슨데요 (어쩌다보니) 암튼 그래서 지금 DB에 엄마-아들 관계로 되어 있음 + 둘다 성별은 남자임 이런 상태인데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네넵 그럼 User의 gender 필드 기준이 아닌, relation에 저장된 값과 isChild 기준으로 반환하는 로직으로 수정하겠습니다!! |
||
|
||
|
||
// 자식 유저와 부모 유저의 gender와 isMeChild 필드를 통해 ParentchildRelation을 구분하는 로직 | ||
public static boolean validate(List<User> parentChildUsers, ParentchildRelation relation) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
포스트맨이 아니라 IntelliJ의 .http 테스트 활용하신건가요!
신기해서 저도 찾아봤습니당
https://ksh-coding.tistory.com/97