-
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
[Feat/#27] 이미지 테이블 경로 단일 컬럼으로 수정, 이미지 업로드 기능 구현 및 리소스 핸들러 설정 추가
- Loading branch information
Showing
21 changed files
with
294 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
version: '3.8' | ||
|
||
services: | ||
mysql: | ||
image: mysql:latest | ||
container_name: mysql | ||
environment: | ||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | ||
MYSQL_DATABASE: ${MYSQL_DATABASE} | ||
MYSQL_USER: ${MYSQL_USER} | ||
MYSQL_PASSWORD: ${MYSQL_PASSWORD} | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- mysql_data:/var/lib/mysql | ||
|
||
|
||
volumes: | ||
mysql_data: | ||
|
||
springboot: | ||
container_name: marketplace | ||
image: ${DOCKER_USER}/${DOCKER_REPO}:marketplace-server # Docker Hub에서 가져올 이미지 | ||
volumes: | ||
- /home/serverking/marketplace:/app/image | ||
ports: | ||
- "8088:8080" | ||
environment: | ||
TZ: "Asia/Seoul" |
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 @@ | ||
version: '3.8' | ||
|
||
services: | ||
mysql: | ||
image: mysql:latest | ||
container_name: mysql | ||
environment: | ||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | ||
MYSQL_DATABASE: ${MYSQL_DATABASE} | ||
MYSQL_USER: ${MYSQL_USER} | ||
MYSQL_PASSWORD: ${MYSQL_PASSWORD} | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- mysql_data:/var/lib/mysql | ||
|
||
|
||
volumes: | ||
mysql_data: | ||
|
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/appcenter/marketplace/domain/image/ImageRepository.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,6 @@ | ||
package com.appcenter.marketplace.domain.image; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ImageRepository extends JpaRepository<Image,Long> { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/appcenter/marketplace/domain/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,12 @@ | ||
package com.appcenter.marketplace.domain.image.service; | ||
|
||
import com.appcenter.marketplace.domain.market.Market; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public interface ImageService { | ||
|
||
void createImage(Market market, List<MultipartFile> multipartFileList) throws IOException; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/appcenter/marketplace/domain/image/service/impl/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,51 @@ | ||
package com.appcenter.marketplace.domain.image.service.impl; | ||
|
||
import com.appcenter.marketplace.domain.image.Image; | ||
import com.appcenter.marketplace.domain.image.ImageRepository; | ||
import com.appcenter.marketplace.domain.image.service.ImageService; | ||
import com.appcenter.marketplace.domain.market.Market; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Transactional(readOnly = true) | ||
@Service | ||
@RequiredArgsConstructor | ||
public class ImageServiceImpl implements ImageService { | ||
private final ImageRepository imageRepository; | ||
|
||
@Value("${image.upload.path}") | ||
private String uploadFolder; | ||
|
||
// 이미지 리스트의 첫번째 요소를 썸네일로 설정 | ||
@Override | ||
@Transactional | ||
public void createImage(Market market, List<MultipartFile> multipartFileList) throws IOException { | ||
|
||
for (int i = 0; i < multipartFileList.size(); i++){ | ||
MultipartFile file = multipartFileList.get(i); | ||
String imageFileName = UUID.randomUUID() + "_" + file.getOriginalFilename(); | ||
File uploadFile = new File(uploadFolder + imageFileName); | ||
|
||
file.transferTo(uploadFile); | ||
|
||
Image image= Image.builder() | ||
.name(imageFileName) | ||
.market(market) | ||
.build(); | ||
imageRepository.save(image); | ||
|
||
if(i==0){ | ||
market.updateThumbnailPath(image.getName()); | ||
} | ||
|
||
} | ||
} | ||
} |
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
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.