Package org.example.dao
Class PostDAO
java.lang.Object
org.example.dao.PostDAO
Data Access Object for Post entities.
Handles CRUD operations and interaction with post_likes table.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeletePost(int postId) Deletes a post from the database by ID.getAllPosts(String currentNickname) Retrieves all posts including an indicator if the current user has liked them.getTopAuthors(int limit) Calculates posts count per author.getTopPosts(int limit) Retrieves the most liked posts.voidSaves a new post to the database.searchByAuthor(String authorQuery, String currentNickname) Searches for posts by author's nickname using a partial match.voidtoggleLike(int postId, String nickname) Adds or removes a like and updates likes_count in a single transaction.voidupdatePost(int postId, String newContent) Updates an existing post's content and sets the updated_at timestamp.
-
Constructor Details
-
PostDAO
public PostDAO()
-
-
Method Details
-
savePost
Saves a new post to the database.- Parameters:
content- The text content of the post.author- The nickname of the post creator.
-
getAllPosts
Retrieves all posts including an indicator if the current user has liked them.- Parameters:
currentNickname- The nickname of the logged-in user.- Returns:
- List of posts sorted by ID descending.
-
searchByAuthor
Searches for posts by author's nickname using a partial match. -
updatePost
Updates an existing post's content and sets the updated_at timestamp. -
deletePost
public void deletePost(int postId) Deletes a post from the database by ID. -
toggleLike
Adds or removes a like and updates likes_count in a single transaction. -
getTopPosts
Retrieves the most liked posts. -
getTopAuthors
Calculates posts count per author.
-