
- Set up project structure with FastAPI - Implement user authentication system with JWT tokens - Create database models for users, notes, and collections - Set up SQLAlchemy ORM and Alembic migrations - Implement CRUD operations for notes and collections - Add filtering and sorting capabilities for notes - Implement health check endpoint - Update project documentation
139 lines
3.8 KiB
Markdown
139 lines
3.8 KiB
Markdown
# Notes API
|
|
|
|
A RESTful API for managing notes with user authentication, collections/folders, and advanced filtering capabilities.
|
|
|
|
## Features
|
|
|
|
- User authentication (sign up, login, logout)
|
|
- CRUD operations for notes
|
|
- Group notes into collections/folders
|
|
- Sort notes by various criteria (created date, updated date, title)
|
|
- Search notes by title and content
|
|
- Filter notes by collection, archived status, and date range
|
|
|
|
## Tech Stack
|
|
|
|
- **Backend**: FastAPI
|
|
- **Database**: SQLite with SQLAlchemy ORM
|
|
- **Authentication**: JWT tokens with OAuth2
|
|
- **Migrations**: Alembic
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── alembic/ # Database migrations
|
|
├── app/
|
|
│ ├── api/ # API endpoints
|
|
│ │ └── v1/ # API version 1
|
|
│ ├── core/ # Core application settings
|
|
│ ├── crud/ # Database CRUD operations
|
|
│ ├── db/ # Database setup
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ └── schemas/ # Pydantic schemas
|
|
├── storage/
|
|
│ └── db/ # SQLite database storage
|
|
├── .env # Environment variables
|
|
├── alembic.ini # Alembic configuration
|
|
├── main.py # Application entry point
|
|
└── requirements.txt # Project dependencies
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone <repository-url>
|
|
cd notes-api
|
|
```
|
|
|
|
2. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Set up environment variables:
|
|
|
|
Create a `.env` file in the root directory with the following variables:
|
|
|
|
```
|
|
SECRET_KEY=your-secret-key
|
|
CORS_ORIGINS=http://localhost:3000,http://localhost:8080
|
|
```
|
|
|
|
4. Run database migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
5. Run 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` - Log in and get access token
|
|
- `GET /api/v1/auth/me` - Get current user information
|
|
|
|
### Users
|
|
|
|
- `GET /api/v1/users/` - List all users
|
|
- `GET /api/v1/users/{user_id}` - Get user by ID
|
|
- `GET /api/v1/users/me` - Get current user
|
|
- `PUT /api/v1/users/me` - Update current user
|
|
|
|
### Notes
|
|
|
|
- `GET /api/v1/notes/` - List notes with various filtering and sorting options
|
|
- `POST /api/v1/notes/` - Create a new note
|
|
- `GET /api/v1/notes/{id}` - Get a note by ID
|
|
- `PUT /api/v1/notes/{id}` - Update a note
|
|
- `DELETE /api/v1/notes/{id}` - Delete a note
|
|
|
|
### Collections
|
|
|
|
- `GET /api/v1/collections/` - List all collections
|
|
- `POST /api/v1/collections/` - Create a new collection
|
|
- `GET /api/v1/collections/{id}` - Get a collection by ID
|
|
- `PUT /api/v1/collections/{id}` - Update a collection
|
|
- `DELETE /api/v1/collections/{id}` - Delete a collection
|
|
- `GET /api/v1/collections/{id}/notes` - Get all notes in a collection
|
|
|
|
### Health Check
|
|
|
|
- `GET /health` - Check API health status
|
|
|
|
## Notes API Query Parameters
|
|
|
|
The Notes API (`GET /api/v1/notes/`) supports the following query parameters for filtering and sorting:
|
|
|
|
- `skip`: Number of items to skip (pagination)
|
|
- `limit`: Maximum number of items to return (pagination)
|
|
- `sort_by`: Field to sort by (`created_at`, `updated_at`, `title`)
|
|
- `sort_order`: Sort order (`asc`, `desc`)
|
|
- `search`: Search term for title and content
|
|
- `archived`: Filter by archived status (`true`, `false`)
|
|
- `collection_id`: Filter by collection ID
|
|
- `start_date`: Filter notes created after this date
|
|
- `end_date`: Filter notes created before this date
|
|
|
|
## License
|
|
|
|
MIT |