| 1 | KINDS = {"note", "task", "event"} |
| 2 | |
| 3 | |
| 4 | def handle_create(req): |
| 5 | if not isinstance(req, dict): |
| 6 | return ("error", "not a request") |
| 7 | if "id" not in req: |
| 8 | return ("error", "missing id") |
| 9 | if not isinstance(req["id"], int) or req["id"] <= 0: |
| 10 | return ("error", "bad id") |
| 11 | if req.get("kind") not in KINDS: |
| 12 | return ("error", "bad kind") |
| 13 | return ("ok", f"created {req['kind']} {req['id']}") |
| 14 | |
| 15 | |
| 16 | def handle_update(req): |
| 17 | if not isinstance(req, dict): |
| 18 | return ("error", "not a request") |
| 19 | if "id" not in req: |
| 20 | return ("error", "missing id") |
| 21 | if not isinstance(req["id"], int) or req["id"] <= 0: |
| 22 | return ("error", "bad id") |
| 23 | if req.get("kind") not in KINDS: |
| 24 | return ("error", "bad kind") |
| 25 | return ("ok", f"updated {req['kind']} {req['id']}") |
| 26 | |
| 27 | |
| 28 | def handle_delete(req): |
| 29 | if not isinstance(req, dict): |
| 30 | return ("error", "not a request") |
| 31 | if "id" not in req: |
| 32 | return ("error", "missing id") |
| 33 | if not isinstance(req["id"], int) or req["id"] <= 0: |
| 34 | return ("error", "bad id") |
| 35 | if req.get("kind") not in KINDS: |
| 36 | return ("error", "bad kind") |
| 37 | return ("ok", f"deleted {req['kind']} {req['id']}") |
| 38 |