Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.DS_STORE
node_modules
scripts/flow/*/.flowconfig
.flowconfig
*~
*.pyc
.grunt
_SpecRunner.html
__benchmarks__
build/
remote-repo/
coverage/
.module-cache
fixtures/dom/public/react-dom.js
fixtures/dom/public/react.js
test/the-files-to-test.generated.js
*.log*
chrome-user-data
*.sublime-project
*.sublime-workspace
.idea
*.iml
.vscode
*.swp
*.swo

packages/react-devtools-core/dist
packages/react-devtools-extensions/chrome/build
packages/react-devtools-extensions/chrome/*.crx
packages/react-devtools-extensions/chrome/*.pem
packages/react-devtools-extensions/firefox/build
packages/react-devtools-extensions/firefox/*.xpi
packages/react-devtools-extensions/firefox/*.pem
packages/react-devtools-extensions/shared/build
packages/react-devtools-extensions/.tempUserDataDir
packages/react-devtools-inline/dist
packages/react-devtools-shell/dist
packages/react-devtools-timeline/dist
161 changes: 161 additions & 0 deletions Film-REST-API-MongoDB/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
config/database.py
17 changes: 17 additions & 0 deletions Film-REST-API-MongoDB/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
FROM python:3.11

#
WORKDIR /code

#
COPY ./requirements.txt /code/requirements.txt

#
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

#
COPY . /code/

#
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
21 changes: 21 additions & 0 deletions Film-REST-API-MongoDB/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 ledan404

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
120 changes: 120 additions & 0 deletions Film-REST-API-MongoDB/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Film REST API with MongoDB

This repository contains a FastAPI application that serves as an API for managing film data. The API connects to a MongoDB database to store and retrieve information about films. It includes endpoints for listing, adding, updating, and deleting films.

## Getting Started

To run this FastAPI application, follow these steps:

1. **Clone the repository:**

```bash
git clone https://github.com/ledan404/Film-REST-API-MongoDB
cd Film-REST-API-MongoDB
```

2. **Install dependencies:**

It's recommended to create a virtual environment before installing dependencies to keep your project isolated.

```bash
python3 -m venv venv # Create a virtual environment (skip if you already have one)
source venv/bin/activate # Activate the virtual environment
pip3 install -r requirements.txt # Install project dependencies
```
3. **Set Up MongoDB:**

This application uses MongoDB as the database to store film data. Here's how you can set up and connect to MongoDB:

- Install MongoDB: Follow the [official installation guide](https://docs.mongodb.com/manual/installation/) to install MongoDB on your system.

- Create a MongoDB Atlas account (optional): You can also use a cloud-hosted MongoDB service like MongoDB Atlas. Create an account and set up a cluster to get the connection URI.

4.1 **Run the application in the local machine:**

```bash
uvicorn main:app --reload
```

The FastAPI application will start, and you'll be able to access the API at `http://localhost:8000`.
4.2 **Run the application using Docker:**

If you prefer using Docker to manage the application and its dependencies, you can build and run the application using the provided Dockerfile.

```bash
docker build -t film-rest-api .
docker run -p 8000:8000 film-rest-api
```

## Project Structure

The repository is organized as follows:

- `main.py`: The main file for the FastAPI application. It initializes the FastAPI app, includes the router, and starts the server using Uvicorn.

- `config/database.py`: This file connects to the MongoDB database and creates a collection to store film data.

- `routes/route.py`: This module contains the routes of the API. It defines the endpoints for listing, adding, updating, and deleting films.

- `models/film.py`: This module defines the `Film` model using Pydantic. It specifies the structure of film data, including title, actors, rating, description, and facts.

- `schema/schemas.py`: This file contains functions for serializing the data from the database. It includes `individual_serial` to serialize a single film and `serial_films` to serialize a list of films.

## Endpoints

### Get All Films

Endpoint: `GET /`

This endpoint returns a list of all films stored in the database.

### Get Film by ID

Endpoint: `GET /{id}`

This endpoint retrieves a specific film by its unique ID.

### Add Film

Endpoint: `POST /`

This endpoint allows you to add a new film to the database. You should provide the film details in the request body.

### Update Film

Endpoint: `PUT /{id}`

This endpoint updates an existing film's details in the database. You should provide the updated film details in the request body.

### Delete Film

Endpoint: `DELETE /{id}`

This endpoint deletes a film from the database based on its ID.

## Film Model

The `Film` model is used to structure the data for films. It includes the following fields:

- `title`: The title of the film.
- `actors`: A list of actor names.
- `rating`: The film's rating (float value).
- `description`: A description of the film.
- `facts`: A list of interesting facts about the film.

## Dependencies

The application uses the following dependencies:

- `FastAPI`: A modern web framework for building APIs with Python.
- `uvicorn`: ASGI server to run the FastAPI application.
- `pymongo`: Python driver for MongoDB to connect and interact with the database.
- `pydantic`: Data validation and settings management using Python type annotations.

## Contributing

Feel free to contribute to this project by opening issues, suggesting enhancements, or submitting pull requests. Your contributions are greatly appreciated!

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
24 changes: 24 additions & 0 deletions Film-REST-API-MongoDB/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Main file for the FastAPI application."""
from fastapi import FastAPI
from routes.route import router
from fastapi.middleware.cors import CORSMiddleware


app = FastAPI()

app.include_router(router)

origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost",
"http://localhost:8080",
]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
Loading