Skip to content
Extraits de code Groupes Projets
Valider 339d5aac rédigé par oussama aftys's avatar oussama aftys
Parcourir les fichiers

added stream messages exports feature

parent 2190184b
Branches
1 requête de fusion!21added stream messages exports feature
Pipeline #10868 en échec avec les étapes
in 20 secondes
......@@ -83,4 +83,11 @@ public class ChatController {
simpMessagingTemplate.convertAndSend("/topic/messages/" + streamId, new ChatMessageResponse(streamId, senderName, MessageType.BLOCK));
}
@GetMapping("/live/export")
@PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public List<ChatMessageResponse> exportMessagesByStream(@RequestParam(required = true, value = "streamId") Long streamId, @RequestHeader String requestAuthorization) {
return chatService.exportMessagesByStream(streamId);
}
}
......@@ -10,12 +10,17 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.marketingconfort.mydressin.mydressinstreamservices.models.entities.ChatMessage;
import com.marketingconfort.mydressin.mydressinstreamservices.models.enums.MessageType;
import com.marketingconfort.mydressin.mydressinstreamservices.models.dtos.ChatMessageResponse;
@Repository
public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long> {
@Query("SELECT m FROM ChatMessage m WHERE m.liveStream.id = :id AND m.type = com.marketingconfort.mydressin.mydressinstreamservices.models.enums.MessageType.CHAT")
List<ChatMessage> findAllMessagesByLiveStreamId(@Param("id") long id, Pageable pageable);
List<ChatMessage> findMessagesByLiveStreamId(@Param("id") long id, Pageable pageable);
@Query("SELECT new com.marketingconfort.mydressin.mydressinstreamservices.models.dtos.ChatMessageResponse(m.id, m.content, m.senderName) FROM ChatMessage m WHERE m.liveStream.id = :id AND m.type = com.marketingconfort.mydressin.mydressinstreamservices.models.enums.MessageType.CHAT order by m.createdAt desc")
List<ChatMessageResponse> findAllMessagesByLiveStreamId(@Param("id") long id);
@Query("SELECT COUNT(m) FROM ChatMessage m WHERE m.liveStream.id = :liveStream " +
"AND m.createdAt BETWEEN :start AND :end")
......
......@@ -13,4 +13,5 @@ public interface IChatService {
void unpinMessage(long id);
ChatMessageResponse save(ChatMessageRequest messageDto);
void deleteMessage(long id );
List<ChatMessageResponse> exportMessagesByStream(long id);
}
......@@ -17,6 +17,8 @@ import com.marketingconfort.mydressin.mydressinstreamservices.models.repositorie
import com.marketingconfort.mydressin.mydressinstreamservices.models.repositories.LiveStreamRepository;
import com.marketingconfort.mydressin.mydressinstreamservices.services.IChatService;
@Service
@AllArgsConstructor
public class ChatService implements IChatService {
......@@ -44,7 +46,7 @@ public class ChatService implements IChatService {
@Override
public List<ChatMessageResponse> getAllMsgByStream(long id, int page, int size, String sortBy, String sortDir) {
Pageable pageable = PageRequest.of(page, size, Sort.Direction.fromString(sortDir), sortBy);
List<ChatMessage> chatMessages = chatMessageRepository.findAllMessagesByLiveStreamId(id, pageable );
List<ChatMessage> chatMessages = chatMessageRepository.findMessagesByLiveStreamId(id, pageable );
Collections.reverse(chatMessages);
return chatMessages.stream()
.map(ChatMessageResponse::fromEntity)
......@@ -93,4 +95,9 @@ public class ChatService implements IChatService {
throw new IllegalArgumentException("User or LiveStream not found");
}
}
@Override
public List<ChatMessageResponse> exportMessagesByStream(long id) {
return chatMessageRepository.findAllMessagesByLiveStreamId(id);
}
}
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter