From 4109acfab7277b61b3be3dbd69f33d8e5452f531 Mon Sep 17 00:00:00 2001 From: Artur Kmieckowiak Date: Fri, 10 Jan 2020 19:47:53 +0100 Subject: [PATCH] Added custom message repository --- .../study/bookapi/repository/MessageRepository.java | 2 +- .../bookapi/repository/MessageRepositoryCustom.java | 11 +++++++++++ .../repository/MessageRepositoryCustomImpl.java | 10 ++++++++++ .../fnecan/study/bookapi/service/MessageService.java | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustom.java create mode 100644 src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustomImpl.java diff --git a/src/main/java/com/fnecan/study/bookapi/repository/MessageRepository.java b/src/main/java/com/fnecan/study/bookapi/repository/MessageRepository.java index 4c0071a..edafc83 100644 --- a/src/main/java/com/fnecan/study/bookapi/repository/MessageRepository.java +++ b/src/main/java/com/fnecan/study/bookapi/repository/MessageRepository.java @@ -6,7 +6,7 @@ import org.springframework.data.mongodb.repository.Query; import java.util.List; -public interface MessageRepository extends MongoRepository { +public interface MessageRepository extends MongoRepository, MessageRepositoryCustom { @Query("{ $and: [{'conversationId': ?1} , {$or: [{ 'authorId': ?0 },{ 'recipientId': ?0 }]}] }") List findMessagesForUserAndConversation(String userId, String conversationId); // TODO: Test query or create a repository implementation diff --git a/src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustom.java b/src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustom.java new file mode 100644 index 0000000..a68b7ff --- /dev/null +++ b/src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustom.java @@ -0,0 +1,11 @@ +package com.fnecan.study.bookapi.repository; + +import com.fnecan.study.bookapi.model.MessageDocument; + +public interface MessageRepositoryCustom { + MessageDocument createMessage( + String message, + String authorId, + String recipientId + ); +} diff --git a/src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustomImpl.java b/src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustomImpl.java new file mode 100644 index 0000000..07899e4 --- /dev/null +++ b/src/main/java/com/fnecan/study/bookapi/repository/MessageRepositoryCustomImpl.java @@ -0,0 +1,10 @@ +package com.fnecan.study.bookapi.repository; + +import com.fnecan.study.bookapi.model.MessageDocument; + +public class MessageRepositoryCustomImpl implements MessageRepositoryCustom { + @Override + public MessageDocument createMessage(String message, String authorId, String recipientId) { + return null; + } +} diff --git a/src/main/java/com/fnecan/study/bookapi/service/MessageService.java b/src/main/java/com/fnecan/study/bookapi/service/MessageService.java index 1da1dcf..4e46f42 100644 --- a/src/main/java/com/fnecan/study/bookapi/service/MessageService.java +++ b/src/main/java/com/fnecan/study/bookapi/service/MessageService.java @@ -21,4 +21,8 @@ public class MessageService { return messageRepository.findMessagesForUserAndConversation(userId, conversationId); } + public MessageDocument createMessage(String message, String authorId, String recipientId) { + return messageRepository.createMessage(message, authorId, recipientId); + } + }