diff --git a/src/main/java/org/ntlab/tampoposerver/repositories/ChatRequestRepository.java b/src/main/java/org/ntlab/tampoposerver/repositories/ChatRequestRepository.java index d45cbb8..08960c5 100644 --- a/src/main/java/org/ntlab/tampoposerver/repositories/ChatRequestRepository.java +++ b/src/main/java/org/ntlab/tampoposerver/repositories/ChatRequestRepository.java @@ -3,7 +3,6 @@ import org.ntlab.tampoposerver.models.ChatRequest; import org.springframework.stereotype.Repository; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -13,19 +12,36 @@ private int id = 0; public ChatRequest addChatRequest(String senderId, String receiverId) { - return null; + ChatRequest chatRequest = new ChatRequest(id, senderId, receiverId); + chatRequests.put(id, chatRequest); + id++; + return chatRequest; } public ChatRequest getChatRequest(int chatRequestId) { return chatRequests.get(chatRequestId); } - public ArrayList getChatRequestsForUser(String userId) { - return null; + public List getChatRequestsForUser(String userId) { + if(userId == null) { + return null; + } + List chatRequestsForUser; + chatRequestsForUser = chatRequests.values().stream().filter(chatReq -> chatReq.getReceiverId().equals(userId) || chatReq.getSenderId().equals(userId)).toList(); + if(chatRequestsForUser.isEmpty()) { + return null; + } + return chatRequestsForUser; } public ChatRequest deleteChatRequest(int chatRequestId) { - return null; + ChatRequest chatRequest = chatRequests.get(chatRequestId); + if(chatRequest == null) { + return null; + } + + chatRequest = chatRequests.remove(chatRequestId); + return chatRequest; } }