Skip to content

Commit

Permalink
Merge pull request #35 from Prography-8th-team8/feature-store-image
Browse files Browse the repository at this point in the history
admin: store에 image 올리기
  • Loading branch information
ympark99 authored Jun 22, 2023
2 parents d400be8 + 9ba6197 commit 4c3fffe
Show file tree
Hide file tree
Showing 29 changed files with 292 additions and 223 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {

// aws s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'javax.xml.bind:jaxb-api:2.3.0'
}

test {
Expand Down
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());
}
}
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);
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package prography.cakeke.server.common;
package prography.cakeke.server.common.domain;

import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonIgnore;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

@Getter
@MappedSuperclass
Expand Down

This file was deleted.

40 changes: 0 additions & 40 deletions src/main/java/prography/cakeke/server/config/error/ErrorCode.java

This file was deleted.

This file was deleted.

This file was deleted.

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());
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import org.springframework.web.multipart.MultipartFile;

import prography.cakeke.server.image.adapter.in.web.response.UploadImageResponse;

public interface ImageUseCase {
UploadImageResponse uploadImage(List<MultipartFile> multipartFiles);

List<String> uploadImages(List<MultipartFile> multipartFiles);
}
Loading

0 comments on commit 4c3fffe

Please sign in to comment.