-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: #54 이미지 업로드 API 엔드포인트 변경
- Loading branch information
Showing
11 changed files
with
84 additions
and
32 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/cabin/plat/config/image/controller/ImageController.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,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<ImageResponse.Avatar> uploadAvatarImage(@RequestPart(value = "image") MultipartFile image) { | ||
return BaseResponse.onSuccess(imageService.uploadAvatarImage(image)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/cabin/plat/config/image/dto/ImageResponse.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,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; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/cabin/plat/config/image/mapper/ImageMapper.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 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(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/cabin/plat/config/image/service/ImageService.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,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); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/cabin/plat/config/image/service/ImageServiceImpl.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,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)); | ||
} | ||
} |
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
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
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
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
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