RentHub Service API¶
Port 3003 rent_db
The RentHub service manages peer-to-peer rental listings and transactions for campus items.
Overview¶
| Property | Value |
|---|---|
| Port | 3003 |
| Database | rent_db |
| Base Path | /api/renthub |
| Auth Required | Partial (viewing is public) |
Database Schema¶
Tables¶
erDiagram
rental_listings ||--o{ rental_transactions : has
rental_listings {
uuid id PK
uuid owner_id
varchar title
text description
varchar category
decimal daily_price
decimal weekly_price
decimal monthly_price
decimal deposit_amount
text[] images
varchar location
varchar condition
varchar status
timestamp created_at
}
rental_transactions {
uuid id PK
uuid listing_id FK
uuid owner_id
uuid renter_id
date start_date
date end_date
decimal total_amount
decimal deposit_paid
varchar status
text return_condition
timestamp created_at
}
API Endpoints¶
Listings¶
Get All Listings¶
GET /listings
Returns all available rental listings.
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
category |
string | Filter by category |
status |
string | Filter by status (default: AVAILABLE) |
minPrice |
number | Minimum daily price |
maxPrice |
number | Maximum daily price |
search |
string | Search in title/description |
limit |
number | Results per page |
offset |
number | Pagination offset |
{
"success": true,
"count": 18,
"data": [
{
"id": "uuid",
"owner_id": "uuid",
"owner_name": "John Doe",
"title": "Calculus Textbook",
"description": "Stewart Calculus 8th Ed",
"category": "Books",
"daily_price": 20.00,
"weekly_price": 100.00,
"monthly_price": 350.00,
"deposit_amount": 200.00,
"images": ["https://..."],
"location": "UIU Campus",
"condition": "GOOD",
"status": "AVAILABLE",
"created_at": "2024-01-15T10:00:00Z"
}
]
}
Get Listing by ID¶
GET /listings/:id
{
"success": true,
"data": {
"id": "uuid",
"owner_id": "uuid",
"owner": {
"name": "John Doe",
"email": "john@uiu.edu",
"phone": "+8801712345678"
},
"title": "Calculus Textbook",
"description": "Full description...",
"category": "Books",
"daily_price": 20.00,
"weekly_price": 100.00,
"monthly_price": 350.00,
"deposit_amount": 200.00,
"images": ["https://..."],
"location": "UIU Campus, Building 5",
"condition": "GOOD",
"status": "AVAILABLE",
"created_at": "2024-01-15T10:00:00Z"
}
}
Create Listing¶
POST /listings
Authentication Required
Categories:
| Category | Description |
|---|---|
Books |
Textbooks, novels, references |
Electronics |
Laptops, tablets, cameras |
Sports |
Sports equipment, gear |
Instruments |
Musical instruments |
Furniture |
Chairs, desks, shelves |
Tools |
Study tools, equipment |
Clothing |
Formal wear, costumes |
Other |
Miscellaneous items |
Conditions:
NEW- Brand new, unusedLIKE_NEW- Barely used, excellentGOOD- Normal wear, fully functionalFAIR- Visible wear, works fine
Update Listing¶
PUT /listings/:id
Owner Only
Delete Listing¶
DELETE /listings/:id
Owner Only
User Listings¶
Get My Listings¶
GET /listings/my
Authentication Required
Returns all listings owned by the current user.
Transactions¶
Create Rental Request¶
POST /transactions
Authentication Required
Pricing Calculation
- 1-6 days: Daily rate × days
- 7-29 days: Weekly rate × weeks (rounded up)
- 30+ days: Monthly rate × months (rounded up)
Get My Rentals¶
GET /transactions/renting
Authentication Required
Returns items the current user is renting.
Get Rental Requests (Owner)¶
GET /transactions/requests
Authentication Required
Returns pending rental requests for the owner's listings.
Approve/Reject Request¶
PATCH /transactions/:id/status
Owner Only
Mark as Returned¶
PATCH /transactions/:id/return
Owner Only
Dashboard¶
Get Rental Statistics¶
GET /dashboard/stats
Authentication Required
Transaction Flow¶
sequenceDiagram
participant R as Renter
participant F as Frontend
participant S as RentHub Service
participant O as Owner
R->>F: Browse listings
F->>S: GET /listings
S-->>F: Return available items
R->>F: Select item & dates
F->>S: POST /transactions
S-->>F: Rental request created
Note over S: Status: PENDING
O->>F: View rental requests
F->>S: GET /transactions/requests
O->>F: Approve rental
F->>S: PATCH /transactions/:id/status
Note over S: Status: ACTIVE
R->>R: Use item during rental
R->>O: Return item
O->>F: Mark as returned
F->>S: PATCH /transactions/:id/return
Note over S: Status: COMPLETED
Transaction Statuses¶
| Status | Description |
|---|---|
PENDING |
Request submitted, awaiting owner approval |
ACTIVE |
Approved and currently rented |
COMPLETED |
Item returned successfully |
CANCELLED |
Request rejected or cancelled |
Error Codes¶
| Code | Message | Description |
|---|---|---|
| 400 | Invalid dates | End date before start date |
| 400 | Item not available | Already rented for dates |
| 401 | Unauthorized | Missing or invalid JWT |
| 403 | Not owner | Cannot modify others' listings |
| 404 | Listing not found | Invalid listing ID |
| 409 | Already rented | Item already in active rental |