This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
48 lines (32 loc) · 1.36 KB
/
example.py
File metadata and controls
48 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from cryptic import MicroService, get_config, Config
from uuid import uuid4
from sqlalchemy import Column, String
from typing import Union, Dict
from scheme import Text, UUID
config: Config = get_config("debug") # this sets config to debug mode
ms: MicroService = MicroService(name="echo")
db_wrapper = ms.get_wrapper()
requirement: Dict[str, Text] = {"your_pets_name": Text(required=True), "wallet": UUID()}
@ms.microservice_endpoint(path=["microservice"])
def handle(data: dict, microservice: str):
return {"myname": "microservice"}
@ms.user_endpoint(path=["user"], requires=requirement)
def handle(data: dict, user: str):
can_pay: bool = ms.contact_microservice("currency", ["exists"], {"source_uuid": data["wallet"]})["exists"]
if can_pay:
mypet: Test = Test.create(data["your_pets_name"])
return {"uuid": mypet.uuid}
else:
return {"error": "you_need_a_valid_wallet"}
class Test(db_wrapper.Base):
__tablename__: str = "test"
uuid: Union[Column, str] = Column(String(36), primary_key=True, unique=True)
name: Union[Column, str] = Column(String(255), nullable=False)
@staticmethod
def create(name: str) -> "Test":
my_test: Test = Test(uuid=str(uuid4()), name=name)
db_wrapper.session.add(my_test)
db_wrapper.session.commit()
return my_test
if __name__ == "__main__":
ms.run()