Skip to content

Commit

Permalink
[FEAT] 마이페이지 API 구현 #117
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 committed Feb 7, 2024
1 parent 199abde commit d2cd9c9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sopt.org.umbba.api.controller.qna;

import static sopt.org.umbba.api.config.jwt.JwtProvider.*;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -84,4 +86,10 @@ public ApiResponse<GetInvitationResponseDto> invitation(Principal principal) {
return ApiResponse.success(SuccessType.GET_INVITE_CODE_SUCCESS, qnAService.getInvitation(JwtProvider.getUserFromPrincial(principal)));
}

@GetMapping("/user/me")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<MyUserInfoResponseDto> getMyUserInfo(Principal principal) {
return ApiResponse.success(SuccessType.GET_MY_USER_INFO_SUCCESS, qnAService.getUserInfo(getUserFromPrincial(principal)));
}

}
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 Integer qnaDate;
private Integer qnaCnt;

public static MyUserInfoResponseDto of(User myUser, User opponentUser, Parentchild parentchild, QnA qnA, 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())
.qnaDate(parentchild.getCount()) // 일수와 문답 수는 다를 수 있음
.qnaCnt(qnaCnt).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sopt.org.umbba.api.config.sqs.producer.SqsProducer;

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;
Expand Down Expand Up @@ -204,6 +205,22 @@ public void filterAllQuestion(Long userId) {
}
}

// 마이페이지 - 부모자식 관계 정보 조회
public MyUserInfoResponseDto getUserInfo(final Long userId) {

User myUser = getUserById(userId);
Parentchild parentchild = getParentchildByUser(myUser);
QnA todayQnA = getTodayQnAByParentchild(parentchild);
User opponentUser = getOpponentByParentchild(parentchild, userId);

int qnaCnt = parentchild.getCount();
if (!todayQnA.isChildAnswer() || !todayQnA.isParentAnswer()) {
qnaCnt -= 1;
}

return MyUserInfoResponseDto.of(myUser, opponentUser, parentchild, todayQnA, qnaCnt);
}

/*
리팩토링을 위해 아래로 뺀 메서드들
*/
Expand Down Expand Up @@ -231,7 +248,7 @@ private List<QnA> getQnAListByParentchild(Parentchild parentchild) {
return qnaList;
}

private QnA getTodayQnAByParentchild(Parentchild parentchild) {
protected QnA getTodayQnAByParentchild(Parentchild parentchild) {
List<QnA> qnaList = parentchild.getQnaList();
if (qnaList == null || qnaList.isEmpty()) {
throw new CustomException(ErrorType.PARENTCHILD_HAVE_NO_QNALIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum SuccessType {
PUSH_ALARM_SUCCESS(HttpStatus.OK, "푸시알림 전송에 성공했습니다."),
PUSH_ALARM_PERIODIC_SUCCESS(HttpStatus.OK, "오늘의 질문 푸시알림 활성에 성공했습니다."),
REMIND_QUESTION_SUCCESS(HttpStatus.OK, "상대방에게 질문을 리마인드 하는 데 성공했습니다."),
GET_MY_USER_INFO_SUCCESS(HttpStatus.OK, "마이페이지 내 정보 조회에 성공했습니다."),
TEST_SUCCESS(HttpStatus.OK, "데모데이 테스트용 API 호출에 성공했습니다."),


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public static ParentchildRelation relation(String gender, String relationInfo, b
throw new CustomException(ErrorType.INVALID_PARENT_CHILD_RELATION_INFO);
}

// 아들 | 딸 | 엄마 | 아빠 구분
public static String getUserType(ParentchildRelation relation, boolean isChild) {
if (relation.childGender.equals("여자")) {
if (isChild) return "딸";
else return "엄마";
} else {
if (isChild) return "아들";
else return "아빠";
}
}


// 자식 유저와 부모 유저의 gender와 isMeChild 필드를 통해 ParentchildRelation을 구분하는 로직
public static boolean validate(List<User> parentChildUsers, ParentchildRelation relation) {
Expand Down

0 comments on commit d2cd9c9

Please sign in to comment.