
- Set up project structure with FastAPI and SQLite - Implement user authentication with JWT - Create database models for users, events, bets, and transactions - Add API endpoints for user management - Add API endpoints for events and betting functionality - Add wallet management for deposits and withdrawals - Configure Alembic for database migrations - Add linting with Ruff - Add documentation in README
182 lines
4.1 KiB
Markdown
182 lines
4.1 KiB
Markdown
# Betting Application API
|
|
|
|
A FastAPI-based backend for a betting application. This API provides functionality for user management, betting on events, wallet operations, and more.
|
|
|
|
## Features
|
|
|
|
- User authentication and management
|
|
- Event creation and management
|
|
- Betting functionality
|
|
- Wallet management (deposits, withdrawals)
|
|
- Transaction history
|
|
- Admin features for event management and bet settlement
|
|
|
|
## Requirements
|
|
|
|
- Python 3.9+
|
|
- SQLite database
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone https://github.com/yourusername/betting-application-api.git
|
|
cd betting-application-api
|
|
```
|
|
|
|
2. Set up a virtual environment:
|
|
|
|
```bash
|
|
python -m venv venv
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
```
|
|
|
|
3. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
4. Create a `.env` file in the root directory with the following content (customize as needed):
|
|
|
|
```
|
|
# App configuration
|
|
SECRET_KEY=yoursecretkey
|
|
API_V1_STR=/api/v1
|
|
PROJECT_NAME=betting-application-api
|
|
ENVIRONMENT=development
|
|
|
|
# JWT Settings
|
|
ACCESS_TOKEN_EXPIRE_MINUTES=30
|
|
JWT_ALGORITHM=HS256
|
|
JWT_SECRET_KEY=your_jwt_secret_key
|
|
|
|
# Security
|
|
ALLOWED_HOSTS=["*"]
|
|
|
|
# Admin user
|
|
FIRST_SUPERUSER_EMAIL=admin@example.com
|
|
FIRST_SUPERUSER_PASSWORD=admin123
|
|
```
|
|
|
|
5. Initialize the database and run migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
## Running the API
|
|
|
|
Start the API server:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000.
|
|
|
|
API documentation is available at:
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## API Endpoints
|
|
|
|
### Authentication
|
|
|
|
- `POST /api/v1/auth/login` - Get access token (OAuth2)
|
|
|
|
### Users
|
|
|
|
- `POST /api/v1/users` - Register a new user
|
|
- `GET /api/v1/users/me` - Get current user information
|
|
- `PUT /api/v1/users/me` - Update current user information
|
|
- `GET /api/v1/users/{user_id}` - Get user by ID (admin or self)
|
|
- `GET /api/v1/users` - List all users (admin only)
|
|
|
|
### Events
|
|
|
|
- `GET /api/v1/events` - List all events (filter by status)
|
|
- `POST /api/v1/events` - Create a new event (admin only)
|
|
- `GET /api/v1/events/{event_id}` - Get event by ID
|
|
- `PUT /api/v1/events/{event_id}` - Update event (admin only)
|
|
- `DELETE /api/v1/events/{event_id}` - Delete event (admin only)
|
|
- `POST /api/v1/events/outcomes/{outcome_id}/settle` - Settle an outcome (admin only)
|
|
|
|
### Bets
|
|
|
|
- `GET /api/v1/bets` - List user's bets (filter by status)
|
|
- `POST /api/v1/bets` - Place a new bet
|
|
- `GET /api/v1/bets/{bet_id}` - Get bet by ID
|
|
- `POST /api/v1/bets/{bet_id}/cancel` - Cancel a pending bet
|
|
|
|
### Wallet
|
|
|
|
- `GET /api/v1/wallet/balance` - Get user's balance
|
|
- `GET /api/v1/wallet/transactions` - Get user's transaction history
|
|
- `POST /api/v1/wallet/deposit` - Deposit funds
|
|
- `POST /api/v1/wallet/withdraw` - Withdraw funds
|
|
|
|
### Health Check
|
|
|
|
- `GET /health` - API health check
|
|
|
|
## Models
|
|
|
|
### User
|
|
|
|
- id: Unique identifier
|
|
- email: User's email (unique)
|
|
- full_name: User's full name
|
|
- is_active: User account status
|
|
- is_admin: Admin privileges flag
|
|
- balance: User's wallet balance
|
|
|
|
### Event
|
|
|
|
- id: Unique identifier
|
|
- name: Event name
|
|
- description: Event description
|
|
- start_time: When the event starts
|
|
- end_time: When the event ends
|
|
- status: upcoming, live, finished, or cancelled
|
|
|
|
### Market
|
|
|
|
- id: Unique identifier
|
|
- event_id: Associated event
|
|
- name: Market name
|
|
- is_active: Market availability status
|
|
|
|
### Outcome
|
|
|
|
- id: Unique identifier
|
|
- market_id: Associated market
|
|
- name: Outcome name
|
|
- odds: Betting odds
|
|
- is_winner: Result status
|
|
- is_active: Outcome availability status
|
|
|
|
### Bet
|
|
|
|
- id: Unique identifier
|
|
- user_id: User who placed the bet
|
|
- outcome_id: The selected outcome
|
|
- amount: Bet amount
|
|
- odds: Odds at time of bet
|
|
- potential_win: Potential winnings
|
|
- status: pending, won, lost, cancelled, or voided
|
|
|
|
### Transaction
|
|
|
|
- id: Unique identifier
|
|
- user_id: Associated user
|
|
- amount: Transaction amount
|
|
- transaction_type: deposit, withdrawal, bet_placed, bet_won, bet_lost, or bet_refund
|
|
- status: pending, completed, failed, or cancelled
|
|
- reference: External reference (optional)
|
|
- bet_id: Associated bet (optional)
|
|
|
|
## License
|
|
|
|
MIT |