-
Notifications
You must be signed in to change notification settings - Fork 0
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 #63 from everymeals/feature/user-info-get
[Feature/user info get] 마이페이지 - 사용자 프로필 조회 API
- Loading branch information
Showing
9 changed files
with
125 additions
and
5 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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/everymeal/server/user/controller/dto/response/UserProfileRes.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,15 @@ | ||
package everymeal.server.user.controller.dto.response; | ||
|
||
|
||
import java.util.Map; | ||
|
||
public record UserProfileRes( | ||
Long userId, String nickName, String profileImgUrl, String universityName) { | ||
public static UserProfileRes of(Map<String, Object> user) { | ||
return new UserProfileRes( | ||
(Long) user.get("userId"), | ||
(String) user.get("nickName"), | ||
(String) user.get("profileImgUrl"), | ||
(String) user.get("universityName")); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/everymeal/server/user/repository/UserMapper.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 everymeal.server.user.repository; | ||
|
||
|
||
import java.util.Map; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Mapper | ||
@Repository | ||
public interface UserMapper { | ||
Map<String, Object> getUserProfile(@Param("idx") Long idx); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
<mapper namespace="everymeal.server.user.repository.UserMapper"> | ||
|
||
<select id="getUserProfile"> | ||
SELECT | ||
u.idx as userId, | ||
u.nickname as nickName, | ||
u.profile_img_url as profileImgUrl, | ||
u2.name as universityName | ||
FROM users u | ||
INNER JOIN university u2 ON u.university_idx = u2.idx AND u2.is_deleted = false | ||
WHERE u.is_deleted = false AND u.idx = #{idx} | ||
</select> | ||
|
||
</mapper> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import everymeal.server.global.exception.ExceptionList; | ||
import everymeal.server.global.util.JwtUtil; | ||
import everymeal.server.global.util.MailUtil; | ||
import everymeal.server.global.util.authresolver.entity.AuthenticatedUser; | ||
import everymeal.server.global.util.aws.S3Util; | ||
import everymeal.server.university.entity.University; | ||
import everymeal.server.university.repository.UniversityRepository; | ||
|
@@ -224,6 +225,30 @@ void checkUser() { | |
assertThat(response).isTrue(); | ||
} | ||
|
||
@DisplayName("인증된 유저의 프로필 확인") | ||
@Test | ||
void getUserProfile() { | ||
// given | ||
String token = jwtUtil.generateEmailToken("[email protected]", "12345"); | ||
|
||
University university = | ||
universityRepository.save( | ||
University.builder().name("명지대학교").campusName("인문캠퍼스").build()); | ||
UserEmailSingReq request = | ||
new UserEmailSingReq("nickname", token, "12345", university.getIdx(), "imageKey"); | ||
|
||
UserLoginRes userLoginRes = userService.signUp(request); | ||
|
||
AuthenticatedUser user = | ||
jwtUtil.getAuthenticateUserFromAccessToken(userLoginRes.accessToken()); | ||
|
||
// when | ||
var response = userService.getUserProfile(user); | ||
|
||
// then | ||
assertEquals(response.nickName(), request.nickname()); | ||
} | ||
|
||
private User createUser(String email, String nickname) { | ||
return User.builder().email(email).nickname(nickname).build(); | ||
} | ||
|