added searchMap methods
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.krylov.refound.controller;
|
||||
|
||||
import com.krylov.refound.dto.MapMarkerDto;
|
||||
import com.krylov.refound.service.MapService;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1")
|
||||
public class MapController {
|
||||
|
||||
private final MapService mapService;
|
||||
|
||||
@GetMapping("/posts/map")
|
||||
public List<MapMarkerDto> getMapMarkers(@RequestParam(required = false) String type, @RequestParam(required = false) String category) {
|
||||
return mapService.findAllWithCoordinates(type, category);
|
||||
}
|
||||
|
||||
}
|
||||
12
src/main/java/com/krylov/refound/dto/ChatPostDto.java
Normal file
12
src/main/java/com/krylov/refound/dto/ChatPostDto.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.krylov.refound.dto;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
/** Краткая информация об объявлении для списка чатов. */
|
||||
@Data
|
||||
public class ChatPostDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
private List<String> images;
|
||||
}
|
||||
12
src/main/java/com/krylov/refound/dto/MapMarkerDto.java
Normal file
12
src/main/java/com/krylov/refound/dto/MapMarkerDto.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.krylov.refound.dto;
|
||||
|
||||
import com.krylov.refound.enums.PostType;
|
||||
|
||||
public record MapMarkerDto(
|
||||
Long id,
|
||||
Double latitude,
|
||||
Double longitude,
|
||||
String title,
|
||||
PostType type,
|
||||
String imageUrl
|
||||
) {}
|
||||
12
src/main/java/com/krylov/refound/dto/PostSearchRequest.java
Normal file
12
src/main/java/com/krylov/refound/dto/PostSearchRequest.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.krylov.refound.dto;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PostSearchRequest {
|
||||
private String search;
|
||||
private List<String> cities;
|
||||
private int page = 0;
|
||||
private int size = 20;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.krylov.refound.repository;
|
||||
|
||||
import com.krylov.refound.dto.MapMarkerDto;
|
||||
import com.krylov.refound.entity.Post;
|
||||
import com.krylov.refound.enums.PostStatus;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -26,11 +27,27 @@ public interface PostRepository extends JpaRepository<Post, Long>, JpaSpecificat
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("update Post p set p.status = :status where p.id = :id")
|
||||
int updateStatus(@Param("id") Long id, @Param("status") PostStatus status);
|
||||
|
||||
List<Post> findByCityContainingIgnoreCaseOrDistrictContainingIgnoreCase(String city, String district);
|
||||
void updateStatus(@Param("id") Long id, @Param("status") PostStatus status);
|
||||
|
||||
@Query("select distinct p.city from Post p where p.city is not null and p.status in :statuses order by p.city")
|
||||
List<String> findDistinctCities(@Param("statuses") Collection<PostStatus> statuses);
|
||||
|
||||
@Query("""
|
||||
select new com.krylov.refound.dto.MapMarkerDto(
|
||||
p.id,
|
||||
p.latitude,
|
||||
p.longitude,
|
||||
p.title,
|
||||
p.type,
|
||||
(select i.url from Image i
|
||||
where i.post = p
|
||||
and i.id = (select min(i2.id) from Image i2 where i2.post = p))
|
||||
)
|
||||
from Post p
|
||||
where p.status not in :excludedStatuses
|
||||
and p.latitude is not null
|
||||
and p.longitude is not null
|
||||
""")
|
||||
List<MapMarkerDto> findMapMarkers(@Param("excludedStatuses") Collection<PostStatus> excludedStatuses);
|
||||
|
||||
}
|
||||
19
src/main/java/com/krylov/refound/service/MapService.java
Normal file
19
src/main/java/com/krylov/refound/service/MapService.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.krylov.refound.service;
|
||||
|
||||
import com.krylov.refound.dto.MapMarkerDto;
|
||||
import com.krylov.refound.enums.PostStatus;
|
||||
import com.krylov.refound.repository.PostRepository;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MapService {
|
||||
|
||||
private final PostRepository postRepository;
|
||||
|
||||
public List<MapMarkerDto> findAllWithCoordinates(String type, String category) {
|
||||
return postRepository.findMapMarkers(List.of(PostStatus.REJECTED, PostStatus.MODERATION));
|
||||
}
|
||||
}
|
||||
@@ -54,4 +54,4 @@ jwt:
|
||||
|
||||
app:
|
||||
cors:
|
||||
allowed-origins: http://localhost:5173,http://localhost:3000
|
||||
allowed-origins: http://localhost:5173,http://localhost:3000,http://192.168.1.75:3000
|
||||
Reference in New Issue
Block a user