Skip to content

Commit

Permalink
Add before and limit params
Browse files Browse the repository at this point in the history
  • Loading branch information
nelifs committed Dec 11, 2024
1 parent 5a66874 commit 280f399
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public MessagesService(MessageRepository messageRepository) {
}

public List<MessageDTO> getMessages(long before, int limit, Channel channel) {
List<Message> messagesArray = messageRepository.findAllByChannel(channel);
List<Message> messagesArray = messageRepository.findAllByChannel(channel, limit);

log.info("MESSAGES ({}, {}) in CHANNEL ({}) found successfully", limit, before, channel.getId());

return messagesArray.stream()
.limit(limit)
.map(message -> new MessageDTO(
message.getId(),
message.getContent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

@Repository
public interface MessageRepository extends CrudRepository<Message, Long> {
List<Message> findAllByChannel(Channel channel);
@Query("SELECT m FROM Message m WHERE m.channel = :ch AND m.timestamp > :before")
List<Message> findAllByChannel(Channel channel, long before);

@Query("SELECT m FROM Message m WHERE m.channel = :ch AND m.id = :id")
Message findByChannelAndId(@Param("ch") Channel channel, @Param("id") long id);
Expand Down

0 comments on commit 280f399

Please sign in to comment.