This PR introduces the functionality to tag posts and tag users in posts. It includes updates to the database schema, models, DTOs, service layer, mappers, and controllers to fully support the creation, retrieval, and updating of posts with associated tags and tagged users. The goal is to enhance user engagement by allowing more detailed categorization and interaction within posts.
Description
1. DB Schema Updates
Tables Added:
tags: Stores tags that can be associated with posts.
post_tags: A join table to link posts with tags.
tagged_users: A join table to link posts with users who are tagged in the posts.
2. Model Updates:
Post Model:
Added relationships for tags and taggedUsers using @ManyToMany annotations.
Tag Model:
Created to represent the tags table.
User Model:
Used for managing users that are tagged in posts.
3. DTO Updates:
PostRequestDTO:
Added Set<String> tagNames to accept a list of tags by name.
Added Set<Long> taggedUserIds to accept a list of user IDs to be tagged in the post.
PostResponseDTO:
Added Set<String> tagNames to return a list of tag names associated with the post.
Added Set<String> taggedUsernames to return a list of usernames tagged in the post.
4. Service Layer Updates:
PostService:
Methods updated to handle tagging during post creation and updating.
Refactored the handling of tags and tagged users into a separate method to maintain clean code.
5. Mapper Updates:
PostMapper:
Updated to map between PostRequestDTO and Post entities, handling tags and tagged users.
TagMapper:
Created to handle conversion between Tag entities and DTOs.
6. Controller Layer Updates:
PostController:
Updated to support creating and updating posts with tags and tagged users via the new DTO fields.
7. Testing:
PostControllerTest:
Added test cases for handling tags and tagged users in posts.
Updated existing tests to verify the inclusion of tags and tagged users.\
PostMapperTest:
Added test cases to verify that tags and tagged users are correctly mapped between entities and DTOs.
TagMapperTest:
Added tests to ensure the correct functionality of the TagMapper.
Examples:
Creating a Post with Tags and Tagged Users:
Request Body:
{
"authorId": 1,
"title": "New Feature Announcement",
"content": "We just launched a new feature!",
"tagNames": ["Feature", "Announcement"],
"taggedUserIds": [2, 3]
}
Response Body
{
"postId": 10,
"authorId": 1,
"title": "New Feature Announcement",
"content": "We just launched a new feature!",
"createdAt": "2024-08-29T10:15:30",
"updatedAt": "2024-08-29T10:15:30",
"tagNames": ["Feature", "Announcement"],
"taggedUsernames": ["testuser2", "testuser3"]
}
TL;DR
This PR introduces the functionality to tag posts and tag users in posts. It includes updates to the database schema, models, DTOs, service layer, mappers, and controllers to fully support the creation, retrieval, and updating of posts with associated tags and tagged users. The goal is to enhance user engagement by allowing more detailed categorization and interaction within posts.
Description
1. DB Schema Updates
tags
: Stores tags that can be associated with posts.post_tags
: A join table to link posts with tags.tagged_users
: A join table to link posts with users who are tagged in the posts.2. Model Updates:
@ManyToMany
annotations.3. DTO Updates:
Set<String>
tagNames to accept a list of tags by name.Set<Long>
taggedUserIds to accept a list of user IDs to be tagged in the post.Set<String>
tagNames to return a list of tag names associated with the post.Set<String>
taggedUsernames to return a list of usernames tagged in the post.4. Service Layer Updates:
5. Mapper Updates:
6. Controller Layer Updates:
7. Testing:
Examples:
Creating a Post with Tags and Tagged Users:
Request Body:
Response Body