Compare commits
No commits in common. "api_demo" and "main" have entirely different histories.
28
main.py
28
main.py
@ -1,5 +1,3 @@
|
|||||||
import random
|
|
||||||
import string
|
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from random import randint
|
from random import randint
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
@ -61,29 +59,3 @@ async def root():
|
|||||||
r = randint(1, cnt)
|
r = randint(1, cnt)
|
||||||
record = await RawData.get(id=r)
|
record = await RawData.get(id=r)
|
||||||
return {"title": record.title, "content": record.content}
|
return {"title": record.title, "content": record.content}
|
||||||
|
|
||||||
|
|
||||||
def generate_random_price():
|
|
||||||
return round(random.uniform(10.0, 1000.0), 2)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_random_sales():
|
|
||||||
return random.randint(100, 10000)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_random_batch_number():
|
|
||||||
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/product/")
|
|
||||||
async def get_product_info(name: str):
|
|
||||||
price = generate_random_price()
|
|
||||||
sales = generate_random_sales()
|
|
||||||
batch_number = generate_random_batch_number()
|
|
||||||
|
|
||||||
return {
|
|
||||||
"name": name,
|
|
||||||
"price": price,
|
|
||||||
"sales": sales,
|
|
||||||
"batch_number": batch_number
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user