134 lines
3.5 KiB
Markdown
134 lines
3.5 KiB
Markdown
# Calories Calculator API
|
|
|
|
A FastAPI-based API for tracking calories and nutritional information. This application allows users to register, track their food intake, and calculate their recommended calorie intake based on personal metrics.
|
|
|
|
## Features
|
|
|
|
- User registration and authentication
|
|
- Food database management
|
|
- Calorie tracking by meal type
|
|
- Daily and weekly calorie summaries
|
|
- BMR (Basal Metabolic Rate) and TDEE (Total Daily Energy Expenditure) calculations
|
|
- Personalized calorie recommendations based on goals
|
|
|
|
## Getting Started
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.8+
|
|
- SQLite
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone <repository-url>
|
|
cd caloriescalculatorapi
|
|
```
|
|
|
|
2. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run database migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
4. Start the application:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000.
|
|
|
|
### API Documentation
|
|
|
|
Once the application is running, you can access the interactive API documentation at:
|
|
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## API Endpoints
|
|
|
|
### Authentication
|
|
|
|
- `POST /api/v1/auth/register` - Register a new user
|
|
- `POST /api/v1/auth/login` - Login and get access token
|
|
- `POST /api/v1/auth/test-token` - Test if the token is valid
|
|
|
|
### Users
|
|
|
|
- `GET /api/v1/users/me` - Get current user data
|
|
- `PUT /api/v1/users/me` - Update current user data
|
|
|
|
### Foods
|
|
|
|
- `GET /api/v1/foods` - List food items
|
|
- `POST /api/v1/foods` - Create a new food item
|
|
- `GET /api/v1/foods/{food_id}` - Get a specific food item
|
|
- `PUT /api/v1/foods/{food_id}` - Update a food item
|
|
- `DELETE /api/v1/foods/{food_id}` - Delete a food item
|
|
- `GET /api/v1/foods/my-foods` - List food items created by the current user
|
|
|
|
### Calorie Entries
|
|
|
|
- `GET /api/v1/calorie-entries` - List calorie entries
|
|
- `POST /api/v1/calorie-entries` - Create a new calorie entry
|
|
- `GET /api/v1/calorie-entries/{entry_id}` - Get a specific calorie entry
|
|
- `PUT /api/v1/calorie-entries/{entry_id}` - Update a calorie entry
|
|
- `DELETE /api/v1/calorie-entries/{entry_id}` - Delete a calorie entry
|
|
- `GET /api/v1/calorie-entries/daily-summary` - Get daily calorie summary
|
|
- `GET /api/v1/calorie-entries/weekly-summary` - Get weekly calorie summary
|
|
|
|
### Calculator
|
|
|
|
- `POST /api/v1/calculator/calculate` - Calculate recommended calories
|
|
- `GET /api/v1/calculator/calculate-from-profile` - Calculate recommended calories based on user profile
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
app/
|
|
├── api/ # API endpoints
|
|
│ └── v1/
|
|
│ ├── endpoints/ # API route handlers
|
|
│ └── api.py # API router configuration
|
|
├── core/ # Core functionality
|
|
│ ├── config.py # Application configuration
|
|
│ ├── deps.py # Dependencies
|
|
│ └── security.py # Security utilities
|
|
├── db/ # Database configuration
|
|
│ ├── base.py # SQLAlchemy Base class
|
|
│ └── session.py # Database session setup
|
|
├── models/ # SQLAlchemy models
|
|
├── schemas/ # Pydantic schemas
|
|
├── services/ # Business logic
|
|
└── utils/ # Utility functions
|
|
migrations/ # Alembic migrations
|
|
main.py # Application entry point
|
|
```
|
|
|
|
## Development
|
|
|
|
### Running Tests
|
|
|
|
```bash
|
|
pytest
|
|
```
|
|
|
|
### Running Linters
|
|
|
|
```bash
|
|
ruff check .
|
|
```
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License.
|