Skip to content

Commit b7033fc

Browse files
authored
Merge pull request #119 from CommitField/Feature/89
Feature/89
2 parents 215b8c2 + c17b66d commit b7033fc

File tree

4 files changed

+55
-31
lines changed

4 files changed

+55
-31
lines changed

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cmf.commitField.domain.chat.chatRoom.dto.ChatRoomUserDto;
88
import cmf.commitField.domain.chat.chatRoom.service.ChatRoomService;
99
import cmf.commitField.domain.user.entity.CustomOAuth2User;
10+
import cmf.commitField.global.aws.s3.S3Service;
1011
import cmf.commitField.global.error.ErrorCode;
1112
import cmf.commitField.global.globalDto.GlobalResponse;
1213
import cmf.commitField.global.security.LoginCheck;
@@ -28,25 +29,25 @@
2829
@RequestMapping("/chat")
2930
public class ChatRoomController {
3031
private final ChatRoomService chatRoomService;
31-
private final FileService fileService;
32+
private final S3Service s3Service; // S3 파일 μ €μž₯을 μœ„ν•œ μ„œλΉ„μŠ€
33+
private final FileService fileService; //local file μ €μž₯을 μœ„ν•œ μ„œλΉ„μŠ€
3234

3335
// μ±„νŒ…λ°© 생성 (파일 μ—…λ‘œλ“œ 포함)
3436
@PostMapping(value = "/room", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
3537
public GlobalResponse<Object> createRoom(
3638
@ModelAttribute @Valid ChatRoomRequest chatRoomRequest) throws IOException {
3739

38-
3940
// 인증 확인
4041
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
4142

4243
if (authentication instanceof OAuth2AuthenticationToken) {
4344
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
44-
Long userId = principal.getId(); // getId()λ₯Ό 톡해 userIdλ₯Ό μΆ”μΆœ
45+
Long userId = principal.getId(); // getId()λ₯Ό 톡해 userId μΆ”μΆœ
4546

4647
// 파일 μ—…λ‘œλ“œ 처리
4748
String imageUrl = null;
4849
if (chatRoomRequest.getFile() != null && !chatRoomRequest.getFile().isEmpty()) {
49-
imageUrl = fileService.saveFile(chatRoomRequest.getFile()); // 파일 μ €μž₯
50+
imageUrl = s3Service.uploadFile(chatRoomRequest.getFile(), "chat-room"); // S3에 μ—…λ‘œλ“œ
5051
}
5152

5253
// μ±„νŒ…λ°© 생성 μ„œλΉ„μŠ€ 호좜 (이미지 URL 포함)
@@ -58,6 +59,7 @@ public GlobalResponse<Object> createRoom(
5859
}
5960
}
6061

62+
6163
//μ±„νŒ…λ°© μž…μž₯
6264
@PostMapping("/room/join/{roomId}")
6365
public GlobalResponse<Object> joinRoom(@PathVariable Long roomId, @RequestBody ChatRoomRequest chatRoomRequest) {
@@ -253,8 +255,33 @@ public GlobalResponse<Object> searchRoomName(
253255
}
254256
}
255257

256-
257-
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+
// }
258285

259286

260287
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//package cmf.commitField.domain.chat.chatRoom.controller.response;
2-
//
3-
//public class ChatRoomResponse {
4-
//}
1+
package cmf.commitField.domain.chat.chatRoom.controller.response;
2+
3+
public class ChatRoomResponse {
4+
}
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)