diff --git a/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java b/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java index fe664dd..5eae345 100644 --- a/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java +++ b/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java @@ -27,49 +27,13 @@ public ChatController(ChatService chatService, SimpMessagingTemplate template, this.template = template; this.redisTemplate = redisTemplate; } -// @MessageMapping("/chat/{sessionId}") -// public void sendChatMessage(@DestinationVariable("sessionId") final String sessionId, -// @RequestBody final ChatMessageRequestDto chatMessageRequestDto) { -// final ChatMessageResponseDto responseDto = chatService.createSendMessageContent(sessionId, chatMessageRequestDto); -// redisTemplate.convertAndSend("meetingRoom", responseDto); -// } + @MessageMapping("/room/{roomName}") @SendTo("/sub/room/{roomName}") public MessageSuccessResponse sendChatMessageInRoom(@DestinationVariable("roomName") final String roomName, @RequestBody final ChatMessageRoomRequestDto chatMessageRoomRequestDto) throws IOException { return MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, chatService.createSendMessageContentInRoom(roomName, chatMessageRoomRequestDto).getMessage()); } -// @MessageMapping("/room/image/{roomName}") -// @SendTo("/sub/room/{roomName}") -// public MessageSuccessResponse sendImageMessageInRoom(@DestinationVariable("roomName") final String roomName, -// @RequestBody final ChatMessageRoomRequestDto chatMessageRoomRequestDto) throws IOException { -// return MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, chatService.createSendMessageContentInRoom(roomName, chatMessageRoomRequestDto).getMessage()); -// } -// @MessageMapping("/room/image/{roomName}") -// @SendTo("/sub/room/{roomName}") -// public MessageSuccessResponse sendImageMessageInRoom(@DestinationVariable("roomName") final String roomName, -// @RequestBody final image image) throws IOException { -// return MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, chatService.createSendImageContentInRoom(roomName, image).getMessage()); -// } -// @MessageMapping("/room/{roomName}") -// public void sendChatMessageInRoom(@DestinationVariable("roomName") final String roomName, -// @RequestBody final ChatMessageRoomRequestDto chatMessageRoomRequestDto) { -// final ChatMessageRoomResponseDto responseDto = chatService.createSendMessageContentInRoom(roomName, chatMessageRoomRequestDto); -// redisTemplate.convertAndSend("meetingRoom", responseDto); -// } -// @MessageMapping("/chat/detail/{sessionId}") -// public void sendChatDetailMessage(@DestinationVariable("sessionId") final String sessionId, -// @RequestBody final ChatMessageListRequestDto chatMessageListRequestDto) { -// final ChatMessageListResponseDto responseDto = chatService.sendChatDetailMessage(sessionId, chatMessageListRequestDto); -// template.convertAndSend("/sub/chat/" + sessionId, MessageSuccessResponse.of(MessageSuccessCode.MESSAGE, responseDto)); -// } -// -// @MessageMapping("/chat/all") -// public void sendUserChatListMessage(@Header("sessionId") final String sessionId, -// @RequestBody final ChatListRequestDto chatListRequestDto) { -// final ChatListResponseDto responseDto = chatService.sendUserChatListMessage(sessionId, chatListRequestDto); -// template.convertAndSend("/sub/chat/" + sessionId, MessageSuccessResponse.of(MessageSuccessCode.CHATLIST, responseDto)); -// } } diff --git a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java index 9c7c2af..a7db8d1 100644 --- a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java +++ b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java @@ -37,7 +37,6 @@ public void sendChatDetailMessage(@DestinationVariable("roomName") final String final RoomMessageListResponseDto responseDto = roomService.sendRoomDetailMessage(roomName); template.convertAndSend("/sub/room/" + roomName, MessageSuccessResponse.of(MessageSuccessCode.MESSAGE, responseDto)); } - // @MessageMapping("/room/all/{sessionId}") public void sendUserChatListMessage(@DestinationVariable("sessionId") final String sessionId) { final RoomListResponseDto responseDto = roomService.sendUserChatListMessage(sessionId); diff --git a/socket/src/main/java/Backend/socket/infra/config/FCMConfig.java b/socket/src/main/java/Backend/socket/infra/config/FCMConfig.java deleted file mode 100644 index 2ae8db7..0000000 --- a/socket/src/main/java/Backend/socket/infra/config/FCMConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -//package Backend.socket.infra.config; -// -//import com.google.auth.oauth2.GoogleCredentials; -//import com.google.firebase.FirebaseApp; -//import com.google.firebase.FirebaseOptions; -//import com.google.firebase.messaging.FirebaseMessaging; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.core.io.ClassPathResource; -// -//import java.io.IOException; -//import java.io.InputStream; -//import java.util.List; -// -//@Configuration -//public class FCMConfig { -// @Bean -// FirebaseMessaging firebaseMessaging() throws IOException { -// ClassPathResource resource = new ClassPathResource("firebase/AccountKey.json"); -// InputStream refreshToken = resource.getInputStream(); -// -// FirebaseApp firebaseApp = null; -// List firebaseAppList = FirebaseApp.getApps(); -// if(firebaseAppList != null && !firebaseAppList.isEmpty()) { -// for (FirebaseApp app : firebaseAppList){ -// if (app.getName().equals(FirebaseApp.DEFAULT_APP_NAME)) { -// firebaseApp = app; -// } -// } -// } else { -// FirebaseOptions options = FirebaseOptions.builder() -// .setCredentials(GoogleCredentials.fromStream(refreshToken)) -// .build(); -// firebaseApp = FirebaseApp.initializeApp(options); -// } -// return FirebaseMessaging.getInstance(firebaseApp); -// } -//} diff --git a/socket/src/main/java/Backend/socket/infra/config/WebConfig.java b/socket/src/main/java/Backend/socket/infra/config/WebConfig.java deleted file mode 100644 index 0207633..0000000 --- a/socket/src/main/java/Backend/socket/infra/config/WebConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -//package Backend.socket.infra.config; -// -//import org.springframework.context.annotation.Configuration; -//import org.springframework.web.servlet.config.annotation.CorsRegistry; -//import org.springframework.web.servlet.config.annotation.EnableWebMvc; -//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -// -//@EnableWebMvc -//@Configuration -//public class WebConfig implements WebMvcConfigurer { -// @Override -// public void addCorsMappings(CorsRegistry registry) { -// registry.addMapping("/**") -// .allowedOrigins("*") -// .allowedMethods("*") -// .exposedHeaders("Access-Control-Allow-Origin", -// "Access-Control-Allow-Methods", -// "Access-Control-Allow-Headers", -// "Access-Control-Max-Age", -// "Access-Control-Request-Headers", -// "Access-Control-Request-Method") -// .allowCredentials(false) -// .maxAge(30000000); -// } -//} diff --git a/socket/src/main/java/Backend/socket/infra/external/AwsService.java b/socket/src/main/java/Backend/socket/infra/external/AwsService.java deleted file mode 100644 index 3c7f0b4..0000000 --- a/socket/src/main/java/Backend/socket/infra/external/AwsService.java +++ /dev/null @@ -1,143 +0,0 @@ -package Backend.socket.infra.external; - - -import Backend.socket.global.error.httpException.InternalServerException; -import Backend.socket.global.error.httpException.InvalidValueException; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import com.amazonaws.services.s3.model.DeleteObjectRequest; -import com.amazonaws.services.s3.model.ObjectMetadata; -import com.amazonaws.services.s3.model.PutObjectRequest; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.server.ResponseStatusException; - -import java.io.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import static Backend.socket.global.error.ErrorCode.INVALID_IMAGE_TYPE; -import static Backend.socket.global.error.ErrorCode.S3_UPLOAD_ERROR; - - -@Slf4j -@RequiredArgsConstructor -@Transactional -@Service -public class AwsService { - @Value("${cloud.aws.s3.bucket}") - private String bucket; - - private final AmazonS3 amazonS3; - - public String uploadImageToS3(String image) throws IOException { - String[] strings = image.split(" "); // ","을 기준으로 바이트 코드를 나눠준다 - String base64Image = strings[1]; - String extension = ""; // if 문을 통해 확장자명을 정해줌 - if (strings[0].equals("data:image/jpeg;base64")) { - extension = "jpeg"; - } else if (strings[0].equals("data:image/png;base64")){ - extension = "png"; - } else { - extension = "jpg"; - } - - -// ... - - byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image); // 바이트 코드를 // 바이트 코드를 - - File tempFile = File.createTempFile("image", "." + extension); // createTempFile을 통해 임시 파일을 생성해준다. (임시파일은 지워줘야함) - try (OutputStream outputStream = new FileOutputStream(tempFile)) { - outputStream.write(imageBytes); // OutputStream outputStream = new FileOutputStream(tempFile)을 통해 생성한 outputStream 객체에 imageBytes를 작성해준다. - } - // 문자열을 공백을 기준으로 분리하여 문자열 배열로 변환 - String[] byteStrings = image.split(" "); - - // byte 배열 생성 - byte[] imageData = new byte[byteStrings.length]; - - for (int i = 0; i < byteStrings.length; i++) { - if (byteStrings[i].matches("-?[0-9]+")) { - imageData[i] = Byte.parseByte(byteStrings[i]); - } else if (byteStrings[i].matches("-?0x[0-9a-fA-F]+")) { - imageData[i] = (byte) Integer.parseInt(byteStrings[i].substring(2), 16); - } else { - // 잘못된 형식의 문자열인 경우 처리할 작업 - imageData[i] = 0; - } - } - - String fileName = UUID.randomUUID().toString(); - String fileUrl = ""; - - try { - ObjectMetadata objectMetadata = new ObjectMetadata(); - objectMetadata.setContentType("image/jpeg"); - objectMetadata.setContentLength(imageData.length); - - InputStream inputStream = new ByteArrayInputStream(imageData); - amazonS3.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata) - .withCannedAcl(CannedAccessControlList.PublicRead)); - - fileUrl = amazonS3.getUrl(bucket, fileName).toString(); - } catch (Exception e) { - e.printStackTrace(); - } - - return fileUrl; - } - - public List uploadImages(List imageDataList) { - if (imageDataList.isEmpty()) - return null; - List fileUrlList = new ArrayList<>(); - - imageDataList.forEach(imageData -> { - String fileName = UUID.randomUUID().toString(); - String fileUrl = ""; - - try { - ObjectMetadata objectMetadata = new ObjectMetadata(); - objectMetadata.setContentType("image/jpeg"); - objectMetadata.setContentLength(imageData.length); - - InputStream inputStream = new ByteArrayInputStream(imageData); - amazonS3.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata) - .withCannedAcl(CannedAccessControlList.PublicRead)); - - fileUrl = amazonS3.getUrl(bucket, fileName).toString(); - } catch (Exception e) { - log.error(e.getMessage()); - throw new InternalServerException(S3_UPLOAD_ERROR); - } - - fileUrlList.add(fileUrl); - }); - - return fileUrlList; - } - public void deleteImage(String fileName) { - amazonS3.deleteObject(new DeleteObjectRequest(bucket, fileName)); - } - public String createFileName(String fileName) { - return UUID.randomUUID().toString().concat(getFileExtension(fileName)); - } - - private String getFileExtension(String fileName) { - try { - return fileName.substring(fileName.lastIndexOf(".")); - } catch(StringIndexOutOfBoundsException e) { - throw new InvalidValueException(INVALID_IMAGE_TYPE); - } - } - -} -