-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 게시글 본문 이미지 업로드/다운로드 기능 추가 #445
Merged
The head ref may contain hidden characters: "feature/gusah009/#109-\uAC8C\uC2DC\uAE00-\uC774\uBBF8\uC9C0-\uC5C5\uB85C\uB4DC-\uAE30\uB2A5"
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions
2
src/main/java/com/keeper/homepage/domain/file/dao/FileRepository.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,8 +1,10 @@ | ||
package com.keeper.homepage.domain.file.dao; | ||
|
||
import com.keeper.homepage.domain.file.entity.FileEntity; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FileRepository extends JpaRepository<FileEntity, Long> { | ||
|
||
Optional<FileEntity> findByFileUUID(String fileUUID); | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/keeper/homepage/domain/post/dto/response/FileForContentResponse.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,21 @@ | ||
package com.keeper.homepage.domain.post.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import static lombok.AccessLevel.PRIVATE; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = PRIVATE) | ||
public class FileForContentResponse { | ||
|
||
private String filePath; | ||
|
||
public static FileForContentResponse from(String filePath) { | ||
return FileForContentResponse.builder() | ||
.filePath(filePath) | ||
.build(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -1034,4 +1034,68 @@ class DownloadFile { | |
assertThat(content).contains(POST_HAS_NOT_THAT_FILE.getMessage()); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("게시글 본문 파일 업로드 테스트") | ||
class UploadFileForContent { | ||
|
||
@Test | ||
@DisplayName("유효한 요청일 경우 게시글 본문 파일 업로드는 성공한다.") | ||
public void 유효한_요청일_경우_게시글_본문_파일_업로드는_성공한다() throws Exception { | ||
String securedValue = getSecuredValue(PostController.class, "uploadFileForContent"); | ||
|
||
Comment on lines
+1044
to
+1046
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
file = new MockMultipartFile("file", "testImage_1x1.png", "image/png", | ||
new FileInputStream("src/test/resources/images/testImage_1x1.png")); | ||
|
||
callUploadFileForContent(memberToken, file) | ||
.andExpect(status().isCreated()) | ||
.andDo(document("upload-file-for-content", | ||
requestCookies( | ||
cookieWithName(ACCESS_TOKEN.getTokenName()) | ||
.description("ACCESS TOKEN %s".formatted(securedValue)) | ||
), | ||
requestParts( | ||
partWithName("file").description("게시글의 본문에 넣을 파일") | ||
), | ||
responseFields( | ||
fieldWithPath("filePath").description("저장된 파일을 불러올 수 있는 file의 hash값과 url입니다.") | ||
))); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("게시글 본문 파일 다운로드 테스트") | ||
class GetFileForContent { | ||
|
||
@Test | ||
@DisplayName("유효한 요청일 경우 게시글 본문 파일 다운로드는 성공한다.") | ||
public void 유효한_요청일_경우_게시글_본문_파일_다운로드는_성공한다() throws Exception { | ||
String securedValue = getSecuredValue(PostController.class, "getFileForContent"); | ||
|
||
FileEntity fileEntity = postService.uploadFileForContent(file); | ||
|
||
callGetFileForContent(memberToken, fileEntity.getFileUUID()) | ||
.andExpect(status().isOk()) | ||
.andExpect( | ||
header().string(CONTENT_DISPOSITION, "attachment; filename=\"" + fileEntity.getFileName() + "\"")) | ||
.andDo(document("get-file-for-content", | ||
requestCookies( | ||
cookieWithName(ACCESS_TOKEN.getTokenName()) | ||
.description("ACCESS TOKEN %s".formatted(securedValue)) | ||
), | ||
pathParameters( | ||
parameterWithName("fileUUID").description("업로드한 파일의 uuid") | ||
), | ||
responseHeaders( | ||
headerWithName(CONTENT_DISPOSITION).description("파일 이름을 포함한 응답 헤더입니다.") | ||
))); | ||
} | ||
|
||
@Test | ||
@DisplayName("존재하지 않는 파일 해시일 경우 게시글 본문 파일 다운로드는 실패한다.") | ||
public void 존재하지_않는_파일_해시일_경우_게시글_본문_파일_다운로드는_실패한다() throws Exception { | ||
callGetFileForContent(memberToken, "invalidFileUUID") | ||
.andExpect(status().isBadRequest()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로그 남기는 이유가 뭔가요?? 또, 보통 하나의 메서드에 로그 하나씩은 남기는 편인가요?
제가 로그를 남겨본적이 없어서..ㅎㅎ 여쭤봅니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 보통은 로그를 따로 안남기는데 이 API 같은 경우는 게시글 본문에 이미지를 올리기만 하면 업로드가 되어서 서버 용량에 영향을 미치기가 쉬운 API라 혹시나 모를 어뷰징에 대비해 로그를 남겨놨습니다~