-
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.
Browse files
Browse the repository at this point in the history
[FEAT] 회원 정보 조회 API 구현
- Loading branch information
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/danpoong/soenter/domain/user/controller/UserController.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,29 @@ | ||
package danpoong.soenter.domain.user.controller; | ||
|
||
import danpoong.soenter.base.ApiResponse; | ||
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse; | ||
import danpoong.soenter.domain.user.service.UserService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/users") | ||
@RequiredArgsConstructor | ||
@Tag(name = "User Controller", description = "유저 관련 API") | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
@GetMapping | ||
@Operation(summary = "회원 프로필 조회 API", description = "사용자의 프로필 정보를 조회합니다.") | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공") | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "잘못된 요청입니다.") | ||
public ApiResponse<GetUserDetailResponse> getUserDetail(Authentication authentication) { | ||
GetUserDetailResponse userDetail = userService.getUserDetail(authentication.getName()); | ||
return ApiResponse.onSuccess(userDetail); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/danpoong/soenter/domain/user/converter/UserConverter.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 danpoong.soenter.domain.user.converter; | ||
|
||
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse; | ||
import danpoong.soenter.domain.user.entity.User; | ||
|
||
public class UserConverter { | ||
public static GetUserDetailResponse toGetUserDetailResponse(User user) { | ||
return GetUserDetailResponse.builder() | ||
.name(user.getName()) | ||
.email(user.getEmail()) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/danpoong/soenter/domain/user/dto/UserDTO.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 danpoong.soenter.domain.user.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
public class UserDTO { | ||
public static class UserResponse { | ||
@Getter | ||
@Builder | ||
public static class GetUserDetailResponse { | ||
private String name; | ||
private String email; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/danpoong/soenter/domain/user/service/UserService.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,7 @@ | ||
package danpoong.soenter.domain.user.service; | ||
|
||
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse; | ||
|
||
public interface UserService { | ||
GetUserDetailResponse getUserDetail(String userId); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/danpoong/soenter/domain/user/service/UserServiceImpl.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,23 @@ | ||
package danpoong.soenter.domain.user.service; | ||
|
||
import danpoong.soenter.domain.user.converter.UserConverter; | ||
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse; | ||
import danpoong.soenter.domain.user.entity.User; | ||
import danpoong.soenter.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserServiceImpl implements UserService { | ||
private final UserRepository userRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public GetUserDetailResponse getUserDetail(String userId) { | ||
User user = userRepository.findById(Long.valueOf(userId)) | ||
.orElseThrow(() -> new RuntimeException("존재하지 않는 사용자입니다.")); | ||
|
||
return UserConverter.toGetUserDetailResponse(user); | ||
} | ||
} |