Skip to content

Commit 205575a

Browse files
committed
Add justfile and modernize project tooling
The changes modernize the project setup by: - Adding a justfile for task automation - Switching to uv for dependency management - Adding proper project dependencies - Improving documentation with quick start guide - Adding new development commands
1 parent b0c81a9 commit 205575a

File tree

4 files changed

+675
-16
lines changed

4 files changed

+675
-16
lines changed

README.md

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,93 @@ This repository contains the code for the Marketplace service demo to follow alo
88

99
### How to run this service?
1010

11-
1. Create a python virtual environment and activate it:
11+
#### Prerequisites
12+
13+
1. Install [uv](https://docs.astral.sh/uv/) for Python package management
14+
2. Install [just](https://github.com/casey/just) for task running:
15+
- macOS: `brew install just`
16+
- Linux: `cargo install just` or download from releases
17+
- Windows: `scoop install just` or `cargo install just`
18+
19+
#### Quick Start
20+
21+
1. Install dependencies using uv:
1222

1323
```sh
14-
python3.12 -m venv ./venv
15-
source ./venv/bin/activate
24+
just install
1625
```
1726

18-
2. Install your service dependencies:
27+
2. Run the service:
1928

2029
```sh
21-
python3.12 -m pip install -r requirements.txt
30+
just run
2231
```
2332

24-
3. Run the service:
33+
3. In a new terminal window, test the API:
2534

2635
```sh
27-
./run.sh run
36+
# Get all customers
37+
just customers
38+
39+
# Get orders for customer 1
40+
just orders
41+
42+
# Get orders for a specific customer
43+
just orders 2
44+
45+
# Get order total
46+
just order-total 1
47+
48+
# Create a new order
49+
just new-order
50+
51+
# Test all endpoints at once
52+
just test-all
53+
```
54+
55+
#### Available Commands
56+
57+
Run `just` or `just --list` to see all available commands:
58+
59+
- `just run` - Start the marketplace server
60+
- `just customers` - Get all customers
61+
- `just orders [customer_id]` - Get customer orders (default customer_id=1)
62+
- `just order-total [order_id]` - Get order total cost (default order_id=1)
63+
- `just orders-between [before] [after]` - Get orders between dates
64+
- `just new-order` - Create a new order with default values
65+
- `just new-order-custom <customer_id> <items_json>` - Create a custom order
66+
- `just test-all` - Test all API endpoints
67+
- `just endpoints` - Show available API endpoints
68+
- `just install` - Install dependencies
69+
- `just lint` - Run code linting
70+
- `just format` - Format code
71+
- `just clean` - Clean up Python cache files
72+
73+
#### Legacy Method (still works)
74+
75+
If you prefer the old approach:
76+
77+
1. Create a python virtual environment and activate it:
78+
79+
```sh
80+
python3.12 -m venv ./venv
81+
source ./venv/bin/activate
2882
```
2983

30-
which is equivalent to
84+
2. Install your service dependencies:
3185

3286
```sh
33-
python3.12 marketsvc/server.py
87+
python3.12 -m pip install -r requirements.txt
3488
```
3589

36-
4. In a new terminal window, run the `curl` commands:
90+
3. Run the service:
3791

3892
```sh
39-
./run.sh customers
93+
./run.sh run
4094
```
4195

42-
which is equivalent to
96+
4. Test the API:
4397

4498
```sh
45-
curl http://localhost:9090/api/customers
99+
./run.sh customers
46100
```

justfile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Marketplace SQLAlchemy Workshop - Task Runner
2+
# Use 'just --list' to see all available commands
3+
4+
# Default recipe to display help
5+
default:
6+
@just --list
7+
8+
# Run the marketplace server
9+
run:
10+
uv run python marketsvc/server.py
11+
12+
# Get all customers
13+
customers:
14+
curl http://localhost:9090/api/customers
15+
16+
# Get customer orders (specify customer_id, default=1)
17+
orders customer_id="1":
18+
curl http://localhost:9090/api/orders/{{customer_id}}
19+
20+
# Get order total cost (specify order_id, default=1)
21+
order-total order_id="1":
22+
curl http://localhost:9090/api/order_total/{{order_id}}
23+
24+
# Get orders between dates
25+
orders-between before="2024-03-22" after="2024-03-14":
26+
curl "http://localhost:9090/api/orders_between_dates/{{before}}/{{after}}"
27+
28+
# Create a new order
29+
new-order:
30+
curl -H "Content-Type: application/json" -d '{"customer_id":1,"items":[{"id":2,"quantity":4},{"id":3,"quantity":6}]}' http://localhost:9090/api/add_new_order
31+
32+
# Create a custom new order (specify customer_id and items as JSON string)
33+
new-order-custom customer_id items:
34+
curl -H "Content-Type: application/json" -d '{"customer_id":{{customer_id}},"items":{{items}}}' http://localhost:9090/api/add_new_order
35+
36+
# Install dependencies using uv
37+
install:
38+
uv sync
39+
40+
# Install development dependencies
41+
install-dev:
42+
uv sync --dev
43+
44+
# Run linting with ruff
45+
lint:
46+
uv run ruff check .
47+
48+
# Format code with ruff
49+
format:
50+
uv run ruff format .
51+
52+
# Run both linting and formatting
53+
check: lint format
54+
55+
# Clean up Python cache files
56+
clean:
57+
find . -type f -name "*.pyc" -delete
58+
find . -type d -name "__pycache__" -delete
59+
60+
# Show API endpoints (requires server to be running)
61+
endpoints:
62+
@echo "Available API endpoints:"
63+
@echo " GET http://localhost:9090/"
64+
@echo " GET http://localhost:9090/api/customers"
65+
@echo " GET http://localhost:9090/api/orders/{customer_id}"
66+
@echo " GET http://localhost:9090/api/order_total/{order_id}"
67+
@echo " GET http://localhost:9090/api/orders_between_dates/{before}/{after}"
68+
@echo " POST http://localhost:9090/api/add_new_order"
69+
70+
# Test all endpoints (requires server to be running in another terminal)
71+
test-all:
72+
@echo "Testing all endpoints..."
73+
@echo "\n1. Testing root endpoint:"
74+
-curl -s http://localhost:9090/
75+
@echo "\n\n2. Testing customers:"
76+
-curl -s http://localhost:9090/api/customers
77+
@echo "\n\n3. Testing customer orders:"
78+
-curl -s http://localhost:9090/api/orders/1
79+
@echo "\n\n4. Testing order total:"
80+
-curl -s http://localhost:9090/api/order_total/1
81+
@echo "\n\n5. Testing orders between dates:"
82+
-curl -s "http://localhost:9090/api/orders_between_dates/2024-03-22/2024-03-14"
83+
@echo "\n\n6. Testing new order creation:"
84+
-curl -s -H "Content-Type: application/json" -d '{"customer_id":1,"items":[{"id":2,"quantity":4},{"id":3,"quantity":6}]}' http://localhost:9090/api/add_new_order
85+
@echo "\n\nAll tests completed!"

pyproject.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ authors = [
1212
{ name = "Aya Elsayed", email = "ayah.ehab11@gmail.com" },
1313
{ name = "Rhythm Patel", email = "rhythmkumar18083@iiitd.ac.in" },
1414
]
15-
dependencies = []
15+
dependencies = [
16+
"fastapi",
17+
"uvicorn[standard]",
18+
"sqlalchemy",
19+
"aiosqlite",
20+
"greenlet",
21+
]
1622

1723
[project.optional-dependencies]
18-
dev = ["ruff"]
24+
dev = [
25+
"ruff",
26+
]
1927

2028
[tool.setuptools.packages.find]
21-
where = ["marketsvc"]
29+
where = ["."]
30+
include = ["marketsvc*"]
31+
32+
[tool.uv]
33+
dev-dependencies = []

0 commit comments

Comments
 (0)