| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /comunica/app_ojos_old/ |
Upload File : |
# Eye Profile Management API
This is an API developed with FastAPI to manage eye profiles as well as associated analyses. It allows for creating profiles, associating eye images, retrieving information stored in a MySQL database, and obtaining access addresses to data distributed on a NAS.
All examples and steps to show who the API works will be done assuming the API it is running in DEBUG mode.
All steps explained can be reproduced in production state by changing the host and port conection shown.
## Features
- **Create Profiles**: Add profiles with names, descriptions, and associated eye images.
- **Consult Profiles**: Retrieve profiles along with their associated images.
- **Database**: MySQL managed via SQLAlchemy.
## Requirements
- Python 3.6 or higher
- MySQL
- pip (Python package manager)
## Installation
1. **Clone the repository:**
```sh
git clone https://github.com/TechImpulse-Dev/api_ojos.git
cd api_ojos
```
2. **Create and activate a virtual environment:**
On Linux/MacOS:
```sh
python3 -m venv env
source env/bin/activate
```
On Windows:
```sh
python -m venv env
env\Scripts\activate
```
3. **Install dependencies:**
```sh
pip install -r requirements.txt
```
4. **Set up environment variables:**
Create an `.env` file in the project root with the following variables:
```plaintext
DEBUG=True
DEBUG_HOST=127.0.0.1
DEBUG_PORT=8000
PROD_HOST=0.0.0.0
PROD_PORT=80
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DB=database_name
```
5. **Set up the database:**
Ensure MySQL is installed and running. Then, create the database:
```sql
CREATE DATABASE database_name;
```
6. **Create tables:**
Run the script to create the necessary tables in the database:
```sh
python create_tables.py
```
## Accessing Interactive Documentation
FastAPI automatically generates API documentation and exposes it through two interfaces:
- **Swagger UI**: Available at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
- **Redoc**: Available at [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)
Additionally, if you visit the API root at [http://127.0.0.1:8000/](http://127.0.0.1:8000/), you will be automatically redirected to the Swagger UI documentation.
## Execution
1. **Start the application:**
```sh
python main.py
```
2. **Check API access:**
Open your browser and visit [http://127.0.0.1:8000/check](http://127.0.0.1:8000/check) to see a response message confirming that the API has been set up correctly.
## Project Structure
```
project/
├── app/
│ ├── init.py
│ ├── conf.py
│ ├── config.py
│ ├── database.py
│ ├── models.py
│ ├── schemas.py
│ └── routes/
│ ├── init.py
│ └── items.py
├── main.py
├── create_tables.py
├── test_api.py
├── .env
├── requirements.txt
```
- **app/**: Contains all the application logic, including models, routes, schemas, and configurations.
- **main.py**: Entry point for the FastAPI application.
- **create_tables.py**: Script to create the database tables.
- **test_api.py**: Script to perform API tests.
- **requirements.txt**: List of project dependencies.
- **.env**: Environment variables needed for application configuration.
## API Usage Examples
### Create a Profile
- **Endpoint**: `POST /profile/`
- **Description**: Creates a new profile with images associated with the eyes.
- **Request body example:**
```json
{
"name": "Test Profile",
"description": "This is a test profile.",
"images": ["base/img.png", "base/img2.png"]
}
```
### Retrieve a Profile
- **Endpoint**: `GET /profile/{id}`
- **Description**: Retrieves a profile and the images associated with its eyes by ID.
- **Response example:**
```json
{
"id": 1,
"name": "Test Profile",
"description": "This is a test profile.",
"eyes": [
{
"eye": 0,
"date": "2024-01-01",
"path": "base/img.png"
},
{
"eye": 1,
"date": "2024-01-01",
"path": "base/img2.png"
}
]
}
```
## Testing
Run the `test_api.py` script to test the API functionality:
```sh
python test_api.py
```
## Contributing
Thank you for considering contributing to this project! Here is the process for contributing:
1. **Fork the repository:**
Fork the repository to have a copy of the project in your GitHub account.
```sh
git clone https://github.com/TechImpulse-Dev/api_ojos.git
cd api_ojos
```
2. **Create a new branch:**
Create a new branch to work on your feature or bug fix.
```sh
git checkout -b your-branch-name
```
3. **Make your changes:**
Make the necessary modifications in your branch. Be sure to follow the project's style guides and best practices.
4. **Commit your changes:**
Commit your changes with a descriptive message.
```sh
git commit -m "Clear description of the changes made"
```
5. **Push your branch to your forked repository:**
Push your branch with the changes to your repository on GitHub.
```sh
git push origin your-branch-name
```
6. **Open a Pull Request:**
In the original repository, open a Pull Request from your branch. Make sure to clearly describe the changes and the reasons for them.
- Include details about the changes and the reason behind them.
- Reference any relevant issue (for example, `Closes #123`).
- Ensure that the Pull Request passes all tests and code reviews.
7. **Review and Merge:**
The development team will review your Pull Request. You may be asked for additional changes before it is accepted. Once approved, your contribution will be merged into the main project.
## License
This project is licensed under the MIT License. This means you are permitted to use, copy, modify, and distribute this software for any purpose, provided the copyright notice and license notice are maintained in all copies or substantial portions of the software.
You can find more details in the [LICENSE](LICENSE) file included in this repository.