@Override public MessageDTO send( AuthenticationTokenDTO authenticationToken, String text, UserId authorId, ChatId destinationChatId) { User author = userRepository.findOne(authorId.id); Chat destinationChat = chatRepository.findOne(destinationChatId.id); logger.info("fgbvdlhfv"); if (author == null || destinationChat == null) { throw new ObjectIsNotFoundException(); } Message message = new Message(text, author, new Date(), destinationChat, null); if (message.getRecipient() != null) { message.getRecipient().getReceivedMessages().add(message); userRepository.save(message.getRecipient()); } message.getAuthor().getSentMessages().add(message); message.getDestinationChat().getMessages().add(message); userRepository.save(message.getAuthor()); chatRepository.save(message.getDestinationChat()); Message sentMessage = messageRepository.save(message); return new MessageDTO( sentMessage.getId(), sentMessage.getText(), sentMessage.getAuthor().getName(), sentMessage.getPostDate(), null); }
@Override public Collection<MessageDTO> readAllMessagesByChatId( AuthenticationTokenDTO token, ChatId chatId) { Collection<Message> messageEntities; messageEntities = messageRepository.findMessageByChatId(chatId.id, token.ownerId); Collection<MessageDTO> returningMessages = transformToDTO(messageEntities); return returningMessages; }
@Override public Collection<MessageDTO> readAllMessagesByChatIdBetweenTwoDates( AuthenticationTokenDTO token, ChatId id, Date from, Date till) { Collection<Message> messageEntities; messageEntities = messageRepository.findMessageByChatIdBetween(id.id, token.ownerId, from, till); Collection<MessageDTO> returningMessages = transformToDTO(messageEntities); return returningMessages; }