7
7
import cmf .commitField .domain .chat .chatRoom .dto .ChatRoomUserDto ;
8
8
import cmf .commitField .domain .chat .chatRoom .service .ChatRoomService ;
9
9
import cmf .commitField .domain .user .entity .CustomOAuth2User ;
10
+ import cmf .commitField .global .aws .s3 .S3Service ;
10
11
import cmf .commitField .global .error .ErrorCode ;
11
12
import cmf .commitField .global .globalDto .GlobalResponse ;
12
13
import cmf .commitField .global .security .LoginCheck ;
28
29
@ RequestMapping ("/chat" )
29
30
public class ChatRoomController {
30
31
private final ChatRoomService chatRoomService ;
31
- private final FileService fileService ;
32
+ private final S3Service s3Service ; // S3 ํ์ผ ์ ์ฅ์ ์ํ ์๋น์ค
33
+ private final FileService fileService ; //local file ์ ์ฅ์ ์ํ ์๋น์ค
32
34
33
35
// ์ฑํ
๋ฐฉ ์์ฑ (ํ์ผ ์
๋ก๋ ํฌํจ)
34
36
@ PostMapping (value = "/room" , consumes = MediaType .MULTIPART_FORM_DATA_VALUE )
35
37
public GlobalResponse <Object > createRoom (
36
38
@ ModelAttribute @ Valid ChatRoomRequest chatRoomRequest ) throws IOException {
37
39
38
-
39
40
// ์ธ์ฆ ํ์ธ
40
41
Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
41
42
42
43
if (authentication instanceof OAuth2AuthenticationToken ) {
43
44
CustomOAuth2User principal = (CustomOAuth2User ) authentication .getPrincipal ();
44
- Long userId = principal .getId (); // getId()๋ฅผ ํตํด userId๋ฅผ ์ถ์ถ
45
+ Long userId = principal .getId (); // getId()๋ฅผ ํตํด userId ์ถ์ถ
45
46
46
47
// ํ์ผ ์
๋ก๋ ์ฒ๋ฆฌ
47
48
String imageUrl = null ;
48
49
if (chatRoomRequest .getFile () != null && !chatRoomRequest .getFile ().isEmpty ()) {
49
- imageUrl = fileService . saveFile (chatRoomRequest .getFile ()); // ํ์ผ ์ ์ฅ
50
+ imageUrl = s3Service . uploadFile (chatRoomRequest .getFile (), "chat-room" ); // S3์ ์
๋ก๋
50
51
}
51
52
52
53
// ์ฑํ
๋ฐฉ ์์ฑ ์๋น์ค ํธ์ถ (์ด๋ฏธ์ง URL ํฌํจ)
@@ -58,6 +59,7 @@ public GlobalResponse<Object> createRoom(
58
59
}
59
60
}
60
61
62
+
61
63
//์ฑํ
๋ฐฉ ์
์ฅ
62
64
@ PostMapping ("/room/join/{roomId}" )
63
65
public GlobalResponse <Object > joinRoom (@ PathVariable Long roomId , @ RequestBody ChatRoomRequest chatRoomRequest ) {
@@ -253,8 +255,33 @@ public GlobalResponse<Object> searchRoomName(
253
255
}
254
256
}
255
257
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
+ // }
258
285
259
286
260
287
}
0 commit comments