Spaces:
Build error
Build error
Create api/main.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354from fastapi import FastAPIfrom pydantic import BaseModel, ValidationError, validator
from pytezos import pytezos
app = FastAPI()
pytezos = pytezos.using(shell = 'https://rpc.tzkt.io/ghostnet', key='edsk3MrRkoidY2SjEgufvi44orvyjxgZoy4LhaJNTNcddWykW6SssL')contract = pytezos.contract('KT1KvCVKiZhkPG8s9CCoxW3r135phk2HhZUV')
# Define the request body modelclass Patient(BaseModel): name: str email: str contact: int age: int gender: str number: int #is_offer: bool = None @validator('name') def name_must_not_be_empty(cls, v): if v == ' ': raise ValueError('must contain a space') return v
@validator('email') def name_must_contain_at(cls, v): if '@' not in v: raise ValueError('must contain @ ') return v
@app.get("/")async def read_root(): return {"Hello": "World"}
# Define the POST route handler@app.post("/patient/")async def create_patient(patient: Patient): # patient object is validated automatically by FastAPI patient_dict = patient.dict() contract.addUser(email = patient.email, name = patient.name, age = patient.age, gender = patient.gender, number = patient.number).with_amount(0).as_transaction().fill().sign().inject() return {"message": f"User {patient.name} with email {patient.email} created successfully"}
api/main.pyAdded+54