fixed GeocodingService add alter city

This commit is contained in:
SlimusMinus
2026-08-04 00:33:17 +03:00
parent 619ce7086b
commit 7429515143
12 changed files with 192 additions and 124 deletions

View File

@@ -35,14 +35,13 @@ public class ChatService {
throw new IllegalArgumentException("Нельзя создать чат с самим собой");
}
Long u1 = Math.min(currentUserId, otherUserId);
Long u2 = Math.max(currentUserId, otherUserId);
Long userId1 = Math.min(currentUserId, otherUserId);
Long userId2 = Math.max(currentUserId, otherUserId);
Chat chat = chatRepository.findByUsers(u1, u2)
.orElseGet(() -> {
Chat chat = chatRepository.findByUsers(userId1, userId2).orElseGet(() -> {
Chat newChat = new Chat();
newChat.setUserOneId(u1);
newChat.setUserTwoId(u2);
newChat.setUserOneId(userId1);
newChat.setUserTwoId(userId2);
newChat.setPostId(postId);
return chatRepository.save(newChat);
});
@@ -64,13 +63,12 @@ public class ChatService {
Chat chat = getChatOrThrow(chatId);
checkParticipant(chat, userId);
return messageRepository.findByChatIdOrderByCreatedAtDesc(chatId, pageable)
.map(this::toMessageDto);
return messageRepository.findByChatIdOrderByCreatedAtDesc(chatId, pageable).map(this::toMessageDto);
}
// Отправка сообщения (вызывается из WebSocket контроллера)
@Transactional
public MessageDto sendMessage(Long senderId, Long chatId, String content) {
public void sendMessage(Long senderId, Long chatId, String content) {
Chat chat = getChatOrThrow(chatId);
checkParticipant(chat, senderId);
@@ -89,15 +87,13 @@ public class ChatService {
? chat.getUserTwoId()
: chat.getUserOneId();
long unreadCount = messageRepository
.countByChatIdAndIsReadFalseAndSenderIdNot(chatId, recipientId);
long unreadCount = messageRepository.countByChatIdAndIsReadFalseAndSenderIdNot(chatId, recipientId);
messagingTemplate.convertAndSend(
"/topic/user/" + recipientId + "/unread",
Map.of("chatId", chatId, "unreadCount", unreadCount)
);
return dto;
}
@Transactional
@@ -114,11 +110,9 @@ public class ChatService {
messageRepository.markAsReadByChatIdAndRecipient(chatId, userId);
}
// ---------- вспомогательные методы ----------
private Chat getChatOrThrow(Long chatId) {
return chatRepository.findById(chatId)
.orElseThrow(() -> new IllegalArgumentException("Чат не найден"));
return chatRepository.findById(chatId).orElseThrow(() -> new IllegalArgumentException("Чат не найден"));
}
private void checkParticipant(Chat chat, Long userId) {
@@ -128,8 +122,7 @@ public class ChatService {
}
private ChatDto toDto(Chat chat, Long currentUserId) {
Long otherUserId = chat.getUserOneId().equals(currentUserId)
? chat.getUserTwoId() : chat.getUserOneId();
Long otherUserId = chat.getUserOneId().equals(currentUserId) ? chat.getUserTwoId() : chat.getUserOneId();
ChatDto dto = new ChatDto();
dto.setId(chat.getId());