@@ -10,62 +10,63 @@ Pypi Seite: https://pypi.org/project/cryptic-game/
10
10
$ pip3 install cryptic-game
11
11
```
12
12
13
+ ## Features
14
+
15
+ - Endpoint Mapping
16
+ - automatic input validation
17
+ - Database Control
18
+ - Sentry and Logger -> Stacktraces and given Data
19
+
13
20
## Quick Start
14
21
15
22
``` python
16
23
from cryptic import MicroService, get_config, Config
17
24
from uuid import uuid4
18
25
from sqlalchemy import Column, String
19
- from typing import Union
20
- from scheme import *
26
+ from typing import Union, Dict
27
+ from scheme import Text, UUID
21
28
22
29
config: Config = get_config(" debug" ) # this sets config to debug mode
23
30
ms: MicroService = MicroService(name = " echo" )
24
- wrapper = ms.get_wrapper()
31
+ db_wrapper = ms.get_wrapper()
25
32
26
- user_device: dict = {
27
- ' user_uuid' : Text(nonempty = True ),
28
- ' device_uuid' : Email(nonempty = True ),
29
- ' active' : Boolean(required = True , default = True ),
30
- ' somedata' : Integer(minimum = 0 , default = 0 ),
31
- }
32
- # just giving an empty dictionary will be interpreted as no validation required.
33
+ requirement: Dict[str , Text] = {" your_pets_name" : Text(required = True ), " wallet" : UUID()}
33
34
34
35
35
36
@ms.microservice_endpoint (path = [" microservice" ])
36
37
def handle (data : dict , microservice : str ):
37
- # excepts from other ms right data
38
- return {" name" : data[" yourname" ]}
38
+ return {" myname" : " microservice" }
39
39
40
40
41
- @ms.user_endpoint (path = [" user" ], requires = user_device )
41
+ @ms.user_endpoint (path = [" user" ], requires = requirement )
42
42
def handle (data : dict , user : str ):
43
- # Input is now already validated
44
- print (user, data[" active" ])
45
- return {" ok" : True }
43
+ can_pay: bool = ms.contact_microservice(" currency" , [" exists" ], {" source_uuid" : data[" wallet" ]})[" exists" ]
46
44
45
+ if can_pay:
46
+ mypet: Test = Test.create(data[" your_pets_name" ])
47
47
48
- if __name__ == ' __main__' :
49
- ms.run()
48
+ return {" uuid" : mypet.uuid}
49
+ else :
50
+ return {" error" : " you_need_a_valid_wallet" }
50
51
51
52
52
- class Test (wrapper .Base ):
53
- __tablename__: str = ' test'
53
+ class Test (db_wrapper .Base ):
54
+ __tablename__: str = " test"
54
55
55
56
uuid: Union[Column, str ] = Column(String(36 ), primary_key = True , unique = True )
56
57
name: Union[Column, str ] = Column(String(255 ), nullable = False )
57
58
58
59
@ staticmethod
59
- def create (name : str ) -> ' Test' :
60
+ def create (name : str ) -> " Test" :
60
61
my_test: Test = Test(uuid = str (uuid4()), name = name)
61
-
62
- wrapper .session.add(my_test)
63
- wrapper .session.commit()
62
+
63
+ db_wrapper .session.add(my_test)
64
+ db_wrapper .session.commit()
64
65
65
66
return my_test
66
67
67
68
68
- if __name__ == ' __main__' :
69
+ if __name__ == " __main__" :
69
70
ms.run()
70
71
```
71
72
@@ -77,13 +78,6 @@ Required are all modules in the `requirements.txt`.
77
78
78
79
Your microservice will be supported by the [ game-server of cryptic] ( https://github.com/cryptic-game/server ) .
79
80
80
- ### Environment variables
81
-
82
- | key | default value |
83
- | -------------------| ---------------|
84
- | SERVER_HOST | 127.0.0.1 |
85
- | SERVER_PORT | 1239 |
86
-
87
81
## Wiki
88
82
89
83
Visit our [ wiki] ( https://github.com/cryptic-game/python3-lib/wiki ) for more information.
0 commit comments