Skip to content

Commit

Permalink
✨ 헤더에 띄워 줄 사진 + 실명 API (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jindongleee authored Nov 7, 2024
1 parent 8ad0475 commit 44e5c5e
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
17 changes: 17 additions & 0 deletions src/main/java/org/example/gather_back_end/user/dto/GetUserRes.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 44e5c5e

Please sign in to comment.