-
Notifications
You must be signed in to change notification settings - Fork 0
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 : 뿌리오 메시지 관련 로직 일부 #26
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.pictalk.message.controller; | ||
|
||
import com.pictalk.message.dto.MessageRequestDto; | ||
import com.pictalk.message.service.MessageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/messages") | ||
public class MessageController { | ||
|
||
private final MessageService messageService; | ||
|
||
// 메시지 발송 | ||
@PostMapping | ||
public void sendMessage(@RequestBody MessageRequestDto.CommonMessage commonMessage) { | ||
// 메시지 전송 로직 | ||
messageService.requestSend(commonMessage); | ||
} | ||
|
||
// @PostMapping | ||
// public void kkaoSendMessage(@RequestBody MessageRequestDto.kkaoMessage kkaoMessage) { | ||
// // 카카오 메시지 전송 로직 | ||
// messageService.requestSend(kkaoMessage); | ||
// } | ||
|
||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.pictalk.message.domain; | ||
|
||
public class Request { | ||
|
||
private String requestUri; | ||
private String authorization; | ||
|
||
public Request(String requestUri, String authorization) { | ||
this.requestUri = requestUri; | ||
this.authorization = authorization; | ||
} | ||
|
||
public String getRequestUri() { | ||
return requestUri; | ||
} | ||
|
||
public String getAuthorization() { | ||
return authorization; | ||
} | ||
|
||
} | ||
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. 코드는 전반적으로 잘 작성되어 있습니다. 하지만 몇 가지 개선 사항을 제안합니다.
이러한 점들을 반영하면 코드의 안정성과 가독성을 높일 수 있습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.pictalk.message.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
public class MessageRequestDto { | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public static class CommonMessage { | ||
private String messageType; | ||
private String content; | ||
private String from; | ||
private String duplicateFlag; | ||
private int targetCount; | ||
private List<TargetDto> targets; | ||
private String refKey; | ||
private String rejectType; | ||
private String sendTime; | ||
private String subject; | ||
private List<FileDto> files; | ||
|
||
} | ||
|
||
|
||
public static class TargetDto { | ||
private String to; | ||
private Map<String, String> changeWord; | ||
private String name; | ||
} | ||
|
||
public static class FileDto { | ||
private String name; | ||
private long size; | ||
private String data; | ||
|
||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public static class kkaoMessage { | ||
private String account; | ||
private String messageType; | ||
private String senderProfile; | ||
private String templateCode; | ||
private String content; | ||
private Long targetCount; | ||
private List<String> targets; | ||
private String senderNumber; | ||
} | ||
|
||
} | ||
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. 코드 리뷰 결과, 몇 가지 수정 및 개선 사항을 제안드립니다.
리팩토링을 통해 코드의 가독성을 높이고 유지보수를 쉽게 하기를 권장합니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.pictalk.message.dto; | ||
|
||
public class MessageResponseDto { | ||
} | ||
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. 코드에서 다음과 같은 부분들을 개선할 수 있습니다:
예시: package com.pictalk.message.dto;
public class MessageResponseDto {
private Long messageId;
private String content;
private Long senderId;
// 생성자
public MessageResponseDto(Long messageId, String content, Long senderId) {
this.messageId = messageId;
this.content = content;
this.senderId = senderId;
}
// Getter 및 Setter
public Long getMessageId() {
return messageId;
}
public void setMessageId(Long messageId) {
this.messageId = messageId;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Long getSenderId() {
return senderId;
}
public void setSenderId(Long senderId) {
this.senderId = senderId;
}
// toString(), equals(), hashCode() 추가 가능
} 이렇게 하면 이 클래스의 활용도가 높아지고 유지보수하기 쉬운 코드가 됩니다. |
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.
코드에서 수정이 필요하거나 개선할 수 있는 부분은 다음과 같습니다.
메소드 분리: 현재
sendMessage
메소드가commonMessage
와 카카오 메시지 모두를 처리하려는 의도가 보입니다. 각 메시지 유형에 대한 메소드를 명확히 분리하는 것이 좋습니다. 주석 처리된kkaoSendMessage
메소드를 복원하고, 두 메소드를 별도로 유지하세요.HTTP 응답 상태 코드: 현재
sendMessage
메소드는 HTTP 응답을 반환하지 않습니다. 성공적인 요청에는ResponseEntity
를 이용해 적절한 상태 코드(예: 201 Created)를 반환하는 것이 좋습니다.예외 처리: 메시지 발송 중 오류가 발생할 경우 사용할 예외 처리가 없습니다.
@ControllerAdvice
또는 특정 예외 핸들러를 통해 사용자 친화적인 에러 메시지와 적절한 상태 코드를 반환하도록 개선할 수 있습니다.DTO 클래스 패키지 구조: DTO 클래스 이름(
MessageRequestDto.CommonMessage
,MessageRequestDto.kkaoMessage
)이 사용하기에 가독성이 떨어질 수 있습니다. 각 메시지 타입에 대해 별도의 DTO 클래스를 만드는 것을 검토해보세요.API 문서화: Swagger 등의 도구를 활용하여 API 문서화를 진행하면 클라이언트와의 통신 시 이해도를 높일 수 있습니다.
수정된 코드 예시는 다음과 같습니다:
위와 같이 개선하여 코드의 가독성과 유지보수성을 높일 수 있습니다.