logo
down
shadow

What would be the best way to implement to check if the Post has been liked by the User using JPA and MySQL?


What would be the best way to implement to check if the Post has been liked by the User using JPA and MySQL?

Content Index :

What would be the best way to implement to check if the Post has been liked by the User using JPA and MySQL?
Tag : java , By : Ben Kohn
Date : November 28 2020, 11:01 PM

this one helps. you could try to extract the liked posts from the list of posts you've just got before. with a "SELECT ... IN" request) and then fill the boolean isLiked; something like :
 ...

@Override
public List<PostMW> getFeed(int page, UserMW user) {
    List<PostMW> result;
    int offset = page * ConstUtil.FEED_POSTS_PER_PAGE;
    postDao.openCurrentSession();
    result = postDao.list(offset, ConstUtil.FEED_POSTS_PER_PAGE);

    List<Long> postIds = new ArrayList();

    for(PostMW post : result){           
       postIds.add(post.getid();
    }

   //then EXtract all liked post from list :
   Query queryIn = em.createQuery("SELECT p.post.id FROM LikeMW p WHERE p.user = :user AND p.post IN :values");

   queryIn.setParameter("values", postIds );
   queryIn.setParameter("user", currentUser);
   List<Object[]> resultIn = queryIn.getResultList();

   Set<Long> postIdLiked ) new HashSet<>();
   for(Object[] row: resultIn) {
       postIdLiked.add(row[0]);
   }
   //then fill the boolean isLiked  
   for(PostMW post : result){            
       if (postIdLiked.contains(post.getId()) 
          post.setLiked(true);      
   }

    postDao.closeCurrentSession();
    return result;
}

...

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to check if a user is edting a table record before allowing another user to edit, not wait for post?


Tag : php , By : Debashree
Date : March 29 2020, 07:55 AM
wish help you to fix your issue There are many system-level approaches you could use to handle the problem. Locking a record for exclusive editing is only one, traditionally chosen by older systems.
A more modern methodology is to allow both edits to proceed without locking—termed optimistic concurrency control. If there is an overlapping edit, see if it can be resolved automatically—many simultaneous edits are, in fact, not contentious, especially if they edit unrelated parts of the record.

facebook api fql stream, how to check if its page post or user post?


Tag : php , By : Trevor Cortez
Date : March 29 2020, 07:55 AM
will be helpful for those in need You'll need to query the profile table to get this.
SELECT id, type FROM profile WHERE id IN (SELECT actor_id FROM #STREAM_QUERY)

Mysql select query for getting current user post and followed friend post


Tag : mysql , By : Philofax
Date : March 29 2020, 07:55 AM
To fix this issue First it is recommended to use explicit JOINS over implicit CROSS JOIN
Try the following query.
 SELECT
    T.postID, 
    T.message, 
    T.time,
    U.userID,
    U.name, 
    U.username, 
    U.picture_url,
    F.userID2,
 FROM
    users AS U  
 INNER JOIN 
    follow_user AS F
 ON U.userID = F.userId1    
 INNER JOIN 
    post AS T
 ON T.pUserID = U.userID OR T.pUserID = F.userId2 
 WHERE
    U.userID = '$uid' //$uid holds the id of the current logged in user
    order by T.postID DESC;

How to implement delete of your post and not other user post in Rails


Tag : ruby-on-rails , By : MikeW
Date : March 29 2020, 07:55 AM
wish helps you Lets say you have a Post model and views all set up:
In your views/posts/show you can set up something like this:
<% if @post.user.id == current_user.id %>
  <%= link_to "Edit", edit_post_path(@post), class:"btn btn-success btn-sm" %>
<% end %>
<% if user_signed_in? %>
  <% if @post.user.id == current_user.id %>
    <%= render 'form', tutorial: @post %>
  <% end %>
<% else %>
  <h1>stop trying to edit others post</h1>
<% end %>

Check if user can comment in a post if he has that post registered


Tag : ruby-on-rails , By : Manu
Date : March 29 2020, 07:55 AM
wish helps you How can i validate if an user belongs to the post he's watching if not dont allow to comment on the post, i tried with if and im using a has_many model like User(devise) UserPost(model) Post and comments(belongs_to post) , playing with the code I tried this and it worked:
  <%if current_user.courses.exists?(@course.id)%>
    do ....
  <%end%>
Related Posts Related QUESTIONS :
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • ImageView hides the round corners of the parent
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • Default Login not successful in spring boot 2.1.7
  • Adding key value pairs from a file to a Hashmap
  • Rub regex: matching a char except when after by another char
  • Convert Base64 String to String Array
  • Escape Unicode Character 'POPCORN' to HTML Entity
  • An empty JSON field which is a boolean/nullable field in Java model, is getting converted as null
  • Mongo java driver cannot find public constructor for interface
  • How to unit test writing a file to AWS Lambda output stream?
  • How to make a GitHub GraphQL API Call from Java
  • What's the difference between @ComponentScan and @Bean in a context configuration?
  • Expected class or package adding a view using a class
  • can be delete of a element in a static array be O(1)?
  • Instance variable heap or stack ? ( with specific example)
  • Assert progress of ProgressBar in Espresso test
  • How to detect if gson.fromjson() has excess elements
  • I cant generate the proper code to select the a specific filter on a BI dashboard I am working on
  • How to Inject Dependencies into a Servlet Filter with Spring Boot Filter Registration Bean?
  • Thrift types as a Generic
  • Effective algorithm to random 4 unique integers less than a big max such as 100_000
  • Combining or and negation in Java regex?
  • Unable to instantiate default tuplizer Exception
  • Multi-tenant migration to work with quarkus
  • Ignite persisting a Set: Cannot find metadata for object with compact footer
  • Maven cannot resolve Jacob dependency using eclipse
  • testcontainers oracle database container starts before database user is created
  • Launching two spring boot apps in integration test
  • Is there a way to add a HashMap's value that is a integer array into a ArrayList?
  • Is there any way that I can get a parameter in paintComponent?
  • Empty stack with one recursive method and one iterative method
  • What's the behavior of onBackpressureBuffer in RxJava2
  • Java regex can only use 1 quantifier in a lookback (need 2)
  • How to fix error in native query : it is showing syntax error near or at
  • How to retrieve nested object from a document and display it in FirestoreRecyclerOptions?
  • Why not use ListIterator for full LinkedList Operation?
  • Android Webview EvaluateJavascript sometimes does not return a response
  • Matcher java doesn't work but regex seems to be good
  • Finding dimensions of a .gif file
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com