diff --git a/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java b/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java index 2492494..5fc5a2a 100644 --- a/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java +++ b/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java @@ -1,6 +1,5 @@ package org.example.gather_back_end.bucket.service; -import org.example.gather_back_end.user.dto.UploadProfileImgRes; import org.springframework.web.multipart.MultipartFile; public interface BucketService { diff --git a/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java b/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java index 53843b0..9d5ca43 100644 --- a/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java +++ b/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java @@ -18,7 +18,6 @@ import lombok.extern.slf4j.Slf4j; import org.example.gather_back_end.domain.User; import org.example.gather_back_end.repository.UserRepository; -import org.example.gather_back_end.user.dto.UploadProfileImgRes; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; diff --git a/src/main/java/org/example/gather_back_end/user/controller/UserController.java b/src/main/java/org/example/gather_back_end/user/controller/UserController.java index 764d323..88671d0 100644 --- a/src/main/java/org/example/gather_back_end/user/controller/UserController.java +++ b/src/main/java/org/example/gather_back_end/user/controller/UserController.java @@ -1,15 +1,26 @@ package org.example.gather_back_end.user.controller; import lombok.RequiredArgsConstructor; -import org.example.gather_back_end.bucket.service.BucketService; -import org.example.gather_back_end.user.dto.UploadProfileImgRes; +import org.example.gather_back_end.user.dto.GetUserRes; +import org.example.gather_back_end.user.service.UserService; import org.example.gather_back_end.util.response.SuccessResponse; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; @RestController @RequiredArgsConstructor -@RequestMapping("/api/users") +@RequestMapping("/api/user") public class UserController implements UserControllerApi { + private final UserService userService; + + // 유저 프로필 이미지 & 이름 GetMapping + @GetMapping("/header-info") + public SuccessResponse getUser(Authentication authentication){ + + GetUserRes res = userService.getUser(authentication); + + return SuccessResponse.of(res); + + } } diff --git a/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java b/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java index 657a82c..f320f58 100644 --- a/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java +++ b/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java @@ -7,27 +7,28 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import org.example.gather_back_end.user.dto.UploadProfileImgRes; +import org.example.gather_back_end.user.dto.GetUserRes; import org.example.gather_back_end.util.response.SuccessResponse; -import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.security.core.Authentication; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; @Tag(name = "User 관련", description = "유저와 관련된 API") public interface UserControllerApi { -// @Operation(summary = "프로필 사진 업로드", description = "유저의 프로필 사진을 업로드하는 API") -// @ApiResponses(value = { -// @ApiResponse(responseCode = "200", description = "성공", -// content = @Content(mediaType = "application/json", -// examples = @ExampleObject(value = "{\n" -// + " \"timestamp\": \"2024-10-22T21:35:03.755865\",\n" -// + " \"isSuccess\": true,\n" -// + " \"code\": \"200\",\n" -// + " \"message\": \"호출에 성공하였습니다.\",\n" -// + " \"data\": null\n" -// + "}"), -// schema = @Schema(implementation = SuccessResponse.class))) -// }) + @Operation(summary = "프로필 사진, 이름 불러오기", description = "유저의 프로필 사진, 이름 불러오는 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공", + content = @Content(mediaType = "application/json", + examples = @ExampleObject(value = "{\n" + + " \"timestamp\": \"2024-10-22T21:35:03.755865\",\n" + + " \"isSuccess\": true,\n" + + " \"code\": \"200\",\n" + + " \"message\": \"호출에 성공하였습니다.\",\n" + + " \"data\": null\n" + + "}"), + schema = @Schema(implementation = SuccessResponse.class))) + }) + @GetMapping + SuccessResponse getUser(Authentication authentication); } diff --git a/src/main/java/org/example/gather_back_end/user/dto/GetUserRes.java b/src/main/java/org/example/gather_back_end/user/dto/GetUserRes.java new file mode 100644 index 0000000..e676252 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/user/dto/GetUserRes.java @@ -0,0 +1,17 @@ +package org.example.gather_back_end.user.dto; + +import lombok.Builder; +import org.example.gather_back_end.domain.User; + +@Builder +public record GetUserRes( + String profileImgUrl, + String name +) { + public static GetUserRes from(User user) { + return GetUserRes.builder() + .profileImgUrl(user.getProfileImgUrl()) + .name(user.getName()) + .build(); + } +} diff --git a/src/main/java/org/example/gather_back_end/user/dto/UploadProfileImgRes.java b/src/main/java/org/example/gather_back_end/user/dto/UploadProfileImgRes.java deleted file mode 100644 index d6fe82a..0000000 --- a/src/main/java/org/example/gather_back_end/user/dto/UploadProfileImgRes.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.example.gather_back_end.user.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -@Builder -public record UploadProfileImgRes( - @Schema(description = "프로필 이미지 public url", example = "https://objectstorage.ap-chuncheon-1.oraclecloud.com/n/axtc7cirqxfb/b/Togather/o/profileImg%2F4ab4db03-f9ef-4526-98e5-1121e45c7eec_profile2.png") - String profileImgUrl -) { - - public static UploadProfileImgRes from(String profileImgUrl) { - return UploadProfileImgRes.builder() - .profileImgUrl(profileImgUrl) - .build(); - } -} diff --git a/src/main/java/org/example/gather_back_end/user/service/UserService.java b/src/main/java/org/example/gather_back_end/user/service/UserService.java new file mode 100644 index 0000000..755c2c2 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/user/service/UserService.java @@ -0,0 +1,11 @@ +package org.example.gather_back_end.user.service; + +import org.example.gather_back_end.user.dto.GetUserRes; +import org.springframework.security.core.Authentication; + +public interface UserService { + + // 사용자 프로필과 이름을 가져오는 서비스 + GetUserRes getUser(Authentication authentication); + +} diff --git a/src/main/java/org/example/gather_back_end/user/service/UserServiceImpl.java b/src/main/java/org/example/gather_back_end/user/service/UserServiceImpl.java new file mode 100644 index 0000000..3564a62 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/user/service/UserServiceImpl.java @@ -0,0 +1,24 @@ +package org.example.gather_back_end.user.service; + +import lombok.RequiredArgsConstructor; +import org.example.gather_back_end.domain.User; +import org.example.gather_back_end.repository.UserRepository; +import org.example.gather_back_end.user.dto.GetUserRes; +import org.example.gather_back_end.util.jwt.dto.CustomOAuth2User; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; + + // 사용자 프로필과 이름 가져오는 서비스 + @Override + public GetUserRes getUser(Authentication authentication) { + CustomOAuth2User customOAuth2User = (CustomOAuth2User) authentication.getPrincipal(); + User user = userRepository.getByUsername(customOAuth2User.getUsername()); + return GetUserRes.from(user); + } +}