This repository contains the code for a social media application built with FastAPI, a modern Python web framework. The application provides functionalities for users to create, read, update, and delete posts, as well as like and favorite posts. Users can also register, login, and manage their profiles.
- Registration: Users can register by providing a unique username, email, password, age, and gender.
- Authentication: Authentication is handled using JWT tokens. Upon successful login, users receive an access token which they can use to authenticate subsequent requests.
- Profile Management: Users can update their profile information, such as username, email, password, age, and gender.
- User Deletion: Users can delete their accounts.
- Create Post: Authenticated users can create new posts with a title, content, location, and specify if the post is published or not.
- Read Post: Users can view posts, which include details like the title, content, author, creation date, number of likes, and comments.
- Update Post: Users can update their own posts, including modifying the title, content, and published status.
- Delete Post: Users can delete their own posts.
- Like Post: Users can like posts they find interesting. They can only like a post once.
- Favorite Post: Users can add posts to their favorites list for quick access. They can also remove posts from their favorites.
- Search Posts: Users can search for posts by title.
-
FastAPI: A modern Python web framework for building APIs with Python type hints.
-
SQLAlchemy: A SQL toolkit and Object-Relational Mapping (ORM) library for Python.
-
PostgreSQL: A powerful, open-source relational database system.
-
Pydantic: Data validation and settings management using Python type annotations.
-
JWT (JSON Web Tokens): Authentication mechanism for securing API endpoints.
-
Passlib: Password hashing library for securely storing passwords.
-
Docker: A platform for developing, shipping, and running applications in containers, providing a consistent environment across different systems.
-
Docker Compose: A tool for defining and running multi-container Docker applications, simplifying the process of managing complex containerized environments.
METHOD | ROUTE | FUNCTIONALITY | ACCESS |
---|---|---|---|
GET | /posts |
Get_All_Posts | All users |
POST | /posts |
Create Post | All users |
GET | /posts/{id} |
Get Post By Id | All users |
PUT | /posts/{id} |
Update Post | All users |
DELETE | /posts/{id} |
Delete Post | All users |
METHOD | ROUTE | FUNCTIONALITY | ACCESS |
---|---|---|---|
GET | /users |
Get_All_Users | All users |
POST | /users |
Create User | All users |
GET | /users/{id} |
Get User By Id | All users |
PUT | /users/{id} |
Update User | All users |
DELETE | /users/{id} |
Delete User | All users |
METHOD | ROUTE | FUNCTIONALITY | ACCESS |
---|---|---|---|
POST | /login |
Login user(jwt) | All users |
METHOD | ROUTE | FUNCTIONALITY | ACCESS |
---|---|---|---|
POST | /likes |
Like Post | All users |
METHOD | ROUTE | FUNCTIONALITY | ACCESS |
---|---|---|---|
POST | /favorite |
Favorite Post | All users |
1- Clone the repository:
git clone https://github.com/yourusername/fast-api.git
2- Create your virtualenv and activate it:
Pipenv or virtualenv
3- Install dependencies:
pip install -r requirements.txt
4- Configure environment variables: Create a .env file and set the following variables:
DATABASE_HOSTNAME=your_database_hostname
DATABASE_PORT=your_database_port
DATABASE_NAME=your_database_name
DATABASE_USERNAME=your_database_username
DATABASE_PASSWORD=your_database_password
SECRET_KEY=your_secret_key
ALGORITHM=your_algorithm
ACCESS_TOKEN_EXPIRE_MINUTES=your_access_token_expire_minutes
5- Run the application:
uvicorn app.main:app --reload
POST /users/
Content-Type: application/json
{
"username": "example_user",
"email": "[email protected]",
"password": "securepassword",
"age": 25,
"gender": "male",
"is_active": true
}
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": 1,
"username": "example_user",
"email": "[email protected]",
"age": 25,
"gender": "male",
"is_active": true,
"created_at": "2024-04-04T12:00:00",
"updated_at": "2024-04-04T12:00:00"
}
POST /posts/
Authorization: Bearer <access_token>
Content-Type: application/json
{
"title": "Example Post",
"content": "This is an example post content.",
"published": true,
"location": "New York, USA"
}
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": 1,
"title": "Example Post",
"content": "This is an example post content.",
"published": true,
"location": "New York, USA",
"comments": 0,
"created_at": "2024-04-04T12:00:00",
"updated_at": "2024-04-04T12:00:00",
"user_id": 1,
"owner": {
"id": 1,
"username": "example_user",
"email": "[email protected]",
"is_active": true
}
}
POST /likes/
Authorization: Bearer <access_token>
Content-Type: application/json
{
"post_id": 1,
"dir": 1
}
HTTP/1.1 201 Created
Content-Type: application/json
{
"message": "User 1 liked post 1"
}
- FastAPI Community
- SQLAlchemy Community
- Python Community
This project is licensed under the MIT License.
Thank you for exploring the Gym Fitness app! If you have any questions, feedback, or just want to say hi, feel free to reach out. Happy fitness journey!