added security and fix edit profile

This commit is contained in:
SlimusMinus
2026-06-18 00:22:50 +03:00
parent 81e3e007e1
commit bafb636cbe
24 changed files with 418 additions and 56 deletions

View File

@@ -1,45 +1,12 @@
package com.krylov.refound.repository;
import com.krylov.refound.entity.Post;
import com.krylov.refound.enums.PostType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface PostRepository extends JpaRepository<Post, Long>, JpaSpecificationExecutor<Post> {
Page<Post> findByType(PostType type, Pageable pageable);
@Query(value = """
SELECT * FROM Posts p
WHERE
(:type IS NULL OR p.type = :type)
AND (:city IS NULL OR p.city = :city)
AND (:category IS NULL OR p.category = :category)
AND (
:lat IS NULL OR :lng IS NULL OR :radius IS NULL OR
(
6371 * acos(
cos(radians(:lat)) * cos(radians(p.latitude)) *
cos(radians(p.longitude) - radians(:lng)) +
sin(radians(:lat)) * sin(radians(p.latitude))
)
) <= :radius
)
""",
countQuery = "SELECT count(*) FROM Posts p",
nativeQuery = true)
Page<Post> searchWithGeo(
@Param("type") String type,
@Param("city") String city,
@Param("category") String category,
@Param("lat") Double lat,
@Param("lng") Double lng,
@Param("radius") Double radius,
Pageable pageable
);
List<Post> findByUserId(Long userId);
}