-
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.
Merge pull request #111 from TRIP-Side-Project/dev
merge main
- Loading branch information
Showing
35 changed files
with
468 additions
and
183 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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/api/trip/common/exception/custom_exception/DuplicateException.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,10 @@ | ||
package com.api.trip.common.exception.custom_exception; | ||
|
||
import com.api.trip.common.exception.CustomException; | ||
import com.api.trip.common.exception.ErrorCode; | ||
|
||
public class DuplicateException extends CustomException { | ||
public DuplicateException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/api/trip/common/exception/custom_exception/ForbiddenException.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,10 @@ | ||
package com.api.trip.common.exception.custom_exception; | ||
|
||
import com.api.trip.common.exception.CustomException; | ||
import com.api.trip.common.exception.ErrorCode; | ||
|
||
public class ForbiddenException extends CustomException { | ||
public ForbiddenException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/api/trip/common/exception/custom_exception/NotMatchException.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,10 @@ | ||
package com.api.trip.common.exception.custom_exception; | ||
|
||
import com.api.trip.common.exception.CustomException; | ||
import com.api.trip.common.exception.ErrorCode; | ||
|
||
public class NotMatchException extends CustomException { | ||
public NotMatchException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
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
31 changes: 21 additions & 10 deletions
31
src/main/java/com/api/trip/domain/articlefile/service/ArticleFileService.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 |
---|---|---|
@@ -1,43 +1,54 @@ | ||
package com.api.trip.domain.articlefile.service; | ||
|
||
import com.api.trip.common.exception.CustomException; | ||
import com.api.trip.common.exception.ErrorCode; | ||
import com.api.trip.domain.articlefile.model.ArticleFile; | ||
import com.api.trip.domain.articlefile.repository.ArticleFileRepository; | ||
import com.api.trip.domain.articlefile.uploader.ArticleFileUploader; | ||
import com.api.trip.domain.member.repository.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class ArticleFileService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final ArticleFileRepository articleFileRepository; | ||
private final ArticleFileUploader articleFileUploader; | ||
|
||
public String upload(MultipartFile multipartFile, String email) { | ||
if (Objects.equals(email, "anonymousUser")) { | ||
throw new RuntimeException("접근 권한이 없습니다."); | ||
memberRepository.findByEmail(email) | ||
.orElseThrow(() -> new CustomException(ErrorCode.UNAUTHORIZED)); | ||
|
||
String url = null; | ||
try { | ||
url = articleFileUploader.upload(multipartFile, UUID.randomUUID().toString()); | ||
} catch (IOException e) { | ||
throw new CustomException(ErrorCode.UPLOAD_FAILED); | ||
} | ||
|
||
String url = articleFileUploader.upload(multipartFile, UUID.randomUUID().toString()); | ||
|
||
ArticleFile articleFile = ArticleFile.builder() | ||
.url(url) | ||
.build(); | ||
|
||
return articleFileRepository.save(articleFile).getUrl(); | ||
return articleFileRepository.save( | ||
ArticleFile.builder() | ||
.url(url) | ||
.build() | ||
) | ||
.getUrl(); | ||
} | ||
|
||
public void deleteTemporaryArticleFilesBefore(LocalDateTime localDateTime) { | ||
List<ArticleFile> articleFiles = articleFileRepository.findAllByArticleNullAndCreatedAtBefore(localDateTime); | ||
|
||
articleFileRepository.deleteAllInBatch(articleFiles); | ||
|
||
articleFiles.forEach(articleFile -> articleFileUploader.delete(articleFile.getUrl())); | ||
} | ||
} |
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.