From 45854ef2bd1d6f1be979683bdc1b11710fb5858e Mon Sep 17 00:00:00 2001 From: SlimusMinus Date: Wed, 28 Oct 2026 21:17:39 +0300 Subject: [PATCH] Add type, status and city to chat post summary Lets the chat list tell apart chats about similar listings and mark closed ones. The full listing is still loaded on demand via GET /posts/{id}. Co-Authored-By: Claude Opus 5.5 --- .../com/krylov/refound/dto/ChatPostDto.java | 11 +++++- .../krylov/refound/service/ChatService.java | 3 ++ .../refound/service/ChatServiceTest.java | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/krylov/refound/dto/ChatPostDto.java b/src/main/java/com/krylov/refound/dto/ChatPostDto.java index a84ac61..f5f2c8a 100644 --- a/src/main/java/com/krylov/refound/dto/ChatPostDto.java +++ b/src/main/java/com/krylov/refound/dto/ChatPostDto.java @@ -1,12 +1,21 @@ package com.krylov.refound.dto; +import com.krylov.refound.enums.PostStatus; +import com.krylov.refound.enums.PostType; import java.util.List; import lombok.Data; -/** Краткая информация об объявлении для списка чатов. */ +/** + * Краткая информация об объявлении для списка чатов: достаточно, чтобы отличить + * чаты по похожим объявлениям (тип, город, закрыто ли). Полное объявление + * фронт догружает по клику через GET /api/v1/posts/{id}. + */ @Data public class ChatPostDto { private Long id; private String title; private List images; + private PostType type; + private PostStatus status; + private String city; } diff --git a/src/main/java/com/krylov/refound/service/ChatService.java b/src/main/java/com/krylov/refound/service/ChatService.java index dbd1f40..238eda3 100644 --- a/src/main/java/com/krylov/refound/service/ChatService.java +++ b/src/main/java/com/krylov/refound/service/ChatService.java @@ -274,6 +274,9 @@ public class ChatService { postDto.setId(post.getId()); postDto.setTitle(post.getTitle()); postDto.setImages(post.getImages().stream().map(Image::getUrl).toList()); + postDto.setType(post.getType()); + postDto.setStatus(post.getStatus()); + postDto.setCity(post.getCity()); dto.setPost(postDto); } diff --git a/src/test/java/com/krylov/refound/service/ChatServiceTest.java b/src/test/java/com/krylov/refound/service/ChatServiceTest.java index 6aa53b3..dd9d195 100644 --- a/src/test/java/com/krylov/refound/service/ChatServiceTest.java +++ b/src/test/java/com/krylov/refound/service/ChatServiceTest.java @@ -14,6 +14,8 @@ import com.krylov.refound.entity.Chat; import com.krylov.refound.entity.Message; import com.krylov.refound.entity.Post; import com.krylov.refound.entity.User; +import com.krylov.refound.enums.PostStatus; +import com.krylov.refound.enums.PostType; import com.krylov.refound.exception.ApiException; import com.krylov.refound.repository.ChatRepository; import com.krylov.refound.repository.MessageRepository; @@ -145,4 +147,41 @@ class ChatServiceTest { assertThat(chats.get(1).getOtherUserName()).isEqualTo("Боб Иванов"); org.mockito.Mockito.verify(userRepository, org.mockito.Mockito.times(1)).findAllById(any()); } + + @Test + void chatListCarriesPostSummaryAndToleratesDeletedPost() { + Chat withPost = new Chat(); + withPost.setId(1L); + withPost.setUserOneId(14L); + withPost.setUserTwoId(19L); + withPost.setPostId(41L); + Chat deletedPost = new Chat(); + deletedPost.setId(2L); + deletedPost.setUserOneId(14L); + deletedPost.setUserTwoId(19L); + deletedPost.setPostId(42L); + when(chatRepository.findAllByUserId(14L)).thenReturn(List.of(withPost, deletedPost)); + when(userRepository.findAllById(any())).thenReturn(List.of()); + Post post = new Post(); + post.setId(41L); + post.setTitle("Шляпа"); + post.setType(PostType.FOUND); + post.setStatus(PostStatus.CLOSED); + post.setCity("Москва"); + when(postRepository.findAllById(any())).thenReturn(List.of(post)); + when(messageRepository.findLastMessages(any())).thenReturn(List.of()); + when(messageRepository.countUnreadByChat(any(), org.mockito.ArgumentMatchers.eq(14L))).thenReturn(List.of()); + + List chats = chatService.getUserChats(14L); + + ChatDto first = chats.stream().filter(c -> c.getId() == 1L).findFirst().orElseThrow(); + assertThat(first.getPost().getTitle()).isEqualTo("Шляпа"); + assertThat(first.getPost().getType()).isEqualTo(PostType.FOUND); + assertThat(first.getPost().getStatus()).isEqualTo(PostStatus.CLOSED); + assertThat(first.getPost().getCity()).isEqualTo("Москва"); + // Объявление удалено: postId остаётся, краткой карточки нет — фронт покажет «удалено» + ChatDto second = chats.stream().filter(c -> c.getId() == 2L).findFirst().orElseThrow(); + assertThat(second.getPostId()).isEqualTo(42L); + assertThat(second.getPost()).isNull(); + } }