Documented API - bounswe/bounswe2024group6 GitHub Wiki

Documented API

Signup

Endpoint: /signup/
Method: POST

Description:
Registers a new user.

Request Body:

{
    "username": "string",
    "password": "string",
    "email": "string",
    "phone_number": "string",
    "bio": "string"
}

Response:


201 Created:
Successful registration.

{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string"
}

400 Bad Request:
Invalid data.

{
    "error": "object"
}

Login
Endpoint: /login/
Method: POST

Description:
Authenticates a user and returns a token.

Request Body:

json
Copy code
{
    "username": "string",
    "password": "string"
}
Response:

200 OK:
Successful login.
json
Copy code
{
    "token": "string",
    "user_id": "integer",
    "username": "string",
    "profile_image": "string"
}
401 Unauthorized:
Invalid credentials.
json
Copy code
{
    "error": "Invalid Credentials"
}
Search
Endpoint: /search/
Method: POST

Description:
Searches for entities based on a query.

Request Body:

json
Copy code
{
    "query": "string"
}
Response:

200 OK:
Successful search.
json
Copy code
{
    "style": [{"name": "string", "image": "string", "entity_id": "integer"}],
    "architect": [{"name": "string", "image": "string", "entity_id": "integer"}],
    "building": [{"name": "string", "image": "string", "entity_id": "integer"}]
}
204 No Content:
Query missing.
json
Copy code
{
    "message": "there was an error with the query."
}
Update User Profile
Endpoint: /update_user_profile/
Method: POST

Description:
Updates the profile of an authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "email": "string",
    "profile_image": "string"
}
Response:

200 OK:
Profile updated.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string"
}
400 Bad Request:
Invalid data.
json
Copy code
{
    "errors": "object"
}
User Profile
Endpoint: /user_profile/
Method: POST

Description:
Fetches the profile and related posts of a user.

Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
Profile data.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string",
    "posts": "array",
    "bookmarked_posts": "array",
    "commented_posts": "array",
    "liked_posts": "array"
}
404 Not Found:
User not found.
json
Copy code
{
    "detail": "Not found."
}
Authenticated User Profile
Endpoint: /auth_user_profile/
Method: POST

Description:
Fetches the profile and related posts of a user, with additional info for the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
Profile data with follow status.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string",
    "is_following": "boolean",
    "posts": "array",
    "bookmarked_posts": "array",
    "commented_posts": "array",
    "liked_posts": "array"
}
404 Not Found:
User not found.
json
Copy code
{
    "detail": "Not found."
}
Create Post
Endpoint: /create_post/
Method: POST

Description:
Creates a new post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "title": "string",
    "text": "string",
    "image_url": "string",
    "entity_id": "integer"
}
Response:

201 Created:
Post created.
json
Copy code
{
    "message": "Post created successfully."
}
400 Bad Request:
Missing required fields.
json
Copy code
{
    "error": "Title and text are required fields."
}
500 Internal Server Error:
Error occurred.
json
Copy code
{
    "error": "string"
}
Like Post
Endpoint: /like_post/
Method: POST

Description:
Likes a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

201 Created:
Post liked.
json
Copy code
{
    "message": "Post liked successfully."
}
400 Bad Request:
Post ID missing or already liked.
json
Copy code
{
    "error": "Post ID is required."
}
json
Copy code
{
    "error": "You have already liked this post."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Unlike Post
Endpoint: /get_like_back/
Method: POST

Description:
Removes a like from a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

200 OK:
Like removed.
json
Copy code
{
    "message": "Like removed successfully."
}
400 Bad Request:
Post ID missing or not liked.
json
Copy code
{
    "error": "Post ID is required."
}
json
Copy code
{
    "error": "You have not liked this post."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Comment on Post
Endpoint: /comment_post/
Method: POST

Description:
Adds a comment to a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer",
    "comment_text": "string"
}
Response:

201 Created:
Comment added.
json
Copy code
{
    "message": "Comment added successfully."
}
400 Bad Request:
Post ID or comment text missing.
json
Copy code
{
    "error": "Post ID and comment text are required."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Bookmark Post
Endpoint: /bookmark_post/
Method: POST

Description:
Bookmarks a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

201 Created:
Post bookmarked.
json
Copy code
{
    "message": "Post bookmarked successfully."
}
400 Bad Request:
Post ID missing or already bookmarked.
json
Copy code
{
    "error": "Post ID is required."
}
json
Copy code
{
    "error": "You have already bookmarked this post."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Unbookmark Post
Endpoint: /unbookmark_post/
Method: POST

Description:
Removes a bookmark from a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

200 OK:
Bookmark removed.
json
Copy code
{
    "message": "Bookmark removed successfully."
}
400 Bad Request:
write all of them in hack.md format
ChatGPT
markdown
Copy code
# API Documentation

## Signup
**Endpoint:** `/signup/`  
**Method:** `POST`

**Description:**  
Registers a new user.

**Request Body:**
```json
{
    "username": "string",
    "password": "string",
    "email": "string"
}
Response:

201 Created:
Successful registration.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string"
}
400 Bad Request:
Invalid data.
json
Copy code
{
    "errors": "object"
}
Login
Endpoint: /login/
Method: POST

Description:
Authenticates a user and returns a token.

Request Body:

json
Copy code
{
    "username": "string",
    "password": "string"
}
Response:

200 OK:
Successful login.
json
Copy code
{
    "token": "string",
    "user_id": "integer",
    "username": "string",
    "profile_image": "string"
}
401 Unauthorized:
Invalid credentials.
json
Copy code
{
    "error": "Invalid
no stop all of them should be in copyable 
ChatGPT
markdown
Copy code
# API Documentation

## Signup
**Endpoint:** `/signup/`  
**Method:** `POST`

**Description:**  
Registers a new user.

**Request Body:**
```json
{
    "username": "string",
    "password": "string",
    "email": "string"
}
Response:

201 Created:
Successful registration.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string"
}
400 Bad Request:
Invalid data.
json
Copy code
{
    "errors": "object"
}
Login
Endpoint: /login/
Method: POST

Description:
Authenticates a user and returns a token.

Request Body:

json
Copy code
{
    "
write everyting in one hackmd format, including codes, json etc.
ChatGPT
markdown
Copy code
# API Documentation

## Signup
**Endpoint:** `/signup/`  
**Method:** `POST`

**Description:**  
Registers a new user.

**Request Body:**

{
    "username": "string",
    "password": "string",
    "email": "string"
}
Response:

201 Created:
Successful registration.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string"
}
400 Bad Request:
Invalid data.
json
Copy code
{
    "errors": "object"
}
Login
Endpoint: /login/
Method: POST

Description:
Authenticates a user and returns a token.

Request Body:

json
Copy code
{
    "username": "string",
    "password": "string"
}
Response:

200 OK:
Successful login.
json
Copy code
{
    "token": "string",
    "user_id": "integer",
    "username": "string",
    "profile_image": "string"
}
401 Unauthorized:
Invalid credentials.
json
Copy code
{
    "error": "Invalid Credentials"
}
Search
Endpoint: /search/
Method: POST

Description:
Searches for entities based on a query.

Request Body:

json
Copy code
{
    "query": "string"
}
Response:

200 OK:
Successful search.
json
Copy code
{
    "style": [{"name": "string", "image": "string", "entity_id": "integer"}],
    "architect": [{"name": "string", "image": "string", "entity_id": "integer"}],
    "building": [{"name": "string", "image": "string", "entity_id": "integer"}]
}
204 No Content:
Query missing.
json
Copy code
{
    "message": "there was an error with the query."
}
Update User Profile
Endpoint: /update_user_profile/
Method: POST

Description:
Updates the profile of an authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "email": "string",
    "profile_image": "string"
}
Response:

200 OK:
Profile updated.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string"
}
400 Bad Request:
Invalid data.
json
Copy code
{
    "errors": "object"
}
User Profile
Endpoint: /user_profile/
Method: POST

Description:
Fetches the profile and related posts of a user.

Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
Profile data.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string",
    "posts": "array",
    "bookmarked_posts": "array",
    "commented_posts": "array",
    "liked_posts": "array"
}
404 Not Found:
User not found.
json
Copy code
{
    "detail": "Not found."
}
Authenticated User Profile
Endpoint: /auth_user_profile/
Method: POST

Description:
Fetches the profile and related posts of a user, with additional info for the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
Profile data with follow status.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string",
    "is_following": "boolean",
    "posts": "array",
    "bookmarked_posts": "array",
    "commented_posts": "array",
    "liked_posts": "array"
}
404 Not Found:
User not found.
json
Copy code
{
    "detail": "Not found."
}
Create Post
Endpoint: /create_post/
Method: POST

