-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from Prography-8th-team8/feature-store-image
admin: store에 image 올리기
- Loading branch information
Showing
29 changed files
with
292 additions
and
223 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
34 changes: 34 additions & 0 deletions
34
src/main/java/prography/cakeke/server/admin/adapter/in/web/AdminController.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,34 @@ | ||
package prography.cakeke.server.admin.adapter.in.web; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import prography.cakeke.server.admin.application.port.in.AdminUseCase; | ||
import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; | ||
|
||
@RestController | ||
@RequestMapping("/api/admin") | ||
@RequiredArgsConstructor | ||
public class AdminController { | ||
|
||
private final AdminUseCase adminUseCase; | ||
|
||
@PostMapping(value = "/upload/image/{storeName}", | ||
consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Operation(summary = "케이크샵 이미지 업로드", description = "AWS S3에 케이크샵 이미지 업로드") | ||
public ResponseEntity<StoreResponse> uploadImage( | ||
@PathVariable(value = "storeName") String storeName, | ||
@RequestPart("image") List<MultipartFile> files) { | ||
return ResponseEntity.ok().body(this.adminUseCase.uploadImage(storeName, files).toResponse()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/prography/cakeke/server/admin/application/port/in/AdminUseCase.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,12 @@ | ||
package prography.cakeke.server.admin.application.port.in; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import prography.cakeke.server.store.domain.Store; | ||
|
||
public interface AdminUseCase { | ||
|
||
Store uploadImage(String storeName, List<MultipartFile> files); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/prography/cakeke/server/admin/application/service/AdminService.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,44 @@ | ||
package prography.cakeke.server.admin.application.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import prography.cakeke.server.admin.application.port.in.AdminUseCase; | ||
import prography.cakeke.server.image.application.port.in.ImageUseCase; | ||
import prography.cakeke.server.store.application.port.in.StoreUseCase; | ||
import prography.cakeke.server.store.domain.Store; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AdminService implements AdminUseCase { | ||
|
||
private static final Integer REPRESENTATIVE_INDEX = 0; // 0번째 업로드 되는 사진은 대표사진 | ||
private final StoreUseCase storeUseCase; | ||
private final ImageUseCase imageUseCase; | ||
|
||
/** | ||
* 해당 가게의 대표이미지와 이미지를 업로드합니다. | ||
* @param storeName 가게 이름 | ||
* @param files 가져올 블로그 개수 (기본 값 3) | ||
* @return 가게 정보 | ||
*/ | ||
@Override | ||
@Transactional | ||
public Store uploadImage(String storeName, List<MultipartFile> files) { | ||
Store store = storeUseCase.getByName(storeName); | ||
List<String> imageLinks = imageUseCase.uploadImages(files); | ||
|
||
// 대표이미지 먼저 바꾼다. (업로드 할 떄, 0번째 업로드 되는 사진은 대표사진이라는 제약이 있다.) | ||
store.uploadThumbnail(imageLinks.get(REPRESENTATIVE_INDEX)); | ||
// imageLinks의 첫 번째인 대표이미지를 제외한 나머지 사진들은 모두 이미지 필드에 추가한다. | ||
imageLinks.remove(REPRESENTATIVE_INDEX); | ||
store.uploadImageUrls(imageLinks); | ||
|
||
return store; | ||
} | ||
} |
20 changes: 14 additions & 6 deletions
20
.../prography/cakeke/server/common/Core.java → ...phy/cakeke/server/common/domain/Core.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
15 changes: 0 additions & 15 deletions
15
src/main/java/prography/cakeke/server/config/error/BaseException.java
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
src/main/java/prography/cakeke/server/config/error/ErrorCode.java
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
src/main/java/prography/cakeke/server/config/error/ErrorResponse.java
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
src/main/java/prography/cakeke/server/config/error/GlobalExceptionHandler.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/main/java/prography/cakeke/server/image/adaper/in/web/ImageExceptionController.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,29 @@ | ||
package prography.cakeke.server.image.adaper.in.web; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import prography.cakeke.server.image.exceptions.InvalidFileNameException; | ||
import prography.cakeke.server.image.exceptions.NotSupportedFileFormatException; | ||
|
||
@RestControllerAdvice | ||
public class ImageExceptionController { | ||
|
||
@ExceptionHandler(value = InvalidFileNameException.class) | ||
protected ResponseEntity<String> invalidFileNameException(InvalidFileNameException exception) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(value = NotSupportedFileFormatException.class) | ||
protected ResponseEntity<String> notSupportedFileFormatException( | ||
NotSupportedFileFormatException exception) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(value = Exception.class) | ||
protected ResponseEntity<String> handleException(Exception exception) { | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage()); | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/main/java/prography/cakeke/server/image/adapter/in/web/ImageController.java
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
src/main/java/prography/cakeke/server/image/adapter/in/web/response/UploadImageResponse.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.