-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 쪽지 API 구현
- Loading branch information
Showing
17 changed files
with
637 additions
and
12 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
src/main/java/com/umc/networkingService/domain/message/controller/MessageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.umc.networkingService.domain.message.controller; | ||
|
||
|
||
import com.umc.networkingService.config.security.auth.CurrentMember; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.message.dto.request.MessageRequest; | ||
import com.umc.networkingService.domain.message.dto.response.MessageResponse; | ||
import com.umc.networkingService.domain.message.facade.MessageFacade; | ||
import com.umc.networkingService.global.common.base.BaseResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Slf4j | ||
@Tag(name = "채팅 API", description = "채팅 관련 API") | ||
@RestController | ||
@Validated | ||
@RequestMapping("/messages") | ||
@RequiredArgsConstructor | ||
public class MessageController { | ||
|
||
|
||
private final MessageFacade messageFacade; | ||
|
||
@Operation(summary = "쪽지 작성 API",description = "쪽지 작성 API") | ||
@PostMapping("/{messageRoomId}") | ||
@ApiResponses( value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
@ApiResponse(responseCode = "MESSAGE002", description = "존재하지 않는 쪽지방"), | ||
}) | ||
public BaseResponse<MessageResponse.MessageId> | ||
postMessage( | ||
@CurrentMember Member member, | ||
@PathVariable UUID messageRoomId, | ||
@RequestBody MessageRequest.Message message | ||
){ | ||
return BaseResponse.onSuccess(messageFacade.postMessage(member, messageRoomId, message)); | ||
} | ||
|
||
@Operation(summary = "쪽지 수정 API",description = "쪽지 수정 API") | ||
@PatchMapping("/{messageId}") | ||
@ApiResponses( value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
@ApiResponse(responseCode = "MESSAGE001", description = "존재하지 않는 쪽지") | ||
}) | ||
public BaseResponse<MessageResponse.MessageId> | ||
patchMessage( | ||
@CurrentMember Member member, | ||
@PathVariable UUID messageId, | ||
@RequestBody MessageRequest.Message message | ||
){ | ||
return BaseResponse.onSuccess(messageFacade.patchMessage(member, messageId, message)); | ||
} | ||
|
||
@Operation(summary = "쪽지 삭제 API",description = "쪽지 삭제 API") | ||
@DeleteMapping("/{messageId}") | ||
@ApiResponses( value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
@ApiResponse(responseCode = "MESSAGE001", description = "존재하지 않는 쪽지") | ||
}) | ||
public BaseResponse<MessageResponse.MessageId> | ||
deleteMessage( | ||
@CurrentMember Member member, | ||
@PathVariable UUID messageId | ||
){ | ||
return BaseResponse.onSuccess(messageFacade.deleteMessage(member, messageId)); | ||
} | ||
|
||
@Operation(summary = "쪽지 상세 조회 API",description = "쪽지 상세 조회 API (페이지 0부터 시작) (isAnonymous가 true일 경우 익명인 메시지))") | ||
@GetMapping("/{messageRoomId}") | ||
@ApiResponses( value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
@ApiResponse(responseCode = "MESSAGE002", description = "존재하지 않는 쪽지방"), | ||
@ApiResponse(responseCode = "COMMON500", description = "페이지 에러, 0<=page를 입력해주세요") | ||
}) | ||
public BaseResponse<MessageResponse.JoinMessages> | ||
joinMessages( | ||
@CurrentMember Member member, | ||
@PathVariable UUID messageRoomId, | ||
@RequestParam(name= "page") int page //페이징 처리 | ||
){ | ||
return BaseResponse.onSuccess(messageFacade.joinMessages(member, messageRoomId, page)); | ||
} | ||
|
||
@Operation(summary = "쪽지함 조회 API",description = "쪽지함 조회 API (isAnonymous가 true일 경우 상대가 익명인 메시지)") | ||
@GetMapping("") | ||
@ApiResponses( value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
@ApiResponse(responseCode = "MESSAGE005", description = "최신 쪽지를 찾을 수 없습니다."), | ||
}) | ||
public BaseResponse<MessageResponse.JoinMessageRooms> | ||
joinMessageRooms( | ||
@CurrentMember Member member | ||
){ | ||
return BaseResponse.onSuccess(messageFacade.joinMessageRooms(member)); | ||
} | ||
|
||
@Operation(summary = "쪽지 시작하기 API",description = "쪽지 시작하기 API") | ||
@PostMapping("") | ||
@ApiResponses( value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
@ApiResponse(responseCode = "MESSAGE003", description = "이미 존재하는 쪽지방"), | ||
@ApiResponse(responseCode = "MESSAGE004", description = "보내는 메시지가 없음") | ||
}) | ||
public BaseResponse<MessageResponse.MessageRoomId> | ||
startMessage( | ||
@CurrentMember Member member, | ||
@RequestBody MessageRequest.StartMessageRoom messageRoom | ||
){ | ||
return BaseResponse.onSuccess(messageFacade.createMessageRoom(member, messageRoom.getMessageRoomUserId(), messageRoom.getIsAnonymous(), messageRoom.getMessageContent())); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/umc/networkingService/domain/message/dto/request/MessageRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.umc.networkingService.domain.message.dto.request; | ||
|
||
import com.umc.networkingService.global.common.enums.Semester; | ||
import lombok.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.UUID; | ||
|
||
public class MessageRequest { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor // 쪽지 생성, 수정 | ||
public static class Message { | ||
//todo: 글자수 제한 | ||
String message; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor // 쪽지방 생성 | ||
public static class StartMessageRoom{ | ||
@NonNull | ||
UUID messageRoomUserId; | ||
Boolean isAnonymous; //기본적으로 실명 | ||
@NonNull | ||
String messageContent; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/umc/networkingService/domain/message/dto/response/MessageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.umc.networkingService.domain.message.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class MessageResponse { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class JoinMessageRooms { //쪽지함 조회 | ||
List<JoinMessageRoom> messageRooms; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class JoinMessageRoom{ | ||
UUID messageRoomId; | ||
UUID messageRoomUserId; | ||
String messageRoomUserName; | ||
String recentMessage; | ||
String recentMessageTime; | ||
Boolean isAnonymous; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class JoinMessages { //쪽지 조회 | ||
List<JoinMessage> JoinMessage; | ||
UUID messageRoomId; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class JoinMessage | ||
{ | ||
UUID messageId; | ||
String message; | ||
String messageTime; | ||
String messageMemberName; | ||
UUID messageMemberId; | ||
Boolean isAnonymous; //해당 메시지의 주인이 익명인지 | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class MessageRoomId | ||
{ | ||
UUID messageRoomId; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class MessageId | ||
{ | ||
UUID messageId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/umc/networkingService/domain/message/facade/MessageFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.umc.networkingService.domain.message.facade; | ||
|
||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.message.dto.request.MessageRequest; | ||
import com.umc.networkingService.domain.message.dto.response.MessageResponse; | ||
import com.umc.networkingService.domain.message.service.MessageRoomService; | ||
import com.umc.networkingService.domain.message.service.MessageService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MessageFacade { | ||
|
||
private final MessageService messageService; | ||
private final MessageRoomService messageRoomService; | ||
|
||
public MessageResponse.MessageId postMessage(Member sender, UUID messageRoomId, MessageRequest.Message message) { | ||
return messageService.postMessage(sender, messageRoomId, message, messageRoomService); | ||
} | ||
|
||
public MessageResponse.MessageId patchMessage(Member member, UUID messageId, MessageRequest.Message message) { | ||
return messageService.patchMessage(member, messageId, message); | ||
} | ||
|
||
public MessageResponse.MessageId deleteMessage(Member member, UUID messageId) { | ||
return messageService.deleteMessage(member, messageId); | ||
} | ||
|
||
public MessageResponse.JoinMessages joinMessages(Member member, UUID messageRoomId, int page) { | ||
return messageService.joinMessages(member, messageRoomId, page, messageRoomService); | ||
} | ||
|
||
public MessageResponse.MessageRoomId createMessageRoom(Member member, UUID receiverId, boolean isAnonymous, String content){ | ||
MessageResponse.MessageRoomId resposnse = messageRoomService.createMessageRoom(member, receiverId, isAnonymous, content); | ||
messageService.postMessage(member, resposnse.getMessageRoomId(), MessageRequest.Message.builder().message(content).build(), messageRoomService); | ||
return resposnse; | ||
} | ||
|
||
public MessageResponse.JoinMessageRooms joinMessageRooms(Member member) { | ||
return messageRoomService.joinMessageRooms(member, messageService); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/umc/networkingService/domain/message/mapper/MessageMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.umc.networkingService.domain.message.mapper; | ||
|
||
import com.umc.networkingService.domain.member.entity.Member; | ||
import com.umc.networkingService.domain.message.dto.response.MessageResponse; | ||
import com.umc.networkingService.domain.message.entity.Message; | ||
import com.umc.networkingService.domain.message.entity.MessageRoom; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
|
||
|
||
public class MessageMapper { | ||
|
||
//쪽지방 리스트 조회ㅓ | ||
public static MessageResponse.JoinMessageRoom toJoinMessageRoom(MessageRoom messageRoom, Message recentMessage, Member messageRoomUser){ | ||
return MessageResponse.JoinMessageRoom.builder() | ||
.messageRoomId(messageRoom.getId()) | ||
.messageRoomUserId(messageRoomUser.getId()) | ||
.messageRoomUserName(messageRoomUser.getNickname()+"/"+messageRoomUser.getName()) | ||
.recentMessage(recentMessage.getContent()) | ||
.recentMessageTime( | ||
recentMessage.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")) | ||
) | ||
.isAnonymous(messageRoom.getIsAnonymous()&&messageRoom.getSender().getId().equals(messageRoomUser.getId())) | ||
.build(); | ||
|
||
} | ||
} |
Oops, something went wrong.