Skip to content

Commit

Permalink
Merge pull request #213 from bankidz/feature/optIn
Browse files Browse the repository at this point in the history
feat: 알림 동의 여부 조회 API
  • Loading branch information
ozzing authored Sep 9, 2022
2 parents f0f6575 + 2f8bf5a commit 95517dc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(SwaggerPatterns).permitAll()
.antMatchers("/kakao/login").permitAll()
.antMatchers("/apple/login").permitAll()
.antMatchers("/apple/revoke").permitAll()
.antMatchers("/user/refresh").permitAll()
.anyRequest().authenticated()
.and()
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/ceos/bankids/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,24 @@ public CommonResponse<OptInDTO> patchNoticeOptIn(@AuthenticationPrincipal User a
}

@ApiOperation(value = "가족 활동 알림 동의")
@PatchMapping(value = "/action", produces = "application/json; charset=utf-8")
@PatchMapping(value = "/service", produces = "application/json; charset=utf-8")
@ResponseBody
public CommonResponse<OptInDTO> patchActionOptIn(@AuthenticationPrincipal User authUser) {
public CommonResponse<OptInDTO> patchServiceOptIn(@AuthenticationPrincipal User authUser) {

log.info("api = 가족 활동 알림 동의, user = {}", authUser.getUsername());
OptInDTO optInDTO = userService.updateServiceOptIn(authUser);

return CommonResponse.onSuccess(optInDTO);
}

@ApiOperation(value = "유저 알림 동의 조회")
@GetMapping(value = "/opt-in", produces = "application/json; charset=utf-8")
@ResponseBody
public CommonResponse<OptInDTO> getOptIn(@AuthenticationPrincipal User authUser) {

log.info("api = 유저 알림 동의 조회, user = {}", authUser.getUsername());
OptInDTO optInDTO = userService.getOptIn(authUser);

return CommonResponse.onSuccess(optInDTO);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/ceos/bankids/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public LoginDTO loginWithAppleAuthenticationCode(String authenticationCode,
public OptInDTO updateNoticeOptIn(User user);

public OptInDTO updateServiceOptIn(User user);

public OptInDTO getOptIn(User user);
}
6 changes: 6 additions & 0 deletions src/main/java/com/ceos/bankids/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,10 @@ public OptInDTO updateServiceOptIn(User user) {

return new OptInDTO(user);
}

@Override
@Transactional
public OptInDTO getOptIn(User user) {
return new OptInDTO(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ public void testIfUserPatchNoticeOptInSucceedThenReturnResult() {

@Test
@DisplayName("유저 가족 활동 알림 동의 시, 결과 반환하는지 확인")
public void testIfUserPatchActionOptInSucceedThenReturnResult() {
public void testIfUserPatchServiceOptInSucceedThenReturnResult() {
// given
User user = User.builder()
.id(1L)
Expand Down Expand Up @@ -1591,7 +1591,7 @@ public void testIfUserPatchActionOptInSucceedThenReturnResult() {
notificationService
);

CommonResponse<OptInDTO> result = userController.patchActionOptIn(user);
CommonResponse<OptInDTO> result = userController.patchServiceOptIn(user);

user.setServiceOptIn(true);
OptInDTO optInDTO = new OptInDTO(user);
Expand Down Expand Up @@ -1669,7 +1669,7 @@ public void testIfUserPatchNoticeOptOutSucceedThenReturnResult() {

@Test
@DisplayName("유저 가족 활동 알림 비동의 시, 결과 반환하는지 확인")
public void testIfUserPatchActionOptOutSucceedThenReturnResult() {
public void testIfUserPatchServiceOptOutSucceedThenReturnResult() {
// given
User user = User.builder()
.id(1L)
Expand Down Expand Up @@ -1717,7 +1717,7 @@ public void testIfUserPatchActionOptOutSucceedThenReturnResult() {
notificationService
);

CommonResponse<OptInDTO> result = userController.patchActionOptIn(user);
CommonResponse<OptInDTO> result = userController.patchServiceOptIn(user);

user.setServiceOptIn(false);
OptInDTO optInDTO = new OptInDTO(user);
Expand Down Expand Up @@ -1784,4 +1784,60 @@ public void testIfUserTypePatchFailWithInvalidBirthdayThrowBadRequestException()
userController.patchUserType(user, userTypeRequest);
});
}

@Test
@DisplayName("유저 푸시 알림 동의 여부 조회 시, 결과 반환하는지 확인")
public void testIfGetUserOptInSucceedThenReturnResult() {
// given
User user = User.builder()
.id(1L)
.username("user1")
.isFemale(true)
.authenticationCode("code")
.provider("kakao")
.isKid(true)
.refreshToken("token")
.expoToken("ExponentPushToken[dd]")
.noticeOptIn(false)
.serviceOptIn(true)
.build();

UserRepository mockUserRepository = Mockito.mock(UserRepository.class);
KidRepository mockKidRepository = Mockito.mock(KidRepository.class);
ParentRepository mockParentRepository = Mockito.mock(ParentRepository.class);
JwtTokenServiceImpl jwtTokenServiceImpl = Mockito.mock(JwtTokenServiceImpl.class);

// when
UserServiceImpl userService = new UserServiceImpl(
mockUserRepository,
mockKidRepository,
mockParentRepository,
jwtTokenServiceImpl
);
FamilyServiceImpl familyService = null;
ChallengeServiceImpl challengeService = null;
KidBackupServiceImpl kidBackupService = null;
ParentBackupServiceImpl parentBackupService = null;
KidServiceImpl kidService = null;
ParentServiceImpl parentService = null;
SlackServiceImpl slackService = null;
ExpoNotificationServiceImpl notificationService = null;

UserController userController = new UserController(
userService,
familyService,
challengeService,
kidBackupService,
parentBackupService,
kidService,
parentService,
slackService,
notificationService
);

CommonResponse<OptInDTO> result = userController.getOptIn(user);

// then
Assertions.assertEquals(CommonResponse.onSuccess(new OptInDTO(user)), result);
}
}

0 comments on commit 95517dc

Please sign in to comment.