From c8bdc5d358d34e095b1c93c21c85370cb5e38165 Mon Sep 17 00:00:00 2001 From: dgh06175 Date: Tue, 10 Sep 2024 19:49:46 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20#54=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20API=20=EC=97=94?= =?UTF-8?q?=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cabin/plat/config/SecurityConfig.java | 3 ++- .../image/controller/ImageController.java | 25 +++++++++++++++++++ .../plat/config/image/dto/ImageResponse.java | 14 +++++++++++ .../plat/config/image/mapper/ImageMapper.java | 13 ++++++++++ .../config/image/service/ImageService.java | 8 ++++++ .../image/service/ImageServiceImpl.java | 20 +++++++++++++++ .../member/controller/MemberController.java | 8 +----- .../domain/member/dto/MemberResponse.java | 7 ------ .../domain/member/mapper/MemberMapper.java | 6 ----- .../domain/member/service/MemberService.java | 2 -- .../member/service/MemberServiceImpl.java | 8 ------ 11 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/cabin/plat/config/image/controller/ImageController.java create mode 100644 src/main/java/com/cabin/plat/config/image/dto/ImageResponse.java create mode 100644 src/main/java/com/cabin/plat/config/image/mapper/ImageMapper.java create mode 100644 src/main/java/com/cabin/plat/config/image/service/ImageService.java create mode 100644 src/main/java/com/cabin/plat/config/image/service/ImageServiceImpl.java diff --git a/src/main/java/com/cabin/plat/config/SecurityConfig.java b/src/main/java/com/cabin/plat/config/SecurityConfig.java index f78f6f7..6aad1c9 100644 --- a/src/main/java/com/cabin/plat/config/SecurityConfig.java +++ b/src/main/java/com/cabin/plat/config/SecurityConfig.java @@ -57,7 +57,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers("/test").authenticated() .requestMatchers("/members/**").authenticated() .requestMatchers("/tracks/**").authenticated() - .requestMatchers("address/**").authenticated() + .requestMatchers("/address/**").authenticated() + .requestMatchers("images/**").authenticated() .anyRequest().denyAll()); http diff --git a/src/main/java/com/cabin/plat/config/image/controller/ImageController.java b/src/main/java/com/cabin/plat/config/image/controller/ImageController.java new file mode 100644 index 0000000..5ff4c9b --- /dev/null +++ b/src/main/java/com/cabin/plat/config/image/controller/ImageController.java @@ -0,0 +1,25 @@ +package com.cabin.plat.config.image.controller; + +import com.cabin.plat.config.image.dto.ImageResponse; +import com.cabin.plat.config.image.service.ImageService; +import com.cabin.plat.global.common.BaseResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/images") +@Tag(name = "이미지 API") +public class ImageController { + private final ImageService imageService; + + @Operation(summary = "사진 업로드", description = "사진을 업로드하여 해당 사진의 URL 을 반환합니다.") + @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public BaseResponse uploadAvatarImage(@RequestPart(value = "image") MultipartFile image) { + return BaseResponse.onSuccess(imageService.uploadAvatarImage(image)); + } +} diff --git a/src/main/java/com/cabin/plat/config/image/dto/ImageResponse.java b/src/main/java/com/cabin/plat/config/image/dto/ImageResponse.java new file mode 100644 index 0000000..7154c5d --- /dev/null +++ b/src/main/java/com/cabin/plat/config/image/dto/ImageResponse.java @@ -0,0 +1,14 @@ +package com.cabin.plat.config.image.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Getter; + +public class ImageResponse { + @Getter + @Builder + public static class Avatar { + @Schema(description = "아바타 이미지 URL", example = "https://example.com/avatar.png") + private String avatar; + } +} diff --git a/src/main/java/com/cabin/plat/config/image/mapper/ImageMapper.java b/src/main/java/com/cabin/plat/config/image/mapper/ImageMapper.java new file mode 100644 index 0000000..2f4638d --- /dev/null +++ b/src/main/java/com/cabin/plat/config/image/mapper/ImageMapper.java @@ -0,0 +1,13 @@ +package com.cabin.plat.config.image.mapper; + +import com.cabin.plat.config.image.dto.ImageResponse; +import org.springframework.stereotype.Component; + +@Component +public class ImageMapper { + public ImageResponse.Avatar toAvatar(String avatar) { + return ImageResponse.Avatar.builder() + .avatar(avatar) + .build(); + } +} diff --git a/src/main/java/com/cabin/plat/config/image/service/ImageService.java b/src/main/java/com/cabin/plat/config/image/service/ImageService.java new file mode 100644 index 0000000..c847954 --- /dev/null +++ b/src/main/java/com/cabin/plat/config/image/service/ImageService.java @@ -0,0 +1,8 @@ +package com.cabin.plat.config.image.service; + +import com.cabin.plat.config.image.dto.ImageResponse; +import org.springframework.web.multipart.MultipartFile; + +public interface ImageService { + ImageResponse.Avatar uploadAvatarImage(MultipartFile image); +} diff --git a/src/main/java/com/cabin/plat/config/image/service/ImageServiceImpl.java b/src/main/java/com/cabin/plat/config/image/service/ImageServiceImpl.java new file mode 100644 index 0000000..162f1f2 --- /dev/null +++ b/src/main/java/com/cabin/plat/config/image/service/ImageServiceImpl.java @@ -0,0 +1,20 @@ +package com.cabin.plat.config.image.service; + +import com.cabin.plat.config.image.dto.ImageResponse; +import com.cabin.plat.config.image.mapper.ImageMapper; +import com.cabin.plat.global.util.S3FileComponent; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +@Service +@RequiredArgsConstructor +public class ImageServiceImpl implements ImageService { + private final ImageMapper imageMapper; + private final S3FileComponent s3FileComponent; + + @Override + public ImageResponse.Avatar uploadAvatarImage(MultipartFile image) { + return imageMapper.toAvatar(s3FileComponent.uploadFile("image", image)); + } +} diff --git a/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java b/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java index 4d8a8fe..d5b3b19 100644 --- a/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java +++ b/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java @@ -18,7 +18,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/members") -@Tag(name = "멤버 API", description = "회원 관련 API입니다. 사용자 프로필 조회, 업데이트 및 삭제, 이미지 업로드 기능을 제공합니다.") +@Tag(name = "멤버 API", description = "회원 관련 API입니다. 사용자 프로필 조회, 업데이트 및 삭제 기능을 제공합니다.") public class MemberController { private final MemberService memberService; @@ -54,12 +54,6 @@ public BaseResponse updateStreamType( return BaseResponse.onSuccess(memberService.updateStreamType(member, streamType)); } - @Operation(summary = "유저 프로필 사진 업로드", description = "프로필 사진을 업로드하고 URL을 반환합니다. 이미지를 `image` 파라미터로 전송하여 프로필 사진을 변경하세요. \"유저 프로필 사진 변경\" API를 호출하기 직전에 사용해서 이미지의 URL을 받으세요.") - @PostMapping(value = "/profile/avatar/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponse uploadAvatarImage(@RequestPart(value = "image") MultipartFile image) { - return BaseResponse.onSuccess(memberService.uploadAvatarImage(image)); - } - @Operation(summary = "유저 프로필 사진 변경", description = "업로드한 이미지의 URL로 프로필 사진을 변경합니다. \"유저 프로필 사진 업로드\" API 에서 받은 이미지 URL을 `avatar` 객체에 담아 요청 본문으로 전달하세요.") @PatchMapping("/profile/avatar") public BaseResponse updateAvatarUrl(@AuthMember Member member, diff --git a/src/main/java/com/cabin/plat/domain/member/dto/MemberResponse.java b/src/main/java/com/cabin/plat/domain/member/dto/MemberResponse.java index b27c43c..57ed073 100644 --- a/src/main/java/com/cabin/plat/domain/member/dto/MemberResponse.java +++ b/src/main/java/com/cabin/plat/domain/member/dto/MemberResponse.java @@ -36,13 +36,6 @@ public static class MemberId { private Long memberId; } - @Getter - @Builder - public static class Avatar { - @Schema(description = "아바타 이미지 URL", example = "https://example.com/avatar.png") - private String avatar; - } - @Getter @Builder @AllArgsConstructor diff --git a/src/main/java/com/cabin/plat/domain/member/mapper/MemberMapper.java b/src/main/java/com/cabin/plat/domain/member/mapper/MemberMapper.java index 1f52b86..63155aa 100644 --- a/src/main/java/com/cabin/plat/domain/member/mapper/MemberMapper.java +++ b/src/main/java/com/cabin/plat/domain/member/mapper/MemberMapper.java @@ -46,10 +46,4 @@ public Member toMember(final String clientId, SocialType socialType) { .email("") .build(); } - - public MemberResponse.Avatar toAvatar(String avatar) { - return MemberResponse.Avatar.builder() - .avatar(avatar) - .build(); - } } diff --git a/src/main/java/com/cabin/plat/domain/member/service/MemberService.java b/src/main/java/com/cabin/plat/domain/member/service/MemberService.java index ea87eb0..0ebfa08 100644 --- a/src/main/java/com/cabin/plat/domain/member/service/MemberService.java +++ b/src/main/java/com/cabin/plat/domain/member/service/MemberService.java @@ -15,8 +15,6 @@ public interface MemberService { MemberResponse.MemberId updateStreamType(Member member, StreamType streamType); - MemberResponse.Avatar uploadAvatarImage(MultipartFile image); - MemberResponse.MemberId updateAvatarUrl(Member member, String avatar); MemberResponse.MemberSignIn appleSocialSignIn(MemberRequest.MemberAppleSocialSignIn request, SocialType socialType); diff --git a/src/main/java/com/cabin/plat/domain/member/service/MemberServiceImpl.java b/src/main/java/com/cabin/plat/domain/member/service/MemberServiceImpl.java index d4329e6..782c37a 100644 --- a/src/main/java/com/cabin/plat/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/cabin/plat/domain/member/service/MemberServiceImpl.java @@ -16,11 +16,9 @@ import com.cabin.plat.domain.member.entity.SocialType; import com.cabin.plat.domain.member.mapper.AuthenticationMapper; import com.cabin.plat.domain.member.repository.RefreshTokenRepository; -import com.cabin.plat.global.util.S3FileComponent; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; import java.util.Optional; @@ -32,7 +30,6 @@ public class MemberServiceImpl implements MemberService { private final MemberRepository memberRepository; private final JwtUtil jwtUtil; - private final S3FileComponent s3FileComponent; private final AuthenticationMapper authenticationMapper; private final RefreshTokenRepository refreshTokenRepository; private final MemberMapper memberMapper; @@ -110,11 +107,6 @@ public MemberId updateStreamType(Member member, StreamType streamType) { return memberMapper.toMemberId(updateMember.getId()); } - @Override - public Avatar uploadAvatarImage(MultipartFile image) { - return memberMapper.toAvatar(s3FileComponent.uploadFile("image", image)); - } - @Override @Transactional public MemberId updateAvatarUrl(Member member, String avatar) { From 520b49caf9f60040182e030ed9491c0b8468695e Mon Sep 17 00:00:00 2001 From: dgh06175 Date: Tue, 10 Sep 2024 19:54:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20#54=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=82=AC=EC=A7=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20API=20=EC=84=A4=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cabin/plat/domain/member/controller/MemberController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java b/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java index d5b3b19..3f66c01 100644 --- a/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java +++ b/src/main/java/com/cabin/plat/domain/member/controller/MemberController.java @@ -54,7 +54,7 @@ public BaseResponse updateStreamType( return BaseResponse.onSuccess(memberService.updateStreamType(member, streamType)); } - @Operation(summary = "유저 프로필 사진 변경", description = "업로드한 이미지의 URL로 프로필 사진을 변경합니다. \"유저 프로필 사진 업로드\" API 에서 받은 이미지 URL을 `avatar` 객체에 담아 요청 본문으로 전달하세요.") + @Operation(summary = "유저 프로필 사진 변경", description = "업로드한 이미지의 URL로 프로필 사진을 변경합니다. \"사진 업로드\" API 에서 받은 이미지 URL을 `avatar` 객체에 담아 요청 본문으로 전달하세요.") @PatchMapping("/profile/avatar") public BaseResponse updateAvatarUrl(@AuthMember Member member, @RequestBody MemberRequest.Avatar avatar) {