-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] #39 계정 정보 조회 API 구현 #50
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
Open
yukyoungs
wants to merge
2
commits into
develop
Choose a base branch
from
feat/#39
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/com/leets7th/job_is_be/domain/user/controller/AccountController.java
This file contains hidden or 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 com.leets7th.job_is_be.domain.user.controller; | ||
|
|
||
| import com.leets7th.job_is_be.domain.user.dto.AccountResponse; | ||
| import com.leets7th.job_is_be.domain.user.service.AccountService; | ||
| import com.leets7th.job_is_be.global.response.ApiResponse; | ||
| import com.leets7th.job_is_be.global.status.SuccessStatus; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.security.oauth2.jwt.Jwt; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/settings/account") | ||
| @RequiredArgsConstructor | ||
| public class AccountController { | ||
|
|
||
| private final AccountService accountService; | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<ApiResponse<AccountResponse>> getAccount( | ||
| @AuthenticationPrincipal Jwt jwt | ||
| ) { | ||
| return ApiResponse.success( | ||
| SuccessStatus.ACCOUNT_GET_SUCCESS, | ||
| accountService.getAccount(userId(jwt)) | ||
| ); | ||
| } | ||
|
|
||
| private Long userId(Jwt jwt) { | ||
| return Long.valueOf(jwt.getSubject()); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/leets7th/job_is_be/domain/user/dto/AccountResponse.java
This file contains hidden or 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 com.leets7th.job_is_be.domain.user.dto; | ||
|
|
||
| import com.leets7th.job_is_be.domain.user.enums.SocialType; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record AccountResponse( | ||
| SocialType socialType, | ||
| LocalDateTime joinedAt, | ||
| String receivingEmail, | ||
| boolean emailVerified | ||
| ) { | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/leets7th/job_is_be/domain/user/service/AccountService.java
This file contains hidden or 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,37 @@ | ||
| package com.leets7th.job_is_be.domain.user.service; | ||
|
|
||
| import com.leets7th.job_is_be.domain.notification.entity.NotificationSetting; | ||
| import com.leets7th.job_is_be.domain.notification.repository.NotificationSettingRepository; | ||
| import com.leets7th.job_is_be.domain.user.dto.AccountResponse; | ||
| import com.leets7th.job_is_be.domain.user.entity.User; | ||
| import com.leets7th.job_is_be.domain.user.repository.UserRepository; | ||
| import com.leets7th.job_is_be.global.exception.GeneralException; | ||
| import com.leets7th.job_is_be.global.status.ErrorStatus; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class AccountService { | ||
|
|
||
| private final UserRepository userRepository; | ||
| private final NotificationSettingRepository notificationSettingRepository; | ||
|
|
||
| public AccountResponse getAccount(Long userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); | ||
|
|
||
| boolean emailVerified = notificationSettingRepository.findByUser(user) | ||
| .map(NotificationSetting::isEmailVerified) | ||
| .orElse(false); | ||
|
|
||
| return new AccountResponse( | ||
| user.getSocialType(), | ||
| user.getCreatedAt(), | ||
| user.getEmail(), | ||
| emailVerified | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
src/test/java/com/leets7th/job_is_be/domain/user/service/AccountServiceTest.java
This file contains hidden or 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,80 @@ | ||
| package com.leets7th.job_is_be.domain.user.service; | ||
|
|
||
| import com.leets7th.job_is_be.domain.notification.entity.NotificationSetting; | ||
| import com.leets7th.job_is_be.domain.notification.repository.NotificationSettingRepository; | ||
| import com.leets7th.job_is_be.domain.user.dto.AccountResponse; | ||
| import com.leets7th.job_is_be.domain.user.entity.User; | ||
| import com.leets7th.job_is_be.domain.user.enums.SocialType; | ||
| import com.leets7th.job_is_be.domain.user.repository.UserRepository; | ||
| import com.leets7th.job_is_be.global.exception.GeneralException; | ||
| import com.leets7th.job_is_be.global.status.ErrorStatus; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.test.util.ReflectionTestUtils; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Optional; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.catchThrowableOfType; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class AccountServiceTest { | ||
|
|
||
| @Mock | ||
| private UserRepository userRepository; | ||
| @Mock | ||
| private NotificationSettingRepository notificationSettingRepository; | ||
|
|
||
| @InjectMocks | ||
| private AccountService accountService; | ||
|
|
||
| private User user() { | ||
| User user = User.builder().socialId("s").socialType(SocialType.KAKAO).email("a@a.com").build(); | ||
| ReflectionTestUtils.setField(user, "id", 1L); | ||
| return user; | ||
| } | ||
|
|
||
| @Test | ||
| void 사용자가_없으면_예외를_던진다() { | ||
| when(userRepository.findById(1L)).thenReturn(Optional.empty()); | ||
|
|
||
| GeneralException exception = catchThrowableOfType( | ||
| () -> accountService.getAccount(1L), GeneralException.class); | ||
|
|
||
| assertThat(exception.getErrorStatus()).isEqualTo(ErrorStatus.USER_NOT_FOUND); | ||
| } | ||
|
|
||
| @Test | ||
| void 계정_정보를_조회한다() { | ||
| User user = user(); | ||
| LocalDateTime createdAt = LocalDateTime.of(2026, 1, 15, 10, 30); | ||
| ReflectionTestUtils.setField(user, "createdAt", createdAt); | ||
| NotificationSetting setting = NotificationSetting.builder().user(user).sendSlot("07:30").build(); | ||
| ReflectionTestUtils.setField(setting, "emailVerified", true); | ||
| when(userRepository.findById(1L)).thenReturn(Optional.of(user)); | ||
| when(notificationSettingRepository.findByUser(user)).thenReturn(Optional.of(setting)); | ||
|
|
||
| AccountResponse response = accountService.getAccount(1L); | ||
|
|
||
| assertThat(response.socialType()).isEqualTo(SocialType.KAKAO); | ||
| assertThat(response.joinedAt()).isEqualTo(createdAt); | ||
| assertThat(response.receivingEmail()).isEqualTo("a@a.com"); | ||
| assertThat(response.emailVerified()).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void 알림_설정이_없으면_이메일_미확인_상태로_반환한다() { | ||
| User user = user(); | ||
| when(userRepository.findById(1L)).thenReturn(Optional.of(user)); | ||
| when(notificationSettingRepository.findByUser(user)).thenReturn(Optional.empty()); | ||
|
|
||
| AccountResponse response = accountService.getAccount(1L); | ||
|
|
||
| assertThat(response.emailVerified()).isFalse(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.