File size: 2,106 Bytes
0c24b98
a9b69c1
2be612d
0c24b98
2be612d
d4116f0
 
0c24b98
2be612d
a9b69c1
 
 
 
 
 
 
 
 
 
 
0c24b98
 
 
a9b69c1
 
 
d4116f0
a9b69c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc4835f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from fastapi import FastAPI
from pydantic import BaseModel
import os

aa = os.getenv("a")
passw = os.getenv("as")

app = FastAPI()
print(aa)
# Initialize the arrays
Greet = []
Bye = []
Sleep = []
Care = []

class Operation(BaseModel):
    a: str
    b: str
    c: str

@app.get("/")
def greet_json():
    return {"Hello": "World!"}

@app.post("/add/")
async def add(op: Operation):
    if op.a == passw:
        target_list = None
        if op.b == 'Greet':
            target_list = Greet
        elif op.b == 'Bye':
            target_list = Bye
        elif op.b == 'Sleep':
            target_list = Sleep
        elif op.b == 'Care':
            target_list = Care

        if target_list is not None:
            target_list.append(op.c)
            return {"result": target_list}
        else:
            return {"result": "Invalid category"}
    else:
        return {"result": "Invalid operation"}

@app.post("/remove/")
async def remove(op: Operation):
    if op.a == 'Check':
        target_list = None
        if op.b == 'Greet':
            target_list = Greet
        elif op.b == 'Bye':
            target_list = Bye
        elif op.b == 'Sleep':
            target_list = Sleep
        elif op.b == 'Care':
            target_list = Care

        if target_list is not None:
            if op.c in target_list:
                target_list.remove(op.c)
                return {"result": target_list}
            else:
                return {"result": "Element not found in the list"}
        else:
            return {"result": "Invalid category"}
    else:
        return {"result": "Invalid operation"}


@app.post("/check/")
async def add(op: Operation):
    if op.a == 'Check':
        target_list = None
        if op.b == 'Greet':
            target_list = Greet
        elif op.b == 'Bye':
            target_list = Bye
        elif op.b == 'Sleep':
            target_list = Sleep
        elif op.b == 'Care':
            target_list = Care
        if target_list is not None:    
            return {"result": target_list}
    else:
        return {"result": "Invalid operation"}