Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feat/#67-demoday_test
  • Loading branch information
jun02160 committed Jul 21, 2023
2 parents d463542 + 3702322 commit f8581b1
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 89 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<img src="https://user-images.githubusercontent.com/80024278/254717698-0849c495-c344-4cd2-a369-8b5def6c1154.jpg" width="750"/>
<br/>


## 🌸 금쪽이들
| 이동섭 | 박예준 |
| :----------------------------------------------------------: |:----------------------------------------------------------------------------------------------------------------------------------:|
Expand All @@ -17,7 +18,7 @@
| Nginx 배포, CI/CD 구축 | 이동섭 |
| DB 구축 (RDS) | 이동섭 |
| ERD 작성 | 이동섭, 박예준 |
| API 구현 | 이동섭, 박예준 |
| API 개발 | 이동섭, 박예준 |
| 소셜로그인 기능 구현 | 이동섭 |
| 푸시알림 기능 구현 | 박예준 |

Expand Down Expand Up @@ -49,12 +50,12 @@

## 📜 API Docs

### 🔗 [API Docs](https://harsh-step-7dd.notion.site/9e5e7a93f4904a0795b15d54f79d9bae?v=c252004af7b248c1bf408fedd45ebb37&pvs=4)
### 🔗 [API Docs](https://harsh-step-7dd.notion.site/API-887ec56c3fdd48e19fec44820b63a83d?pvs=4)

<hr>

## ☁️ ERD
<img width="600" src="https://github.com/Team-Umbba/Umbba-Server/assets/67463603/d7230c16-016f-4119-b5cd-595053a55a5c">
<img width="600" src="https://user-images.githubusercontent.com/80024278/254723343-d27666c0-1a4d-4e0e-a4cf-ea79dcd08c08.png">

<hr>

Expand All @@ -64,19 +65,19 @@
🗂 main
🗂 java/sopt/org/umbbaServer
🗂 domain
🗂 parentchild
📁 parentchild
🗂 controller
🗂 dao
🗂 model
🗂 repository
🗂 service
🗂 qna
📁 qna
🗂 controller
🗂 dao
🗂 model
🗂 repository
🗂 service
🗂 user
📁 user
🗂 controller
🗂 model
🗂 repository
Expand All @@ -85,15 +86,15 @@
🗂 apple
🗂 kakao
🗂 global
🗂 common
📁 common
🗂 advice
🗂 dto
🗂 config
📁 config
🗂 auth
🗂 jwt
🗂 redis
🗂 exception
🗂 util
📁 util
🗂 slack
🗂 resources
application.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ public ApiResponse<OnboardingInviteResponseDto> onboardInvite(@RequestBody @Vali

Long userId = JwtProvider.getUserFromPrincial(principal);
OnboardingInviteResponseDto response = parentchildService.onboardInvite(userId, request);
qnAService.filterFirstQuestion(userId, request.getOnboardingAnswerList());
qnAService.filterFirstQuestion(userId);

return ApiResponse.success(SuccessType.CREATE_PARENT_CHILD_SUCCESS, response);
}

@PatchMapping("/onboard/match")
@ResponseStatus(HttpStatus.OK)
@ResponseStatus(HttpStatus.CREATED)
public ApiResponse<InviteResultResponseDto> inviteRelation(@RequestBody @Valid final InviteCodeRequestDto request, Principal principal) {
return ApiResponse.success(SuccessType.MATCH_PARENT_CHILD_SUCCESS, parentchildService.matchRelation(JwtProvider.getUserFromPrincial(principal), request));
}

@PatchMapping("/onboard/receive")
@ResponseStatus(HttpStatus.OK)
@ResponseStatus(HttpStatus.CREATED)
public ApiResponse<OnboardingReceiveResponseDto> onboardReceive(@RequestBody @Valid final OnboardingReceiveRequestDto request, Principal principal) throws InterruptedException {

Long userId = JwtProvider.getUserFromPrincial(principal);
OnboardingReceiveResponseDto response = parentchildService.onboardReceive(userId, request);
qnAService.filterAllQuestion(userId, request.getOnboardingAnswerList());
qnAService.filterAllQuestion(userId);

return ApiResponse.success(SuccessType.CREATE_PARENT_CHILD_SUCCESS, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public class OnboardingInviteRequestDto {
@JsonFormat(pattern = "kk:mm")
private LocalTime pushTime;

@NotEmpty // TODO 여기서 걸러지게 만들어야함
@NotEmpty
private List<String> onboardingAnswerList;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sopt.org.umbbaServer.domain.parentchild.controller.dto.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Builder;
Expand All @@ -14,12 +16,25 @@
@Getter
@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class InviteResultResponseDto {

private Long parentchildId;

private Boolean isMatchFinish;

private List<UserInfoDto> parentchildUsers;
private String parentchildRelation;

public static InviteResultResponseDto of(boolean isMatchFinish, Parentchild parentchild, List<User> parentChildUsers) {
return InviteResultResponseDto.builder()
.parentchildId(parentchild.getId())
.isMatchFinish(isMatchFinish)
.parentchildUsers(parentChildUsers.stream().map(u -> UserInfoDto.of(u)).collect(Collectors.toList()))
.parentchildRelation(parentchild.getRelation().getValue())
.build();
}

public static InviteResultResponseDto of(Parentchild parentchild, List<User> parentChildUsers) {
return InviteResultResponseDto.builder()
.parentchildId(parentchild.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static ParentchildRelation relation(String gender, String relationInfo, b
if (relationInfo.equals("아들")) {
return ParentchildRelation.DAD_SON;
} else if (relationInfo.equals("딸")) {
return ParentchildRelation.DAD_DAU; // TODO 클라에서 둘 중 하나의 값만 받도록 처리하니까 else if 구문 빼도 무관
return ParentchildRelation.DAD_DAU;
}
} else if(gender.equals("여자")) { // 엄마
if (relationInfo.equals("아들")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sopt.org.umbbaServer.domain.parentchild.model.Parentchild;
import sopt.org.umbbaServer.domain.parentchild.model.ParentchildRelation;
import sopt.org.umbbaServer.domain.parentchild.repository.ParentchildRepository;
import sopt.org.umbbaServer.domain.qna.model.OnboardingAnswer;
import sopt.org.umbbaServer.domain.user.model.User;
import sopt.org.umbbaServer.domain.user.repository.UserRepository;
import sopt.org.umbbaServer.global.config.ScheduleConfig;
Expand All @@ -24,6 +25,7 @@
import sopt.org.umbbaServer.global.util.fcm.FCMService;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
Expand Down Expand Up @@ -55,44 +57,78 @@ public OnboardingInviteResponseDto onboardInvite(Long userId, OnboardingInviteRe
.inviteCode(generateInviteCode())
.isInvitorChild(request.getIsInvitorChild())
.relation(ParentchildRelation.relation(request.getUserInfo().getGender(), request.getRelationInfo(), request.getIsInvitorChild()))
.pushTime(request.getPushTime()) // TODO 케이스에 따라 없을 수도 있음
.pushTime(request.getPushTime())
.count(1)
.build();
parentchildRepository.save(parentchild);
user.updateParentchild(parentchild);
user.updateIsMatchFinish(true);
log.info("userInfo: {}", request.getUserInfo().getBornYear());

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

if (onboardingAnswerList.size() != 5) {
throw new CustomException(ErrorType.INVALID_ONBOARDING_ANSWER_SIZE);
}

if (getUserById(userId).isMeChild()) {
parentchild.changeChildOnboardingAnswerList(onboardingAnswerList);
} else {
parentchild.changeParentOnboardingAnswerList(onboardingAnswerList);
}

return OnboardingInviteResponseDto.of(parentchild, user);

}


// [수신] 초대받는 측의 온보딩 정보 입력
@Transactional
public OnboardingReceiveResponseDto onboardReceive(Long userId, OnboardingReceiveRequestDto request) throws InterruptedException {

if (getParentchildByUserId(userId) != null) {

User user = getUserById(userId);
user.updateOnboardingInfo(
request.getUserInfo().getName(),
request.getUserInfo().getGender(),
request.getUserInfo().getBornYear()
);
if (getUserById(userId).getParentChild() == null) {
throw new CustomException(ErrorType.RECEIVE_AFTER_MATCH);
}

Parentchild parentchild = getParentchildByUserId(userId);
User user = getUserById(userId);
user.updateOnboardingInfo(
request.getUserInfo().getName(),
request.getUserInfo().getGender(),
request.getUserInfo().getBornYear()
);

Parentchild parentchild = user.getParentChild();
// parentchild.updateInfo(); TODO 온보딩 송수신 측의 관계 정보가 불일치한 경우에 대한 처리
List<User> parentChildUsers = getParentChildUsers(parentchild);
List<User> parentChildUsers = getParentChildUsers(parentchild);

/*if (!ParentchildRelation.validate(parentChildUsers, parentchild.getRelation())) {
throw new CustomException(ErrorType.INVALID_PARENT_CHILD_RELATION);
}*/
ScheduleConfig.resetScheduler();
fcmScheduler.pushTodayQna();
// String을 Enum으로 변경
List<OnboardingAnswer> onboardingAnswerList = request.getOnboardingAnswerList().stream()
.map(OnboardingAnswer::of)
.collect(Collectors.toList());

if (onboardingAnswerList.size() != 5) {
throw new CustomException(ErrorType.INVALID_ONBOARDING_ANSWER_SIZE);
}

return OnboardingReceiveResponseDto.of(parentchild, user, parentChildUsers);
if (getUserById(userId).isMeChild()) {
parentchild.changeChildOnboardingAnswerList(onboardingAnswerList);
} else {
parentchild.changeParentOnboardingAnswerList(onboardingAnswerList);
}

throw new CustomException(ErrorType.RECEIVE_AFTER_MATCH);
/*if (!ParentchildRelation.validate(parentChildUsers, parentchild.getRelation())) {
throw new CustomException(ErrorType.INVALID_PARENT_CHILD_RELATION);
}*/
ScheduleConfig.resetScheduler();
fcmScheduler.pushTodayQna();


return OnboardingReceiveResponseDto.of(parentchild, user, parentChildUsers);

}


Expand All @@ -116,8 +152,7 @@ public InviteResultResponseDto matchRelation(Long userId, InviteCodeRequestDto r
throw new CustomException(ErrorType.ALREADY_EXISTS_PARENT_CHILD_USER);
}

// TODO ParentChild에 연관된 User 수에 따른 예외처리
// TODO 하나의 유저는 하나의 관계만 가지도록 예외처리
// TODO ParentChild에 연관된 User 수에 따른 예외 메시지 출력
user.updateParentchild(newMatchRelation);
user.updateIsMatchFinish(true);
log.info("로그인한 유저가 성립된 Parentchild Id: {}", user.getParentChild().getId());
Expand All @@ -127,21 +162,14 @@ public InviteResultResponseDto matchRelation(Long userId, InviteCodeRequestDto r
throw new CustomException(ErrorType.INVALID_PARENT_CHILD_RELATION);
}

return InviteResultResponseDto.of(newMatchRelation, parentChildUsers);
return InviteResultResponseDto.of(user.isMatchFinish(), newMatchRelation, parentChildUsers);
}

public List<User> getParentChildUsers(Parentchild newMatchRelation) {
return userRepository.findUserByParentChild(newMatchRelation);
}


private Parentchild getParentchildByUserId(Long userId) {

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

private User getUserById(Long userId) {

return userRepository.findById(userId).orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public enum QuestionSection {
GOLDEN(3L, "청춘시절", 2),
COUPLE(4L, "연애시절", 1),
MARRIAGE(5L, "우리가 만나고", 1),
MARRIAGE2(6L, "우리가 만나고", 1); // 전연령 - 우리가 만나고
MARRIAGE2(5L, "우리가 만나고", 1); // 전연령 - 우리가 만나고
;

private final Long sectionId;
private final Long sectionId; //findBySectionId 하면 안됨
private final String value;
private final int questionCount;
}
Loading

0 comments on commit f8581b1

Please sign in to comment.