Skip to content

Commit b421797

Browse files
committed
Feat: S3 설정 변경, chatRoom 파일 설정
1 parent 7ac3e1b commit b421797

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

src/main/java/cmf/commitField/domain/chat/chatRoom/controller/ChatRoomController.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cmf.commitField.domain.chat.chatRoom.controller;
22

3+
import cmf.commitField.domain.File.service.FileService;
34
import cmf.commitField.domain.chat.chatRoom.controller.request.ChatRoomRequest;
45
import cmf.commitField.domain.chat.chatRoom.controller.request.ChatRoomUpdateRequest;
56
import cmf.commitField.domain.chat.chatRoom.dto.ChatRoomDto;
@@ -29,6 +30,7 @@
2930
public class ChatRoomController {
3031
private final ChatRoomService chatRoomService;
3132
private final S3Service s3Service; // S3 파일 저장을 위한 서비스
33+
private final FileService fileService; //local file 저장을 위한 서비스
3234

3335
// 채팅방 생성 (파일 업로드 포함)
3436
@PostMapping(value = "/room", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@@ -57,6 +59,7 @@ public GlobalResponse<Object> createRoom(
5759
}
5860
}
5961

62+
6063
//채팅방 입장
6164
@PostMapping("/room/join/{roomId}")
6265
public GlobalResponse<Object> joinRoom(@PathVariable Long roomId, @RequestBody ChatRoomRequest chatRoomRequest) {
@@ -252,8 +255,33 @@ public GlobalResponse<Object> searchRoomName(
252255
}
253256
}
254257

255-
256-
258+
// // 채팅방 생성 (파일 업로드 포함)
259+
// @PostMapping(value = "/room", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
260+
// public GlobalResponse<Object> createRoom(
261+
// @ModelAttribute @Valid ChatRoomRequest chatRoomRequest) throws IOException {
262+
//
263+
//
264+
// // 인증 확인
265+
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
266+
//
267+
// if (authentication instanceof OAuth2AuthenticationToken) {
268+
// CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
269+
// Long userId = principal.getId(); // getId()를 통해 userId를 추출
270+
//
271+
// // 파일 업로드 처리
272+
// String imageUrl = null;
273+
// if (chatRoomRequest.getFile() != null && !chatRoomRequest.getFile().isEmpty()) {
274+
// imageUrl = fileService.saveFile(chatRoomRequest.getFile()); // 파일 저장
275+
// }
276+
//
277+
// // 채팅방 생성 서비스 호출 (이미지 URL 포함)
278+
// chatRoomService.createRoom(chatRoomRequest, userId, imageUrl);
279+
//
280+
// return GlobalResponse.success("채팅방을 생성하였습니다.");
281+
// } else {
282+
// throw new IllegalArgumentException("로그인 후에 이용해 주세요.");
283+
// }
284+
// }
257285

258286

259287
}
Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package cmf.commitField.global.aws.s3;
22

3-
import jakarta.annotation.PreDestroy;
43
import org.springframework.stereotype.Component;
54
import software.amazon.awssdk.services.s3.S3Client;
6-
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
7-
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
8-
import software.amazon.awssdk.services.s3.model.S3Object;
95

106
@Component
117
public class S3Cleaner {
@@ -17,21 +13,21 @@ public S3Cleaner(S3Client s3Client) {
1713
this.s3Client = s3Client;
1814
}
1915

20-
@PreDestroy
21-
public void cleanup() {
22-
// S3에서 테스트 파일 삭제
23-
ListObjectsV2Request listObjects = ListObjectsV2Request.builder()
24-
.bucket(bucketName)
25-
.build();
26-
27-
// 파일 목록을 가져옵니다.
28-
ListObjectsV2Response listObjectsResponse = s3Client.listObjectsV2(listObjects);
29-
30-
// 각 파일을 삭제합니다.
31-
for (S3Object s3Object : listObjectsResponse.contents()) {
32-
s3Client.deleteObject(builder -> builder.bucket(bucketName).key(s3Object.key()));
33-
}
34-
35-
System.out.println("S3에 있는 테스트 파일들을 삭제했습니다.");
36-
}
16+
// @PreDestroy
17+
// public void cleanup() {
18+
// // S3에서 테스트 파일 삭제
19+
// ListObjectsV2Request listObjects = ListObjectsV2Request.builder()
20+
// .bucket(bucketName)
21+
// .build();
22+
//
23+
// // 파일 목록을 가져옵니다.
24+
// ListObjectsV2Response listObjectsResponse = s3Client.listObjectsV2(listObjects);
25+
//
26+
// // 각 파일을 삭제합니다.
27+
// for (S3Object s3Object : listObjectsResponse.contents()) {
28+
// s3Client.deleteObject(builder -> builder.bucket(bucketName).key(s3Object.key()));
29+
// }
30+
//
31+
// System.out.println("S3에 있는 테스트 파일들을 삭제했습니다.");
32+
// }
3733
}

src/main/java/cmf/commitField/global/aws/s3/S3Service.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public String uploadFile(MultipartFile file, String dirName) throws IOException
2525
.bucket(BUCKET_NAME)
2626
.key(fileName)
2727
.contentType(file.getContentType())
28+
// .acl(ObjectCannedACL.PUBLIC_READ) // Public Read 권한 추가
2829
.build();
2930

3031
s3Client.putObject(putObjectRequest,

0 commit comments

Comments
 (0)