Part of the CircleConnect social networking platform. This microservice handles posts, comments, and likes functionality.
- Go (1.21+)
- Gin Web Framework
- MongoDB
- Create and view posts
- Post comments
- Like/unlike posts
- Filter posts by community or user
- Go 1.21 or higher
- MongoDB
- Clone the repository
- Navigate to the post-service directory
- Copy the environment example file
cp .env.example .env - Update the environment variables in
.envfile with your configuration - Run the service
go run main.go
GET /api/posts- Get all postsGET /api/posts/:id- Get a specific post by IDGET /api/communities/:community_id/posts- Get all posts in a communityGET /api/posts/:post_id/comments- Get all comments for a post
POST /api/posts- Create a new postGET /api/user/posts- Get posts created by the authenticated userPOST /api/posts/:post_id/comments- Add a comment to a postPOST /api/posts/:post_id/like- Like a postDELETE /api/posts/:post_id/like- Unlike a post
This service uses JWT tokens for authentication. Include a valid JWT token in the Authorization header:
Authorization: Bearer your_jwt_token
This project is part of CircleConnect, developed for SW Architecture and Design.
POST /api/posts
Description: Create a new post.
Headers:
Authorization: Bearer <token>
Request Body:
{
"title": "string",
"content": "string",
"community_id": "number (optional)",
"media_urls": ["string"] (optional),
"tags": ["string"] (optional)
}Responses:
201 Created: Returns the created post400 Bad Request: If the request body is invalid401 Unauthorized: If the user is not authenticated
GET /api/posts
Description: Get all posts.
Responses:
200 OK: Returns a list of posts
GET /api/posts/:id
Description: Get a post by its ID.
Responses:
200 OK: Returns the post404 Not Found: If the post is not found
GET /api/communities/:community_id/posts
Description: Get all posts in a specific community.
Responses:
200 OK: Returns a list of posts400 Bad Request: If the community ID is invalid
GET /api/user/posts
Description: Get all posts created by the authenticated user.
Headers:
Authorization: Bearer <token>
Responses:
200 OK: Returns a list of posts401 Unauthorized: If the user is not authenticated