added all edit posts for admin
This commit is contained in:
@@ -1,10 +1,43 @@
|
||||
package com.krylov.refound.util;
|
||||
|
||||
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 jakarta.persistence.criteria.Join;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class PostSpecification {
|
||||
|
||||
/**
|
||||
* Поиск для админской ленты: видимы все объявления, включая MODERATION и REJECTED.
|
||||
* Совпадение ищется по названию, описанию, городу, району и данным владельца.
|
||||
*/
|
||||
public static Specification<Post> adminSearch(String search, PostType type, PostStatus status) {
|
||||
return Specification.allOf(
|
||||
(root, query, cb) -> type == null ? cb.conjunction() : cb.equal(root.get("type"), type),
|
||||
(root, query, cb) -> status == null ? cb.conjunction() : cb.equal(root.get("status"), status),
|
||||
(root, query, cb) -> {
|
||||
if (!StringUtils.hasText(search)) {
|
||||
return cb.conjunction();
|
||||
}
|
||||
String pattern = "%" + search.toLowerCase().trim() + "%";
|
||||
// user_id — NOT NULL, поэтому inner join не теряет объявления без владельца.
|
||||
Join<Post, User> user = root.join("user");
|
||||
return cb.or(
|
||||
cb.like(cb.lower(root.get("title")), pattern),
|
||||
cb.like(cb.lower(root.get("description")), pattern),
|
||||
cb.like(cb.lower(root.get("city")), pattern),
|
||||
cb.like(cb.lower(root.get("district")), pattern),
|
||||
cb.like(cb.lower(user.get("login")), pattern),
|
||||
cb.like(cb.lower(user.get("name")), pattern),
|
||||
cb.like(cb.lower(user.get("lastName")), pattern)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static Specification<Post> hasSearch(String search) {
|
||||
return (root, query, cb) -> {
|
||||
if (search == null || search.isBlank()) {
|
||||
|
||||
Reference in New Issue
Block a user