Added custom message repository

This commit is contained in:
Artur Kmieckowiak 2020-01-10 19:47:53 +01:00
parent 3b7f380b57
commit 4109acfab7
4 changed files with 26 additions and 1 deletions

View File

@ -6,7 +6,7 @@ import org.springframework.data.mongodb.repository.Query;
import java.util.List;
public interface MessageRepository extends MongoRepository<MessageDocument, String> {
public interface MessageRepository extends MongoRepository<MessageDocument, String>, MessageRepositoryCustom {
@Query("{ $and: [{'conversationId': ?1} , {$or: [{ 'authorId': ?0 },{ 'recipientId': ?0 }]}] }")
List<MessageDocument> findMessagesForUserAndConversation(String userId, String conversationId); // TODO: Test query or create a repository implementation

View File

@ -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
);
}

View File

@ -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;
}
}

View File

@ -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);
}
}