Skip to content

Commit

Permalink
add :: imageUpload api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Umjiseung committed Jun 5, 2024
1 parent 50abec8 commit 62ca156
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mindway.server.v2.domain.image.presentation;

import com.mindway.server.v2.domain.image.presentation.dto.response.ImageUploadResponseDto;
import com.mindway.server.v2.domain.image.service.ImageUploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequiredArgsConstructor
public class ImageController {

private final ImageUploadService imageUploadService;

@PostMapping
public ResponseEntity<ImageUploadResponseDto> uploadImage(@RequestPart MultipartFile image) {
ImageUploadResponseDto response = imageUploadService.execute(image);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mindway.server.v2.domain.image.presentation.dto.response;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ImageUploadResponseDto {
private String img_url;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mindway.server.v2.domain.image.service;

import com.mindway.server.v2.domain.image.presentation.dto.response.ImageUploadResponseDto;
import org.springframework.web.multipart.MultipartFile;

public interface ImageUploadService {
ImageUploadResponseDto execute(MultipartFile image);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mindway.server.v2.domain.image.service.impl;

import com.mindway.server.v2.domain.image.presentation.dto.response.ImageUploadResponseDto;
import com.mindway.server.v2.domain.image.service.ImageUploadService;
import com.mindway.server.v2.domain.image.util.ImageConverter;
import com.mindway.server.v2.global.annotation.ServiceWithTransaction;
import com.mindway.server.v2.global.thirdparty.aws.S3Util;
import lombok.RequiredArgsConstructor;
import org.springframework.web.multipart.MultipartFile;

@ServiceWithTransaction
@RequiredArgsConstructor
public class ImageUploadServiceImpl implements ImageUploadService {

private final S3Util s3Util;
private final ImageConverter imageConverter;

public ImageUploadResponseDto execute(MultipartFile image) {
String img_url = s3Util.imageUpload(image);
return imageConverter.toDto(img_url);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mindway.server.v2.domain.image.util;

import com.mindway.server.v2.domain.image.presentation.dto.response.ImageUploadResponseDto;

public interface ImageConverter {
ImageUploadResponseDto toDto(String img_url);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mindway.server.v2.domain.image.util.impl;

import com.mindway.server.v2.domain.image.presentation.dto.response.ImageUploadResponseDto;
import com.mindway.server.v2.domain.image.util.ImageConverter;
import org.springframework.stereotype.Component;

@Component
public class ImageConverterImpl implements ImageConverter {

public ImageUploadResponseDto toDto(String img_url) {
return ImageUploadResponseDto.builder()
.img_url(img_url)
.build();
}
}

0 comments on commit 62ca156

Please sign in to comment.