fixed address for map
This commit is contained in:
@@ -16,6 +16,7 @@ public class PostResponse {
|
|||||||
private String category;
|
private String category;
|
||||||
private String city;
|
private String city;
|
||||||
private String district;
|
private String district;
|
||||||
|
private String address;
|
||||||
// Координаты нужны фронту, чтобы кнопка «место на карте» открывала точку
|
// Координаты нужны фронту, чтобы кнопка «место на карте» открывала точку
|
||||||
// объявления, а не общий вид карты. Без этих полей /detail/{id} отдавал
|
// объявления, а не общий вид карты. Без этих полей /detail/{id} отдавал
|
||||||
// null, и MapView падал на дефолтный центр.
|
// null, и MapView падал на дефолтный центр.
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class AdminPostResponse {
|
|||||||
private String category;
|
private String category;
|
||||||
private String city;
|
private String city;
|
||||||
private String district;
|
private String district;
|
||||||
|
private String address;
|
||||||
private Double latitude;
|
private Double latitude;
|
||||||
private Double longitude;
|
private Double longitude;
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ public class Post {
|
|||||||
private PostCategory category;
|
private PostCategory category;
|
||||||
private String city;
|
private String city;
|
||||||
private String district;
|
private String district;
|
||||||
|
// Полный адрес из формы; city/district — нормализованные данные геокодера
|
||||||
|
@Column(length = 500)
|
||||||
|
private String address;
|
||||||
private Double latitude;
|
private Double latitude;
|
||||||
private Double longitude;
|
private Double longitude;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ public class PostService {
|
|||||||
post.setStatus(PostStatus.MODERATION);
|
post.setStatus(PostStatus.MODERATION);
|
||||||
post.setUser(currentUser);
|
post.setUser(currentUser);
|
||||||
post.setIsReward(request.getReward());
|
post.setIsReward(request.getReward());
|
||||||
|
// Адрес из формы сохраняем как есть; геокодер заполняет только city/district
|
||||||
|
post.setAddress(normalizeAddress(request.getAddress()));
|
||||||
if (request.getLatitude() == null || request.getLongitude() == null) {
|
if (request.getLatitude() == null || request.getLongitude() == null) {
|
||||||
post.setCity(request.getAddress());
|
post.setCity(request.getAddress());
|
||||||
} else {
|
} else {
|
||||||
@@ -199,6 +201,7 @@ public class PostService {
|
|||||||
post.setType(request.getType());
|
post.setType(request.getType());
|
||||||
post.setIsReward(request.getReward());
|
post.setIsReward(request.getReward());
|
||||||
post.setReward(request.getRewardText());
|
post.setReward(request.getRewardText());
|
||||||
|
post.setAddress(normalizeAddress(request.getAddress()));
|
||||||
|
|
||||||
if (request.getLatitude() != null && request.getLongitude() != null) {
|
if (request.getLatitude() != null && request.getLongitude() != null) {
|
||||||
post.setLatitude(request.getLatitude());
|
post.setLatitude(request.getLatitude());
|
||||||
@@ -410,4 +413,8 @@ public class PostService {
|
|||||||
|
|
||||||
return toResponse(post, true);
|
return toResponse(post, true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private static String normalizeAddress(String address) {
|
||||||
|
return StringUtils.hasText(address) ? address.trim() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ public class AdminPostService {
|
|||||||
if (StringUtils.hasText(category)) {
|
if (StringUtils.hasText(category)) {
|
||||||
post.setCategory(PostCategory.fromDisplayName(category));
|
post.setCategory(PostCategory.fromDisplayName(category));
|
||||||
}
|
}
|
||||||
|
if (StringUtils.hasText(address)) {
|
||||||
|
post.setAddress(address.trim());
|
||||||
|
}
|
||||||
if (latitude != null && longitude != null) {
|
if (latitude != null && longitude != null) {
|
||||||
post.setLatitude(latitude);
|
post.setLatitude(latitude);
|
||||||
post.setLongitude(longitude);
|
post.setLongitude(longitude);
|
||||||
@@ -303,6 +306,7 @@ public class AdminPostService {
|
|||||||
.category(post.getCategory() == null ? null : post.getCategory().getDisplayName())
|
.category(post.getCategory() == null ? null : post.getCategory().getDisplayName())
|
||||||
.city(post.getCity())
|
.city(post.getCity())
|
||||||
.district(post.getDistrict())
|
.district(post.getDistrict())
|
||||||
|
.address(post.getAddress())
|
||||||
.latitude(post.getLatitude())
|
.latitude(post.getLatitude())
|
||||||
.longitude(post.getLongitude())
|
.longitude(post.getLongitude())
|
||||||
.phone(post.getPhone())
|
.phone(post.getPhone())
|
||||||
|
|||||||
@@ -30,3 +30,4 @@ databaseChangeLog:
|
|||||||
- include: { file: db/changelog/add/017-messages-chat-id.yaml }
|
- include: { file: db/changelog/add/017-messages-chat-id.yaml }
|
||||||
- include: { file: db/changelog/alter/014-posts-rules-accepted-type.yaml }
|
- include: { file: db/changelog/alter/014-posts-rules-accepted-type.yaml }
|
||||||
- include: { file: db/changelog/alter/015-chats-unique-per-post.yaml }
|
- include: { file: db/changelog/alter/015-chats-unique-per-post.yaml }
|
||||||
|
- include: { file: db/changelog/add/018-add-address-posts.yaml }
|
||||||
|
|||||||
@@ -284,6 +284,23 @@ class AdminPostServiceTest {
|
|||||||
assertThat(post.getCity()).isEqualTo("Тверь");
|
assertThat(post.getCity()).isEqualTo("Тверь");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updatePost_keepsClientAddressAndTakesCityFromGeocoder() {
|
||||||
|
Post post = post(1L, PostStatus.ACTIVE);
|
||||||
|
when(postRepository.findById(1L)).thenReturn(java.util.Optional.of(post));
|
||||||
|
when(postRepository.save(any(Post.class))).thenAnswer(inv -> inv.getArgument(0));
|
||||||
|
when(geocodingService.getAddress("55.0", "37.0"))
|
||||||
|
.thenReturn(new com.krylov.refound.dto.AddressInfo("Москва", "Тверской район"));
|
||||||
|
|
||||||
|
AdminPostResponse dto = service.updatePost(1L, "LOSS", "Кот", " Москва, Тверская улица, 7 ",
|
||||||
|
55.0, 37.0, null, null, null, false, null, List.of(), "[]");
|
||||||
|
|
||||||
|
assertThat(post.getAddress()).isEqualTo("Москва, Тверская улица, 7");
|
||||||
|
assertThat(post.getCity()).isEqualTo("Москва");
|
||||||
|
assertThat(post.getDistrict()).isEqualTo("Тверской район");
|
||||||
|
assertThat(dto.getAddress()).isEqualTo("Москва, Тверская улица, 7");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateStatus_closesPostAndIncrementsStatistics() {
|
void updateStatus_closesPostAndIncrementsStatistics() {
|
||||||
Post post = post(1L, PostStatus.ACTIVE);
|
Post post = post(1L, PostStatus.ACTIVE);
|
||||||
|
|||||||
Reference in New Issue
Block a user