Skip to content

Commit

Permalink
Merge pull request #20 from 9oormthon-univ/feature/#18
Browse files Browse the repository at this point in the history
[FEAT] 회원 정보 조회 API 구현
  • Loading branch information
haeun1107 authored Nov 19, 2024
2 parents 1594a9a + d4ea8cf commit 4302128
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
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);
}
}
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 src/main/java/danpoong/soenter/domain/user/dto/UserDTO.java
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;
}
}
}
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);
}
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);
}
}

0 comments on commit 4302128

Please sign in to comment.