Description:
Creates a new post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "title": "string",
    "text": "string",
    "image_url": "string",
    "entity_id": "integer"
}
Response:

201 Created:
Post created.
json
Copy code
{
    "message": "Post created successfully."
}
400 Bad Request:
Missing required fields.
json
Copy code
{
    "error": "Title and text are required fields."
}
500 Internal Server Error:
Error occurred.
json
Copy code
{
    "error": "string"
}
Like Post
Endpoint: /like_post/
Method: POST

Description:
Likes a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

201 Created:
Post liked.
json
Copy code
{
    "message": "Post liked successfully."
}
400 Bad Request:
Post ID missing or already liked.
json
Copy code
{
    "error": "Post ID is required."
}
json
Copy code
{
    "error": "You have already liked this post."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Unlike Post
Endpoint: /get_like_back/
Method: POST

Description:
Removes a like from a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

200 OK:
Like removed.
json
Copy code
{
    "message": "Like removed successfully."
}
400 Bad Request:
Post ID missing or not liked.
json
Copy code
{
    "error": "Post ID is required."
}
json
Copy code
{
    "error": "You have not liked this post."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Comment on Post
Endpoint: /comment_post/
Method: POST

Description:
Adds a comment to a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer",
    "comment_text": "string"
}
Response:

201 Created:
Comment added.
json
Copy code
{
    "message": "Comment added successfully."
}
400 Bad Request:
Post ID or comment text missing.
json
Copy code
{
    "error": "Post ID and comment text are required."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Bookmark Post
Endpoint: /bookmark_post/
Method: POST

Description:
Bookmarks a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

201 Created:
Post bookmarked.
json
Copy code
{
    "message": "Post bookmarked successfully."
}
400 Bad Request:
Post ID missing or already bookmarked.
json
Copy code
{
    "error": "Post ID is required."
}
json
Copy code
{
    "error": "You have already bookmarked this post."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Unbookmark Post
Endpoint: /unbookmark_post/
Method: POST

Description:
Removes a bookmark from a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

200 OK:
Bookmark removed.
json
Copy code
{
    "message": "Bookmark removed successfully."
}
400 Bad Request:
Post ID missing.
json
Copy code
{
    "error": "Post ID is required."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Follow User
Endpoint: /follow_user/
Method: POST

Description:
Follows a user by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "username": "string"
}
Response:

201 Created:
User followed.
json
Copy code
{
    "message": "You are now following {username}."
}
400 Bad Request:
Username missing or following self.
json
Copy code
{
    "error": "Username is missing in the request body."
}
json
Copy code
{
    "error": "You cannot follow yourself."
}
404 Not Found:
User not found.
json
Copy code
{
    "error": "User does not exist."
}
Unfollow User
Endpoint: /unfollow_user/
Method: POST

Description:
Unfollows a user by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
User unfollowed.
json
Copy code
{
    "message": "You have unfollowed {username}."
}
400 Bad Request:
Username missing or not following.
json
Copy code
{
    "error": "Username is missing in the request body."
}
json
Copy code
{
    "error": "You are not following {username}."
}
404 Not Found:
User not found.
json
Copy code
{
    "error": "User does not exist."
}
List Followers
Endpoint: /list_followers/
Method: POST

Description:
Lists followers of a user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
List of followers.
json
Copy code
{
    "followers": [{"username": "string"}]
}
400 Bad Request:
Username missing.
json
Copy code
{
    "error": "Username is missing in the request body."
}
404 Not Found:
User not found.
json
Copy code
{
    "error": "User does not exist."
}
List Following
Endpoint: /list_following/
Method: POST

Description:
Lists users followed by a user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
List of followed users.
json
Copy code
{
    "following": [{"username": "string"}]
}
400 Bad Request:
Username missing.
json
Copy code
{
    "error": "Username is missing in the request body."
}
404 Not Found:
User not found.
json
Copy code
{
    "error": "User does not exist."
}
Guest Feed
Endpoint: /guest_feed/
Method: GET

Description:
Fetches latest posts for guest users.

Response:

200 OK:
List of post IDs.
json
Copy code
{
    "post_ids": ["integer"]
}
500 Internal Server Error:
Error occurred.
json
Copy code
{
    "error": "string"
}
Authenticated Feed
Endpoint: /auth_feed/
Method: GET

Description:
Fetches posts from followed users for authenticated users.

Request Headers:

Authorization: Token <token>
Response:

200 OK:
List of post IDs.
json
Copy code
{
    "post_ids": ["integer"]
}
500 Internal Server Error:
Error occurred.
json
Copy code
{
    "error": "string"
}
Get Posts by IDs
Endpoint: /get_posts_by_ids/
Method: POST

Description:
Fetches post details by post ID.

Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

200 OK:
Post details.
json
Copy code
{
    "id": "integer",
    "title": "string",
    "text": "string",
    "author": "object",
    "created_at": "datetime",
    "updated_at": "datetime",
    "image": "string",
    "likes_count": "integer"
}
400 Bad Request:
Post ID missing.
json
Copy code
{
    "error": "Post ID is required."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Building View
Endpoint: /building_view/
Method: POST

Description:
Fetches building information by entity ID.

Request Body:

json
Copy code
{
    "entity_id": "integer"
}
Response:

200 OK:
Building details.
json
Copy code
{
    "entity_id": "integer",
    "name": "string",
    "description": "string",
    "image": "string"
}
Architect View
Endpoint: /architect_view/
Method: POST

Description:
Fetches architect information by entity ID.

Request Body:

json
Copy code
{
    "entity_id": "integer"
}
Response:

200 OK:
Architect details.
json
Copy code
{
    "entity_id": "integer",
    "name": "string",
    "description": "string",
    "image": "string"
}
Style View
Endpoint: /style_view/
Method: POST

Description:
Fetches style information by entity ID.

Request Body:

json
Copy code
{
    "entity_id": "integer"
}
Response:

200 OK:
Style details.
json
Copy code
{
    "entity_id": "integer",
    "name": "string",
    "description": "string",
    "image": "string"
}
Delete Post
Endpoint: /delete_post/
Method: DELETE

Description:
Deletes a post by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "post_id": "integer"
}
Response:

200 OK:
Post deleted.
json
Copy code
{
    "message": "Post deleted successfully."
}
400 Bad Request:
Post ID missing.
json
Copy code
{
    "error": "Post ID is required."
}
403 Forbidden:
Unauthorized action.
json
Copy code
{
    "error": "You do not have permission to delete this post."
}
404 Not Found:
Post not found.
json
Copy code
{
    "error": "Post does not exist."
}
Delete Comment
Endpoint: /delete_comment/
Method: DELETE

Description:
Deletes a comment by the authenticated user.

Request Headers:

Authorization: Token <token>
Request Body:

json
Copy code
{
    "comment_id": "integer"
}
Response:

200 OK:
Comment deleted.
json
Copy code
{
    "message": "Comment deleted successfully."
}
400 Bad Request:
Comment ID missing.
json
Copy code
{
    "error": "Comment ID is required."
}
403 Forbidden:
Unauthorized action.
json
Copy code
{
    "error": "You do not have permission to delete this comment."
}
404 Not Found:
Comment not found.
json
Copy code
{
    "error": "Comment does not exist."
}
Get Entity Posts
Endpoint: /get_entity_posts/
Method: GET

Description:
Fetches posts related to an entity by entity ID.

Request Body:

json
Copy code
{
    "entity_id": "integer"
}
Response:

200 OK:
List of posts.
json
Copy code
{
    "posts": "array"
}
400 Bad Request:
Entity ID missing.
json
Copy code
{
    "error": "Entity ID is required."
}
404 Not Found:
Entity not found.
json
Copy code
{
    "error": "Entity does not exist."
}
Basic User Info
Endpoint: /basic_user_info/
Method: POST

Description:
Fetches basic user information by username.

Request Body:

json
Copy code
{
    "username": "string"
}
Response:

200 OK:
User data.
json
Copy code
{
    "id": "integer",
    "username": "string",
    "email": "string",
    "profile_image": "string"
}
404 Not Found:
User not found.
json
Copy code
{
    "detail": "Not found."
}
Entity from Search Result
Endpoint: /entity_from_searchresult/
Method: POST

Description:
Fetches entity information from search result ID.

Request Body:

json
Copy code
{
    "id": "integer"
}
Response:

200 OK:
Entity details.
json
Copy code
{
    "entity_id": "integer",
    "name": "string",
    "category": "string"
}
404 Not Found:
Search result not found.
json
Copy code
{
    "detail": "Not found."
}
⚠️ **GitHub.com Fallback** ⚠️