-
Notifications
You must be signed in to change notification settings - Fork 1
Feature - userId 해싱 #156
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
Open
JiwonHwang01
wants to merge
7
commits into
main
Choose a base branch
from
feature/userIdHashing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature - userId 해싱 #156
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cceadc6
feature: UserService.getUserProfile 유저 id 해싱 #155
JiwonHwang01 a5cb56f
fix: 불필요한 부분 제거 #155
JiwonHwang01 c1fd91f
feature: JwtService 토큰 user_id 해싱 #155
JiwonHwang01 19faaaf
feature: MeetService.updatePaymentStatus user_id 해싱 #155
JiwonHwang01 7ed0e2b
fix: 불필요한 주석 지우기 #156
JiwonHwang01 dafd987
fix: 불필요한 출력문 지우기 #156
JiwonHwang01 81687d3
fix: 코드 컨벤션 맞추기 #156
JiwonHwang01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| package org.ktb.modie.presentation.v1.controller; | ||
|
|
||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.ktb.modie.core.exception.BusinessException; | ||
| import org.ktb.modie.core.exception.CustomErrorCode; | ||
| import org.ktb.modie.core.response.SuccessResponse; | ||
|
|
@@ -22,80 +24,79 @@ | |
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
|
|
||
| @RestController | ||
| public class ChatHistoryController { | ||
|
|
||
| private final ChatRepository chatRepository; | ||
| private final UserRepository userRepository; | ||
| private final MeetRepository meetRepository; // MeetRepository 추가 | ||
| private final HashIdUtil hashIdUtil; | ||
|
|
||
| // 생성자 수정: MeetRepository도 주입받도록 수정 | ||
| public ChatHistoryController(ChatRepository chatRepository, UserRepository userRepository, | ||
| MeetRepository meetRepository, HashIdUtil hashIdUtil) { | ||
| this.chatRepository = chatRepository; | ||
| this.userRepository = userRepository; | ||
| this.meetRepository = meetRepository; | ||
| this.hashIdUtil = hashIdUtil; | ||
| } | ||
|
|
||
| @GetMapping("/api/v1/chat/{meetId}") | ||
| public ResponseEntity<SuccessResponse<List<ChatDto>>> getChatHistory( | ||
| @PathVariable("meetId") String meetHashId, | ||
| @RequestParam(value = "lastChatId", required = false) Long lastChatId, | ||
| @RequestAttribute("userId") String loggedInUserId, | ||
| HttpServletRequest request) { | ||
|
|
||
| Long meetId = hashIdUtil.decode(meetHashId); | ||
| System.out.println("getChatHistory start !! "); | ||
| // 유저 정보 보완 (userId로 DB에서 조회) | ||
| meetRepository.findById(meetId) | ||
| .orElseThrow(() -> new BusinessException( | ||
| CustomErrorCode.MEETING_NOT_FOUND, | ||
| "알 수 없는 모임입니다." | ||
| )); | ||
|
|
||
| List<Chat> chatList; | ||
| Pageable pageable = PageRequest.of(0, 25); | ||
|
|
||
| if (lastChatId == null || lastChatId == 0) { | ||
| chatList = chatRepository.findTop25ByMeetIdOrderByCreatedAtDesc(meetId, pageable); | ||
| } else { | ||
| chatList = chatRepository.findByMeetIdAndMessageIdLessThanOrderByCreatedAtDesc(meetId, lastChatId, | ||
| pageable); | ||
| } | ||
|
|
||
| List<ChatDto> chatDtoList = chatList.stream() | ||
| .map(chat -> { | ||
| User user = chat.getUser(); | ||
| Meet meet = chat.getMeet(); | ||
|
|
||
| // 방장 여부 확인 | ||
| boolean isOwner = meet.getOwner().getUserId().equals(chat.getUser().getUserId()); | ||
|
|
||
| // 본인 여부 확인 | ||
| boolean isMe = chat.getUser().getUserId().equals(loggedInUserId); | ||
|
|
||
| // 변경된 DTO 필드명에 맞춰 생성자 호출 | ||
| return new ChatDto( | ||
| // chat.getMessageId().longValue(), // chatId | ||
| chat.getMessageId(), // chatId | ||
| (chat.getUser().getUserId()), // userId | ||
| chat.getMessageContent(), // content (이전의 message) | ||
| user.getUserName(), // nickname (이전의 sender) | ||
| chat.getCreatedAt().toString().split("\\.")[0], // dateTime | ||
| meetHashId, // meetId | ||
| isOwner, // isOwner | ||
| isMe // isMe | ||
| ); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| System.out.println("chatDtoList size : " + chatDtoList.size()); | ||
|
|
||
| return SuccessResponse.of(chatDtoList).asHttp(HttpStatus.OK); | ||
| } | ||
| private final ChatRepository chatRepository; | ||
| private final UserRepository userRepository; | ||
| private final MeetRepository meetRepository; // MeetRepository 추가 | ||
| private final HashIdUtil hashIdUtil; | ||
|
|
||
| // 생성자 수정: MeetRepository도 주입받도록 수정 | ||
| public ChatHistoryController(ChatRepository chatRepository, UserRepository userRepository, | ||
| MeetRepository meetRepository, HashIdUtil hashIdUtil) { | ||
| this.chatRepository = chatRepository; | ||
| this.userRepository = userRepository; | ||
| this.meetRepository = meetRepository; | ||
| this.hashIdUtil = hashIdUtil; | ||
| } | ||
|
|
||
| @GetMapping("/api/v1/chat/{meetId}") | ||
| public ResponseEntity<SuccessResponse<List<ChatDto>>> getChatHistory( | ||
| @PathVariable("meetId") String meetHashId, | ||
| @RequestParam(value = "lastChatId", required = false) Long lastChatId, | ||
| @RequestAttribute("userId") String loggedInUserId, | ||
| HttpServletRequest request) { | ||
|
|
||
| Long meetId = hashIdUtil.decode(meetHashId); | ||
| System.out.println("getChatHistory start !! "); | ||
|
Member
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. 출력문 지우기 ! |
||
| // 유저 정보 보완 (userId로 DB에서 조회) | ||
| meetRepository.findById(meetId) | ||
| .orElseThrow(() -> new BusinessException( | ||
| CustomErrorCode.MEETING_NOT_FOUND, | ||
| "알 수 없는 모임입니다." | ||
| )); | ||
|
|
||
| List<Chat> chatList; | ||
| Pageable pageable = PageRequest.of(0, 25); | ||
|
|
||
| if (lastChatId == null || lastChatId == 0) { | ||
| chatList = chatRepository.findTop25ByMeetIdOrderByCreatedAtDesc(meetId, pageable); | ||
| } else { | ||
| chatList = chatRepository.findByMeetIdAndMessageIdLessThanOrderByCreatedAtDesc(meetId, lastChatId, | ||
| pageable); | ||
|
Member
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. 120자를 초과해서 줄을 띄워야할 때 파라미터를 모두 한 줄에 두면 더 보기 쉬울 거 같습니다 ! pageable만 다른 줄이 아닌 meetId도 다른 줄에 있도록 ! |
||
| } | ||
|
|
||
| List<ChatDto> chatDtoList = chatList.stream() | ||
| .map(chat -> { | ||
| User user = chat.getUser(); | ||
| Meet meet = chat.getMeet(); | ||
|
|
||
| // 방장 여부 확인 | ||
| boolean isOwner = meet.getOwner().getUserId().equals(chat.getUser().getUserId()); | ||
|
|
||
| // 본인 여부 확인 | ||
| boolean isMe = chat.getUser().getUserId().equals(loggedInUserId); | ||
|
|
||
| // 변경된 DTO 필드명에 맞춰 생성자 호출 | ||
| String userHashId = hashIdUtil.encode(Long.parseLong(user.getUserId())); | ||
| return new ChatDto( | ||
| chat.getMessageId(), // chatId | ||
| userHashId, // userId | ||
| chat.getMessageContent(), // content (이전의 message) | ||
| user.getUserName(), // nickname (이전의 sender) | ||
| chat.getCreatedAt().toString().split("\\.")[0], // dateTime | ||
| meetHashId, // meetId | ||
| isOwner, // isOwner | ||
| isMe // isMe | ||
| ); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| System.out.println("chatDtoList size : " + chatDtoList.size()); | ||
|
|
||
| return SuccessResponse.of(chatDtoList).asHttp(HttpStatus.OK); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
주석 지우기 !
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.
주석 지웠습니다 감삼당!