-
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.
Merge pull request #45 from Project-Catcher/feat-hs-user-info
내 정보 가져오기 구현
- Loading branch information
Showing
6 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/java/com/catcher/core/dto/user/UserInfoResponse.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,21 @@ | ||
package com.catcher.core.dto.user; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class UserInfoResponse { | ||
private String username; | ||
private String phone; | ||
private String email; | ||
private String profileImageUrl; | ||
private String nickname; | ||
private ZonedDateTime emailMarketingTerm; | ||
private ZonedDateTime phoneMarketingTerm; | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/test/java/com/catcher/testconfiguriation/WithCustomMockUser.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,22 @@ | ||
package com.catcher.testconfiguriation; | ||
|
||
import com.catcher.core.domain.entity.enums.UserRole; | ||
import org.springframework.security.test.context.support.WithSecurityContext; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.time.ZonedDateTime; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@WithSecurityContext(factory = WithCustomMockUserSecurityContextFactory.class) | ||
public @interface WithCustomMockUser{ | ||
Long id() default 1L; | ||
String username() default "username"; | ||
String password() default "password"; | ||
String phone() default "phone"; | ||
String email() default "email"; | ||
String profileImageUrl() default "profileImageUrl"; | ||
String introduceContent() default "introduceContent"; | ||
String nickname() default "nickname"; | ||
UserRole role(); | ||
} |
59 changes: 59 additions & 0 deletions
59
src/test/java/com/catcher/testconfiguriation/WithCustomMockUserSecurityContextFactory.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,59 @@ | ||
package com.catcher.testconfiguriation; | ||
|
||
import com.catcher.core.domain.entity.User; | ||
import com.catcher.core.domain.entity.enums.UserRole; | ||
import com.catcher.security.CatcherUser; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.test.context.support.WithSecurityContextFactory; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import static com.catcher.core.domain.entity.enums.UserProvider.CATCHER; | ||
|
||
|
||
public class WithCustomMockUserSecurityContextFactory implements WithSecurityContextFactory<WithCustomMockUser> { | ||
|
||
@Override | ||
public SecurityContext createSecurityContext(WithCustomMockUser annotation) { | ||
Long id = annotation.id(); | ||
String username = annotation.username(); | ||
String password = annotation.password(); | ||
String phone = annotation.phone(); | ||
String email = annotation.email(); | ||
String profileImageUrl = annotation.profileImageUrl(); | ||
String introduceContent = annotation.introduceContent(); | ||
String nickname = annotation.nickname(); | ||
UserRole role = annotation.role(); | ||
|
||
CatcherUser user = | ||
new CatcherUser(createUser(id, username, password, phone, email, profileImageUrl, introduceContent, nickname, role)); | ||
|
||
UsernamePasswordAuthenticationToken token = | ||
new UsernamePasswordAuthenticationToken(user, password); | ||
SecurityContext context = SecurityContextHolder.getContext(); | ||
context.setAuthentication(token); | ||
return context; | ||
} | ||
|
||
private User createUser(long id, String username, String password, String phone, String email, String profileImageUrl, String introduceContent, String nickname, UserRole role) { | ||
return User.builder() | ||
.id(id) | ||
.username(username) | ||
.password(password) | ||
.phone(phone) | ||
.email(email) | ||
.profileImageUrl(profileImageUrl) | ||
.introduceContent(introduceContent) | ||
.nickname(nickname) | ||
.userProvider(CATCHER) | ||
.userRole(role) | ||
.userAgeTerm(ZonedDateTime.now()) | ||
.userServiceTerm(ZonedDateTime.now()) | ||
.userPrivacyTerm(ZonedDateTime.now()) | ||
.emailMarketingTerm(ZonedDateTime.now()) | ||
.phoneMarketingTerm(ZonedDateTime.now()) | ||
.build(); | ||
} | ||
} |