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 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-28 21:17:39 +03:00
parent 1a3be8e3ee
commit 45854ef2bd
3 changed files with 52 additions and 1 deletions

View File

@@ -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<String> images;
private PostType type;
private PostStatus status;
private String city;
}

View File

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

View File

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