Code Monkey home page Code Monkey logo

Comments (4)

torshid avatar torshid commented on May 28, 2024

Hey @vittoN :)
I am not sure if I have understood correctly your suggestion, can you give an example of how would you use that in a filter query?

from springfilter.

vittoN avatar vittoN commented on May 28, 2024

Let's assume i would extract all messages where recipient is the user logged in the system. So, using a custom JPA query i'll write:

@Query("select m from Message m where m.to.id = ?#{ principal?.id }")
Page<Message> findInbox(Pageable pageable);

I would like a way to limit searched results in the same way using spring-filter.

from springfilter.

torshid avatar torshid commented on May 28, 2024

I see what you mean, I think it will be quiet hard to support @Query. What you can do is anding the user's filter with an another filter:

Specification<Message> incomingFilter = // user's filter

Specification<Message> loggedInUserFilter = new FilterSpecification<Message>(FilterBuilder.equal("principal.id", getLoggedInUserId()));

Specification<Message> finalFilter = FilterSpecification.merge(incomingFilter, loggedInUserFilter); // or Specification.where(loggedInUserFilter).and(incomingFilter);

Page<Message> messages = repository.findAll(finalFilter, pageable);

That way, no matter what the user's filter is, he will only and only be able to get/filter his own messages.

Hope it's clear.

from springfilter.

torshid avatar torshid commented on May 28, 2024

@vittoN I think that anding filters should have met your requirements, closing the issue for now.

from springfilter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.