diff --git a/api/src/main/java/com/civilwar/boardsignal/auth/dto/OAuthUserInfo.java b/api/src/main/java/com/civilwar/boardsignal/auth/dto/OAuthUserInfo.java index fa79df9c..d51f7381 100644 --- a/api/src/main/java/com/civilwar/boardsignal/auth/dto/OAuthUserInfo.java +++ b/api/src/main/java/com/civilwar/boardsignal/auth/dto/OAuthUserInfo.java @@ -2,12 +2,8 @@ public record OAuthUserInfo( String email, - String name, String nickname, String imageUrl, - String birthYear, - String ageRange, - String gender, String provider, String providerId ) { diff --git a/api/src/main/java/com/civilwar/boardsignal/auth/handler/OAuth2LoginSuccessHandler.java b/api/src/main/java/com/civilwar/boardsignal/auth/handler/OAuth2LoginSuccessHandler.java index 67c5d3fe..3606fd4e 100644 --- a/api/src/main/java/com/civilwar/boardsignal/auth/handler/OAuth2LoginSuccessHandler.java +++ b/api/src/main/java/com/civilwar/boardsignal/auth/handler/OAuth2LoginSuccessHandler.java @@ -25,7 +25,8 @@ @RequiredArgsConstructor public class OAuth2LoginSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { - private final String DOMAIN = "https://team-civilwar-boardsignal-fe.pages.dev"; + private final String DOMAIN = "http://localhost:5173"; + // "https://team-civilwar-boardsignal-fe.pages.dev"; private final String REFRESHTOKEN_NAME = "RefreshToken_Id"; private final AuthService authService; diff --git a/api/src/main/java/com/civilwar/boardsignal/auth/mapper/AuthApiMapper.java b/api/src/main/java/com/civilwar/boardsignal/auth/mapper/AuthApiMapper.java index eb72cd7a..e382661a 100644 --- a/api/src/main/java/com/civilwar/boardsignal/auth/mapper/AuthApiMapper.java +++ b/api/src/main/java/com/civilwar/boardsignal/auth/mapper/AuthApiMapper.java @@ -14,12 +14,8 @@ public final class AuthApiMapper { public static UserLoginRequest toUserLoginRequest(OAuthUserInfo oAuthUserInfo) { return new UserLoginRequest( oAuthUserInfo.email(), - oAuthUserInfo.name(), oAuthUserInfo.nickname(), oAuthUserInfo.imageUrl(), - oAuthUserInfo.birthYear(), - oAuthUserInfo.ageRange(), - oAuthUserInfo.gender(), oAuthUserInfo.provider(), oAuthUserInfo.providerId() ); diff --git a/api/src/main/java/com/civilwar/boardsignal/auth/mapper/OAuthAttributeMapper.java b/api/src/main/java/com/civilwar/boardsignal/auth/mapper/OAuthAttributeMapper.java index 895610a7..929cb291 100644 --- a/api/src/main/java/com/civilwar/boardsignal/auth/mapper/OAuthAttributeMapper.java +++ b/api/src/main/java/com/civilwar/boardsignal/auth/mapper/OAuthAttributeMapper.java @@ -30,22 +30,14 @@ private static OAuthUserInfo kakaoUserInfo(Map userAttributes, Map profile = (Map) kakaoAccount.get("profile"); String email = (String) kakaoAccount.get("email"); - String name = (String) kakaoAccount.get("name"); String nickName = (String) profile.get("nickname"); String imageUrl = (String) profile.get("profile_image_url"); - String birthYear = (String) kakaoAccount.get("birthyear"); - String ageRange = (String) kakaoAccount.get("age_range"); - String gender = (String) kakaoAccount.get("gender"); String providerId = userAttributes.get("id").toString(); return new OAuthUserInfo( email, - name, nickName, imageUrl, - birthYear, - ageRange, - gender, provider, providerId ); @@ -54,26 +46,18 @@ private static OAuthUserInfo kakaoUserInfo(Map userAttributes, private static OAuthUserInfo naverUserInfo(Map userAttributes, String provider) { - Map kakaoAccount = (Map) userAttributes + Map naverAccount = (Map) userAttributes .get("response"); - String email = kakaoAccount.get("email"); - String name = kakaoAccount.get("name"); - String nickName = kakaoAccount.get("nickname"); - String imageUrl = kakaoAccount.get("profile_image"); - String birthYear = kakaoAccount.get("birthyear"); - String ageRange = kakaoAccount.get("age"); - String gender = kakaoAccount.get("gender"); - String providerId = kakaoAccount.get("id"); + String email = naverAccount.get("email"); + String nickName = naverAccount.get("nickname"); + String imageUrl = naverAccount.get("profile_image"); + String providerId = naverAccount.get("id"); return new OAuthUserInfo( email, - name, nickName, imageUrl, - birthYear, - ageRange, - gender, provider, providerId ); diff --git a/api/src/main/java/com/civilwar/boardsignal/user/dto/request/ApiUserModifyRequest.java b/api/src/main/java/com/civilwar/boardsignal/user/dto/request/ApiUserModifyRequest.java index a77d5d98..566129e7 100644 --- a/api/src/main/java/com/civilwar/boardsignal/user/dto/request/ApiUserModifyRequest.java +++ b/api/src/main/java/com/civilwar/boardsignal/user/dto/request/ApiUserModifyRequest.java @@ -4,6 +4,8 @@ public record ApiUserModifyRequest( String nickName, + String gender, + int birth, String line, String station, List categories diff --git a/api/src/main/java/com/civilwar/boardsignal/user/mapper/UserApiMapper.java b/api/src/main/java/com/civilwar/boardsignal/user/mapper/UserApiMapper.java index cb4e2b7b..7ce03ac6 100644 --- a/api/src/main/java/com/civilwar/boardsignal/user/mapper/UserApiMapper.java +++ b/api/src/main/java/com/civilwar/boardsignal/user/mapper/UserApiMapper.java @@ -25,6 +25,8 @@ public static UserModifyRequest toUserModifyRequest(Long userId, userId, apiUserModifyRequest.nickName(), userCategories, + apiUserModifyRequest.gender(), + apiUserModifyRequest.birth(), apiUserModifyRequest.line(), apiUserModifyRequest.station(), image diff --git a/api/src/test/java/com/civilwar/boardsignal/auth/presentation/AuthApiControllerTest.java b/api/src/test/java/com/civilwar/boardsignal/auth/presentation/AuthApiControllerTest.java index 3dedb203..5f2ebc0e 100644 --- a/api/src/test/java/com/civilwar/boardsignal/auth/presentation/AuthApiControllerTest.java +++ b/api/src/test/java/com/civilwar/boardsignal/auth/presentation/AuthApiControllerTest.java @@ -1,6 +1,5 @@ package com.civilwar.boardsignal.auth.presentation; -import static org.mockito.BDDMockito.given; import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -10,7 +9,6 @@ import com.civilwar.boardsignal.auth.domain.model.Token; import com.civilwar.boardsignal.auth.exception.AuthErrorCode; import com.civilwar.boardsignal.auth.infrastructure.JwtTokenProvider; -import com.civilwar.boardsignal.boardgame.domain.constant.Category; import com.civilwar.boardsignal.common.support.ApiTestSupport; import com.civilwar.boardsignal.user.UserFixture; import com.civilwar.boardsignal.user.domain.constants.Role; @@ -18,13 +16,11 @@ import com.civilwar.boardsignal.user.domain.repository.UserRepository; import jakarta.servlet.http.Cookie; import java.time.LocalDateTime; -import java.util.List; import java.util.function.Supplier; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.transaction.annotation.Transactional; @DisplayName("[AuthApiController 테스트]") class AuthApiControllerTest extends ApiTestSupport { @@ -95,41 +91,6 @@ void logoutTest2() throws Exception { .andExpect(jsonPath("$.logoutResult").value(false)); } - @Test - @Transactional - @DisplayName("[AccessToken의 사용자 정보를 반환한다.]") - void getLoginUserInfoTest() throws Exception { - //given - User loginUserEntity = userRepository.findById(loginUser.getId()) - .orElseThrow(); - - String updateNickname = "업데이트된 닉네임"; - List categories = List.of(Category.CUSTOMIZABLE, Category.PARTY); - String subwayLine = "2호선"; - String subwayStation = "사당역"; - String image = "update image"; - loginUserEntity.updateUser(updateNickname, categories, subwayLine, subwayStation, image); - - LocalDateTime now = LocalDateTime.of(2024, 3, 4, 9, 27, 0); - given(nowTime.get()).willReturn(now); - - int expectedAge = nowTime.get().getYear() - loginUser.getBirth() + 1; - - //then - mockMvc.perform(get("/api/v1/auth") - .header(AUTHORIZATION, accessToken)) - .andExpect(jsonPath("$.id").value(loginUser.getId())) - .andExpect(jsonPath("$.email").value(loginUser.getEmail())) - .andExpect(jsonPath("$.nickname").value(updateNickname)) - .andExpect(jsonPath("$.ageGroup").value(loginUser.getAgeGroup().getDescription())) - .andExpect(jsonPath("$.gender").value(loginUser.getGender().getDescription())) - .andExpect(jsonPath("$.isJoined").value(true)) - .andExpect(jsonPath("$.age").value(expectedAge)) - .andExpect(jsonPath("$.subwayLine").value(subwayLine)) - .andExpect(jsonPath("$.subwayStation").value(subwayStation)) - .andExpect(jsonPath("$.categories.size()").value(2)); - } - @Test @DisplayName("[인증이 안 된 사용자가 접근 시 401 에러와 전용 에러 메시지 & 코드를 반환한다.]") void exceptionHandlingTest() throws Exception { diff --git a/api/src/test/java/com/civilwar/boardsignal/room/presentation/RoomControllerTest.java b/api/src/test/java/com/civilwar/boardsignal/room/presentation/RoomControllerTest.java index 365086d4..74691e37 100644 --- a/api/src/test/java/com/civilwar/boardsignal/room/presentation/RoomControllerTest.java +++ b/api/src/test/java/com/civilwar/boardsignal/room/presentation/RoomControllerTest.java @@ -40,7 +40,6 @@ import com.civilwar.boardsignal.room.dto.response.ParticipantJpaDto; import com.civilwar.boardsignal.room.infrastructure.repository.MeetingInfoJpaRepository; import com.civilwar.boardsignal.user.UserFixture; -import com.civilwar.boardsignal.user.domain.constants.AgeGroup; import com.civilwar.boardsignal.user.domain.constants.Gender; import com.civilwar.boardsignal.user.domain.constants.Role; import com.civilwar.boardsignal.user.domain.entity.User; @@ -781,14 +780,10 @@ void participantRoomTest3() throws Exception { roomRepository.save(room); User user = User.of("email", - "name", "nickName", "provider", "providerId", - "testURL", - 1998, - AgeGroup.TWENTY, - Gender.MALE); + "testURL"); User savedUser = userRepository.save(user); Token token = tokenProvider.createToken(savedUser.getId(), Role.USER); @@ -829,14 +824,10 @@ void participantRoomTest4() throws Exception { roomRepository.save(room); User user = User.of("email", - "name", "nickName", "provider", "providerId", - "testURL", - 2020, - AgeGroup.TWENTY, - Gender.MALE); + "testURL"); User savedUser = userRepository.save(user); Token token = tokenProvider.createToken(savedUser.getId(), Role.USER); @@ -877,14 +868,10 @@ void participantRoomTest5() throws Exception { roomRepository.save(room); User user = User.of("email", - "name", "nickName", "provider", "providerId", - "testURL", - 1998, - AgeGroup.TWENTY, - Gender.MALE); + "testURL"); User savedUser = userRepository.save(user); blackListRepository.save(RoomBlackList.of(room.getId(), savedUser.getId())); diff --git a/api/src/test/java/com/civilwar/boardsignal/user/presentation/UserApiControllerTest.java b/api/src/test/java/com/civilwar/boardsignal/user/presentation/UserApiControllerTest.java index 69d77983..9d7ec5f2 100644 --- a/api/src/test/java/com/civilwar/boardsignal/user/presentation/UserApiControllerTest.java +++ b/api/src/test/java/com/civilwar/boardsignal/user/presentation/UserApiControllerTest.java @@ -1,6 +1,7 @@ package com.civilwar.boardsignal.user.presentation; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; import static org.springframework.http.HttpHeaders.AUTHORIZATION; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; @@ -20,6 +21,8 @@ import com.civilwar.boardsignal.review.domain.entity.ReviewEvaluation; import com.civilwar.boardsignal.review.domain.repository.ReviewRepository; import com.civilwar.boardsignal.user.UserFixture; +import com.civilwar.boardsignal.user.domain.constants.AgeGroup; +import com.civilwar.boardsignal.user.domain.constants.Gender; import com.civilwar.boardsignal.user.domain.constants.OAuthProvider; import com.civilwar.boardsignal.user.domain.constants.Role; import com.civilwar.boardsignal.user.domain.entity.User; @@ -28,10 +31,13 @@ import com.civilwar.boardsignal.user.dto.request.ValidNicknameRequest; import java.io.FileInputStream; import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; import java.util.List; +import java.util.function.Supplier; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; @@ -47,12 +53,16 @@ class UserApiControllerTest extends ApiTestSupport { private TokenProvider tokenProvider; @Autowired private WishRepository wishRepository; + @MockBean + private Supplier now; @Test @DisplayName("[회원은 정보를 수정 할 수 있다]") void joinUserTest() throws Exception { //given + given(now.get()).willReturn(LocalDateTime.of(2024, 4, 16, 0, 0, 0)); + User userFixture = UserFixture.getUserFixture(OAuthProvider.KAKAO.getType(), "testURL"); userRepository.save(userFixture); @@ -61,6 +71,8 @@ void joinUserTest() throws Exception { ApiUserModifyRequest apiUserModifyRequest = new ApiUserModifyRequest( "injuning", + Gender.MALE.getDescription(), + 1970, "2호선", "사당역", List.of("가족게임", "파티게임") @@ -99,6 +111,7 @@ void joinUserTest() throws Exception { assertThat(findUser.getNickname()).isEqualTo(apiUserModifyRequest.nickName()); assertThat(findUser.getLine()).isEqualTo(apiUserModifyRequest.line()); assertThat(findUser.getStation()).isEqualTo(apiUserModifyRequest.station()); + assertThat(findUser.getAgeGroup()).isEqualTo(AgeGroup.FIFTY); } @@ -106,6 +119,8 @@ void joinUserTest() throws Exception { @DisplayName("유저의 자신의 프로필을 조회할 수 있다.") void getUserProfileTest() throws Exception { //given + given(now.get()).willReturn(LocalDateTime.of(2024, 4, 16, 0, 0, 0)); + List evaluationFixture = ReviewFixture.getEvaluationFixture(); Review review = ReviewFixture.getReviewFixture(100L, loginUser.getId(), 1L, evaluationFixture); @@ -145,6 +160,8 @@ void getUserProfileTest() throws Exception { @DisplayName("타인의 프로필을 조회할 수 있다.") void getUserProfileTest2() throws Exception { //given + given(now.get()).willReturn(LocalDateTime.of(2024, 4, 16, 0, 0, 0)); + User anotherUser = UserFixture.getUserFixture2("providerId", "testUrl"); userRepository.save(anotherUser); List evaluationFixture = ReviewFixture.getEvaluationFixture(); @@ -202,7 +219,8 @@ void validNicknameTest1() throws Exception { void validNicknameTest2() throws Exception { //given String existName = loginUser.getName(); - loginUser.updateUser(existName, List.of(Category.CUSTOMIZABLE), "2호선", "사당역", "testURL"); + loginUser.updateUser(existName, List.of(Category.CUSTOMIZABLE), Gender.MALE, 2000, + AgeGroup.TWENTY, "2호선", "사당역", "testURL"); userRepository.save(loginUser); ValidNicknameRequest validNicknameRequest = new ValidNicknameRequest(existName); @@ -240,7 +258,8 @@ void validNicknameTest4() throws Exception { User anotherUser = UserFixture.getUserFixture("providerId", "testURL"); String existName = anotherUser.getName(); userRepository.save(anotherUser); - anotherUser.updateUser(existName, List.of(Category.CUSTOMIZABLE), "2호선", "사당역", "testURL"); + anotherUser.updateUser(existName, List.of(Category.CUSTOMIZABLE), Gender.MALE, 2000, + AgeGroup.TWENTY, "2호선", "사당역", "testURL"); userRepository.save(loginUser); ValidNicknameRequest validNicknameRequest = new ValidNicknameRequest(existName); diff --git a/core/src/main/java/com/civilwar/boardsignal/auth/application/AuthService.java b/core/src/main/java/com/civilwar/boardsignal/auth/application/AuthService.java index 9cb5cd37..81fbf6ac 100644 --- a/core/src/main/java/com/civilwar/boardsignal/auth/application/AuthService.java +++ b/core/src/main/java/com/civilwar/boardsignal/auth/application/AuthService.java @@ -7,8 +7,6 @@ import com.civilwar.boardsignal.auth.dto.response.UserLoginResponse; import com.civilwar.boardsignal.auth.dto.response.UserLogoutResponse; import com.civilwar.boardsignal.auth.mapper.AuthMapper; -import com.civilwar.boardsignal.user.domain.constants.AgeGroup; -import com.civilwar.boardsignal.user.domain.constants.Gender; import com.civilwar.boardsignal.user.domain.entity.User; import com.civilwar.boardsignal.user.domain.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -33,14 +31,10 @@ public UserLoginResponse login(UserLoginRequest userLoginRequest) { user = userRepository.save( User.of( userLoginRequest.email(), - userLoginRequest.name(), userLoginRequest.nickname(), userLoginRequest.provider(), userLoginRequest.providerId(), - userLoginRequest.imageUrl(), - Integer.parseInt(userLoginRequest.birthYear()), - AgeGroup.of(userLoginRequest.ageRange(), userLoginRequest.provider()), - Gender.of(userLoginRequest.gender(), userLoginRequest.provider()) + userLoginRequest.imageUrl() ) ); } diff --git a/core/src/main/java/com/civilwar/boardsignal/auth/dto/request/UserLoginRequest.java b/core/src/main/java/com/civilwar/boardsignal/auth/dto/request/UserLoginRequest.java index 3d33d801..4877cc53 100644 --- a/core/src/main/java/com/civilwar/boardsignal/auth/dto/request/UserLoginRequest.java +++ b/core/src/main/java/com/civilwar/boardsignal/auth/dto/request/UserLoginRequest.java @@ -2,12 +2,8 @@ public record UserLoginRequest( String email, - String name, String nickname, String imageUrl, - String birthYear, - String ageRange, - String gender, String provider, String providerId ) { diff --git a/core/src/main/java/com/civilwar/boardsignal/user/application/UserService.java b/core/src/main/java/com/civilwar/boardsignal/user/application/UserService.java index 2b9ec913..fa603132 100644 --- a/core/src/main/java/com/civilwar/boardsignal/user/application/UserService.java +++ b/core/src/main/java/com/civilwar/boardsignal/user/application/UserService.java @@ -5,6 +5,8 @@ import com.civilwar.boardsignal.common.exception.NotFoundException; import com.civilwar.boardsignal.image.domain.ImageRepository; import com.civilwar.boardsignal.room.domain.repository.RoomRepository; +import com.civilwar.boardsignal.user.domain.constants.AgeGroup; +import com.civilwar.boardsignal.user.domain.constants.Gender; import com.civilwar.boardsignal.user.domain.entity.User; import com.civilwar.boardsignal.user.domain.entity.UserCategory; import com.civilwar.boardsignal.user.domain.repository.UserRepository; @@ -50,6 +52,9 @@ public UserModifyResponse modifyUser(UserModifyRequest userModifyRequest) { findUser.updateUser( userModifyRequest.nickName(), userModifyRequest.categories(), + Gender.toGender(userModifyRequest.gender()), + userModifyRequest.birth(), + AgeGroup.convert(userModifyRequest.birth(), now.get()), userModifyRequest.line(), userModifyRequest.station(), profileImageUrl diff --git a/core/src/main/java/com/civilwar/boardsignal/user/domain/constants/AgeGroup.java b/core/src/main/java/com/civilwar/boardsignal/user/domain/constants/AgeGroup.java index 2493e81e..9fb8e24c 100644 --- a/core/src/main/java/com/civilwar/boardsignal/user/domain/constants/AgeGroup.java +++ b/core/src/main/java/com/civilwar/boardsignal/user/domain/constants/AgeGroup.java @@ -3,6 +3,7 @@ import static com.civilwar.boardsignal.user.exception.UserErrorCode.NOT_FOUND_AGE_GROUP; import com.civilwar.boardsignal.common.exception.NotFoundException; +import java.time.LocalDateTime; import java.util.Arrays; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,21 +12,23 @@ @RequiredArgsConstructor public enum AgeGroup { - UNDER_CHILDREN("1~9", "1-9", "미취학 아동"), - CHILDREN("10~14", "10-14", "어린이"), - TEENAGER("14~19", "14-19", "청소년"), - TWENTY("20~29", "20-29", "20대"), - THIRTY("30~39", "30-39", "30대"), - FORTY("40~49", "40-49", "40대"), - FIFTY("50~59", "50-59", "50대"), - SIXTY("60~69", "60-69", "60대"), - SEVENTY("70~79", "70-79", "70대"), - EIGHTY("80~89", "80-89", "80대"), - NINETY("90~", "90-", "90이상"); + UNKNOWN("0", "0", "알 수 없음", 0), + UNDER_CHILDREN("1~9", "1-9", "미취학 아동", 9), + CHILDREN("10~14", "10-14", "어린이", 14), + TEENAGER("14~19", "14-19", "청소년", 19), + TWENTY("20~29", "20-29", "20대", 29), + THIRTY("30~39", "30-39", "30대", 39), + FORTY("40~49", "40-49", "40대", 49), + FIFTY("50~59", "50-59", "50대", 59), + SIXTY("60~69", "60-69", "60대", 69), + SEVENTY("70~79", "70-79", "70대", 79), + EIGHTY("80~89", "80-89", "80대", 89), + NINETY("90~", "90-", "90이상", 100); private final String kakaoType; private final String naverType; private final String description; + private final int maxAge; public static AgeGroup of(String input, String provider) { return Arrays.stream(values()) @@ -34,6 +37,22 @@ public static AgeGroup of(String input, String provider) { .orElseThrow(() -> new NotFoundException(NOT_FOUND_AGE_GROUP)); } + public static AgeGroup convert(int birthYear, LocalDateTime now) { + AgeGroup userAgeGroup = UNKNOWN; + //사용자 나이 + int userAge = now.getYear() - birthYear + 1; + + for (AgeGroup a : values()) { + //현재 연령대에 사용자의 나이가 포함된다면 + if (a.getMaxAge() >= userAge) { + userAgeGroup = a; + break; + } + } + return userAgeGroup; + + } + private boolean isEqual(String input, String provider) { if (provider.equals(OAuthProvider.KAKAO.getType())) { return input.equalsIgnoreCase(this.kakaoType); diff --git a/core/src/main/java/com/civilwar/boardsignal/user/domain/entity/User.java b/core/src/main/java/com/civilwar/boardsignal/user/domain/entity/User.java index 68885743..7a1610cb 100644 --- a/core/src/main/java/com/civilwar/boardsignal/user/domain/entity/User.java +++ b/core/src/main/java/com/civilwar/boardsignal/user/domain/entity/User.java @@ -100,13 +100,13 @@ public class User extends BaseEntity implements UserDetails { private User( @NonNull String email, @NonNull String name, - @NonNull String nickname, + String nickname, @NonNull String provider, @NonNull String providerId, @NonNull String profileImageUrl, - @NonNull int birth, - @NonNull AgeGroup ageGroup, - @NonNull Gender gender + int birth, + AgeGroup ageGroup, + Gender gender ) { this.email = email; this.name = name; @@ -123,6 +123,22 @@ private User( this.signal = 0; } + public static User of( + String email, + String nickname, + String provider, + String providerId, + String profileImageUrl + ) { + return User.builder() + .email(email) + .name(nickname) + .provider(provider) + .providerId(providerId) + .profileImageUrl(profileImageUrl) + .build(); + } + public static User of( String email, String name, @@ -150,11 +166,17 @@ public static User of( public void updateUser( String nickname, List categories, + Gender gender, + int birth, + AgeGroup ageGroup, String line, String station, String profileImageUrl ) { this.nickname = nickname; + this.gender = gender; + this.birth = birth; + this.ageGroup = ageGroup; this.line = line; this.station = station; this.userCategories.clear(); diff --git a/core/src/main/java/com/civilwar/boardsignal/user/dto/request/UserModifyRequest.java b/core/src/main/java/com/civilwar/boardsignal/user/dto/request/UserModifyRequest.java index c1d1878d..a7ba13a4 100644 --- a/core/src/main/java/com/civilwar/boardsignal/user/dto/request/UserModifyRequest.java +++ b/core/src/main/java/com/civilwar/boardsignal/user/dto/request/UserModifyRequest.java @@ -9,6 +9,8 @@ public record UserModifyRequest( Long id, String nickName, List categories, + String gender, + int birth, String line, String station, MultipartFile image diff --git a/core/src/test/java/com/civilwar/boardsignal/auth/application/AuthServiceTest.java b/core/src/test/java/com/civilwar/boardsignal/auth/application/AuthServiceTest.java index 7c874c01..645c616d 100644 --- a/core/src/test/java/com/civilwar/boardsignal/auth/application/AuthServiceTest.java +++ b/core/src/test/java/com/civilwar/boardsignal/auth/application/AuthServiceTest.java @@ -12,8 +12,6 @@ import com.civilwar.boardsignal.auth.dto.response.IssueTokenResponse; import com.civilwar.boardsignal.auth.dto.response.UserLoginResponse; import com.civilwar.boardsignal.user.UserFixture; -import com.civilwar.boardsignal.user.domain.constants.AgeGroup; -import com.civilwar.boardsignal.user.domain.constants.Gender; import com.civilwar.boardsignal.user.domain.constants.OAuthProvider; import com.civilwar.boardsignal.user.domain.constants.Role; import com.civilwar.boardsignal.user.domain.entity.User; @@ -48,11 +46,7 @@ void loginTest1() { UserLoginRequest userLoginRequest = new UserLoginRequest( "abc1234@gmail.com", "최인준", - "injuning", "testURL", - String.valueOf(2000), - AgeGroup.TWENTY.getKakaoType(), - Gender.MALE.getKakaoType(), OAuthProvider.KAKAO.getType(), providerId ); @@ -84,10 +78,6 @@ void loginTest2() { "abc1234@gmail.com", "최인준", "injuning", - "testURL", - String.valueOf(2000), - AgeGroup.TWENTY.getKakaoType(), - Gender.MALE.getKakaoType(), OAuthProvider.KAKAO.getType(), providerId ); diff --git a/core/src/test/java/com/civilwar/boardsignal/user/application/UserServiceTest.java b/core/src/test/java/com/civilwar/boardsignal/user/application/UserServiceTest.java index 5e48e409..5a680ebc 100644 --- a/core/src/test/java/com/civilwar/boardsignal/user/application/UserServiceTest.java +++ b/core/src/test/java/com/civilwar/boardsignal/user/application/UserServiceTest.java @@ -7,13 +7,16 @@ import com.civilwar.boardsignal.common.MultipartFileFixture; import com.civilwar.boardsignal.image.domain.ImageRepository; import com.civilwar.boardsignal.user.UserFixture; +import com.civilwar.boardsignal.user.domain.constants.Gender; import com.civilwar.boardsignal.user.domain.entity.User; import com.civilwar.boardsignal.user.domain.repository.UserRepository; import com.civilwar.boardsignal.user.dto.request.UserModifyRequest; import com.civilwar.boardsignal.user.dto.response.UserModifyResponse; import java.io.IOException; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; +import java.util.function.Supplier; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,6 +34,8 @@ class UserServiceTest { private UserRepository userRepository; @Mock private ImageRepository imageRepository; + @Mock + private Supplier now; @InjectMocks private UserService userService; @@ -48,6 +53,8 @@ void joinUserTest() throws IOException { id, "injuning", List.of(Category.FAMILY, Category.PARTY), + Gender.MALE.getDescription(), + 2000, "2호선", "사당역", imageFixture @@ -55,6 +62,7 @@ void joinUserTest() throws IOException { User userFixture = UserFixture.getUserFixture(providerId, testUrl); Boolean isJoined = userFixture.getIsJoined(); + when(now.get()).thenReturn(LocalDateTime.of(2024, 11, 20, 0, 0, 0)); when(imageRepository.save(imageFixture)).thenReturn(testUrl); when(userRepository.findById(id)).thenReturn(Optional.of(userFixture)); ReflectionTestUtils.setField(userFixture, "id", id);