Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subforum endpoints #475

Merged
merged 10 commits into from
Dec 6, 2024
Merged

Subforum endpoints #475

merged 10 commits into from
Dec 6, 2024

Conversation

TheRealLowyer
Copy link
Contributor

Implement Subforum Endpoints

Overview

This pull request introduces the implementation of two new endpoints for managing and retrieving subforum data:

  1. /subforums/searchKeyword
  2. /subforum/{id}

These endpoints provide functionality for searching subforums by keyword and retrieving detailed subforum information, respectively.


Endpoints Added

1. /subforums/searchKeyword

  • Description: Searches for subforums with titles containing a given keyword.

  • Input:

    • keyword (query parameter): The keyword to search for in subforum titles.
  • Output: Returns a list of subforums matching the keyword with the following details:

    • id: Subforum ID.
    • title: Subforum title.
    • numberOfPosts: Number of posts in the subforum.
  • Success Response Example:

    [
        {
            "id": 1,
            "title": "Technology Discussions",
            "numberOfPosts": 10
        },
        {
            "id": 2,
            "title": "AI Innovations",
            "numberOfPosts": 5
        }
    ]

2. /subforum/{id}

  • Description: Retrieves detailed information about a specific subforum by ID.

  • Input:

    • id (path parameter): The ID of the subforum.
    • username (query parameter): The username to determine if the user is following the subforum.
  • Output: Returns detailed information about the subforum, including:

    • subforumName: The name of the subforum.
    • isFollowedByGivenUsername: Whether the given username is following the subforum.
    • posts: A list of posts in the subforum, each containing:
      • postID: Post ID.
      • title: Post title.
      • content: Post content.
      • creatorUsername: The username of the post creator.
      • creatorProfilePhoto: The profile photo of the post creator.
      • nofLikes: Number of likes on the post.
      • creationDate: Post creation date.
      • nofComments: Number of comments on the post.
    • numberOfPosts: Total number of posts in the subforum.
    • numberOfFollowers: Total number of followers for the subforum.
  • Success Response Example:

    {
        "subforumName": "Technology Discussions",
        "isFollowedByGivenUsername": true,
        "posts": [
            {
                "postID": 101,
                "title": "Best Programming Languages in 2024",
                "content": "Java and Python continue to dominate...",
                "creatorUsername": "techguru",
                "creatorProfilePhoto": "https://example.com/profiles/techguru.jpg",
                "nofLikes": 15,
                "creationDate": "2024-12-01T10:15:30",
                "nofComments": 5
            }
        ],
        "numberOfPosts": 1,
        "numberOfFollowers": 5
    }
  • Error Response Example (Subforum Not Found):

    {
        "subforumName": null,
        "isFollowedByGivenUsername": null,
        "posts": null,
        "numberOfPosts": null,
        "numberOfFollowers": null
    }

Key Changes

  1. Repository:
    • Added custom queries to search subforums by keyword and retrieve subforum details, including post and follower counts.
  2. Service:
    • Implemented logic to:
      • Search subforums by keyword.
      • Fetch subforum details, including whether the user is following the subforum, the number of posts, and post-specific details such as content, likes, creation date, and number of comments.
  3. DTOs:
    • Created SubforumDetailsDTO and PostSummaryDTO for structured API responses.
  4. Controller:
    • Added endpoints for /subforums/searchKeyword and /subforum/{id} with validation and query parameter handling.

Testing

  • Verified:
    • Subforums are correctly filtered by keyword in /subforums/searchKeyword.
    • Detailed subforum information is returned for valid IDs in /subforum/{id}.
    • Proper error response for invalid subforum IDs.
  • Added unit and integration tests for service and controller logic.

Notes

  • Future Enhancement: Consider pagination for posts in /subforum/{id} if subforums have many posts.
  • Ensure that profile photos are efficiently handled if stored as large Base64 strings or URLs.

Checklist

  • Added custom repository queries.
  • Implemented service logic for subforum endpoints.
  • Created DTOs for structured response data.
  • Added comprehensive testing for new endpoints.

This pull request provides the functionality for searching and retrieving subforum data efficiently. Let me know if further details or refinements are needed!

@karatashsyn karatashsyn merged commit b88a421 into main Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Enhancement New feature or request Priority: High Requires taking action ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants