-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…d_info [FEAT] 온보딩 부모자식 관계 정보 입력(초대하는 측) API
- Loading branch information
Showing
17 changed files
with
305 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/sopt/org/umbbaServer/domain/parentchild/controller/ParentchildController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package sopt.org.umbbaServer.domain.parentchild.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.OnboardingInviteRequestDto; | ||
import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.OnboardingInviteResponseDto; | ||
import sopt.org.umbbaServer.domain.parentchild.service.ParentchildService; | ||
import sopt.org.umbbaServer.global.common.dto.ApiResponse; | ||
import sopt.org.umbbaServer.global.exception.SuccessType; | ||
|
||
import javax.validation.Valid; | ||
|
||
@RestController | ||
@RequestMapping("/onboard") | ||
@RequiredArgsConstructor | ||
public class ParentchildController { | ||
|
||
private final ParentchildService parentchildService; | ||
|
||
@PostMapping("/invite") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ApiResponse<OnboardingInviteResponseDto> onboardInvite(@Valid @RequestBody OnboardingInviteRequestDto request) { | ||
return ApiResponse.success(SuccessType.CREATE_PARENT_CHILD_SUCCESS, parentchildService.onboardInvite(request)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...org/umbbaServer/domain/parentchild/controller/dto/request/OnboardingInviteRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package sopt.org.umbbaServer.domain.parentchild.controller.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.time.LocalTime; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class OnboardingInviteRequestDto { | ||
|
||
@NotNull | ||
private UserInfoDto userInfo; | ||
|
||
private boolean isInvitorChild; | ||
|
||
private String relationInfo; // 아들 or 딸 | 아빠 or 엄마 | ||
|
||
// TODO 디폴트 값 지정해줘야 할까? -> by 디폴트 생성자 | ||
@JsonFormat(pattern = "kk:mm") | ||
private LocalTime pushTime; | ||
} |
13 changes: 13 additions & 0 deletions
13
...rg/umbbaServer/domain/parentchild/controller/dto/request/OnboardingReceiveRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package sopt.org.umbbaServer.domain.parentchild.controller.dto.request; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class OnboardingReceiveRequestDto { | ||
|
||
private UserInfoDto userInfo; | ||
} |
12 changes: 12 additions & 0 deletions
12
.../umbbaServer/domain/parentchild/controller/dto/response/OnboadringReceiveResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package sopt.org.umbbaServer.domain.parentchild.controller.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class OnboadringReceiveResponseDto { | ||
} |
38 changes: 38 additions & 0 deletions
38
...g/umbbaServer/domain/parentchild/controller/dto/response/OnboardingInviteResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sopt.org.umbbaServer.domain.parentchild.controller.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; | ||
import sopt.org.umbbaServer.domain.user.controller.dto.request.UserInfoDto; | ||
import sopt.org.umbbaServer.domain.user.model.User; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class OnboardingInviteResponseDto { | ||
|
||
private Long parentchildId; | ||
|
||
private UserInfoDto userInfo; | ||
|
||
private String parentchildRelation; | ||
|
||
private LocalTime pushTime; | ||
|
||
private String inviteCode; | ||
|
||
public static OnboardingInviteResponseDto of(Parentchild parentchild, User user) { | ||
return OnboardingInviteResponseDto.builder() | ||
.parentchildId(parentchild.getId()) | ||
.userInfo(UserInfoDto.of(user)) | ||
.parentchildRelation(parentchild.getRelation().getValue()) | ||
.pushTime(parentchild.getPushTime()) | ||
.inviteCode(parentchild.getInviteCode()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/sopt/org/umbbaServer/domain/parentchild/respository/ParentchildRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package sopt.org.umbbaServer.domain.parentchild.respository; | ||
|
||
import org.springframework.data.repository.Repository; | ||
import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ParentchildRepository extends Repository<Parentchild, Long> { | ||
|
||
// CREATE | ||
void save(Parentchild parentchild); | ||
|
||
// READ | ||
Optional<Parentchild> findById(Long id); | ||
|
||
|
||
// UPDATE | ||
|
||
// DELETE | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package sopt.org.umbbaServer.domain.parentchild.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.bytebuddy.utility.RandomString; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.org.umbbaServer.domain.parentchild.controller.dto.request.OnboardingInviteRequestDto; | ||
import sopt.org.umbbaServer.domain.parentchild.controller.dto.response.OnboardingInviteResponseDto; | ||
import sopt.org.umbbaServer.domain.parentchild.model.Parentchild; | ||
import sopt.org.umbbaServer.domain.parentchild.model.ParentchildRelation; | ||
import sopt.org.umbbaServer.domain.parentchild.respository.ParentchildRepository; | ||
import sopt.org.umbbaServer.domain.user.model.User; | ||
import sopt.org.umbbaServer.domain.user.repository.UserRepository; | ||
import sopt.org.umbbaServer.global.exception.CustomException; | ||
import sopt.org.umbbaServer.global.exception.ErrorType; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ParentchildService { | ||
|
||
private final ParentchildRepository parentchildRepository; | ||
private final UserRepository userRepository; | ||
|
||
// [발신] 초대하는 측의 온보딩 정보 입력 | ||
@Transactional | ||
public OnboardingInviteResponseDto onboardInvite(OnboardingInviteRequestDto request) { | ||
|
||
User user = userRepository.findById(request.getUserInfo().getUserId()).orElseThrow( | ||
() -> new CustomException(ErrorType.INVALID_USER) | ||
); | ||
user.updateOnboardingInfo( | ||
request.getUserInfo().getName(), | ||
request.getUserInfo().getGender(), | ||
request.getUserInfo().getBornYear() | ||
); | ||
|
||
Parentchild parentchild = Parentchild.builder() | ||
.inviteCode(generateInviteCode()) | ||
.isInvitorChild(request.isInvitorChild()) | ||
.relation(getRelation(request.getUserInfo().getGender(), request.getRelationInfo(), request.isInvitorChild())) | ||
.pushTime(request.getPushTime()) // TODO 케이스에 따라 없을 수도 있음 | ||
.build(); | ||
parentchildRepository.save(parentchild); | ||
|
||
log.info("userInfo: {}", request.getUserInfo().getBornYear()); | ||
return OnboardingInviteResponseDto.of(parentchild, user); | ||
} | ||
|
||
// [수신] 초대받는 측의 온보딩 정보 입력 | ||
// public OnboadringReceiveResponseDto | ||
|
||
// 부모자식 관계 케이스 분류하기 | ||
private ParentchildRelation getRelation(String gender, String relationInfo, boolean isInvitorChild) { | ||
|
||
// 내가 부모다 | ||
if (!isInvitorChild) { | ||
if (gender.equals("남자")) { // 아빠 | ||
if (relationInfo.equals("아들")) { | ||
return ParentchildRelation.DAD_SON; | ||
} else if (relationInfo.equals("딸")) { | ||
return ParentchildRelation.DAD_DAU; // TODO 클라에서 둘 중 하나의 값만 받도록 처리하니까 else if 구문 빼도 무관 | ||
} | ||
} else if(gender.equals("여자")) { // 엄마 | ||
if (relationInfo.equals("아들")) { | ||
return ParentchildRelation.MOM_SON; | ||
} else if (relationInfo.equals("딸")) { | ||
return ParentchildRelation.DAD_DAU; | ||
} | ||
} | ||
} else { // 내가 자식이다 | ||
if (gender.equals("남자")) { // 아들 | ||
if (relationInfo.equals("아빠")) { | ||
return ParentchildRelation.DAD_SON; | ||
} else if (relationInfo.equals("엄마")) { | ||
return ParentchildRelation.MOM_SON; | ||
} | ||
} else if(gender.equals("여자")) { // 딸 | ||
if (relationInfo.equals("아빠")) { | ||
return ParentchildRelation.DAD_DAU; | ||
} else if (relationInfo.equals("엄마")) { | ||
return ParentchildRelation.MOM_DAU; | ||
} | ||
} | ||
} | ||
|
||
throw new CustomException(ErrorType.INVALID_PARENT_CHILD_RELATION_INFO); | ||
} | ||
|
||
// 초대코드 생성 (형식예시: WUHZ-iGbPX9X) | ||
private String generateInviteCode() { | ||
return RandomStringUtils.randomAlphabetic(4).toUpperCase() + | ||
"-" + RandomStringUtils.randomAlphanumeric(6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/sopt/org/umbbaServer/domain/user/controller/dto/request/UserInfoDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package sopt.org.umbbaServer.domain.user.controller.dto.request; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import sopt.org.umbbaServer.domain.user.model.User; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class UserInfoDto { | ||
|
||
private Long userId; | ||
|
||
@NotBlank(message = "이름은 필수 입력 값입니다.") | ||
private String name; | ||
|
||
@NotBlank(message = "성별은 필수 입력 값입니다.") | ||
private String gender; | ||
|
||
@NotBlank(message = "출생연도는 필수 입력 값입니다.") | ||
private int bornYear; | ||
|
||
public static UserInfoDto of(User user) { | ||
return UserInfoDto.builder() | ||
.userId(user.getId()) | ||
.name(user.getUsername()) | ||
.gender(user.getGender()) | ||
.bornYear(user.getBornYear()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters