Загрузка данных


from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
def check_health():
    return "health"

users = {}
notes = {}

@app.post("/register")
def register(username: str, password: str):
    print(users)
    if username in users:
        return {"msg": "user exists"}
    users[username] = password
    notes[username] = []
    return {"msg": "ok"}


@app.post("/login")
def login(username: str, password: str):
    if username in users:
        if users[username] == password:
            return {"msg": "login ok"}
    
    return {"msg": "error"}


@app.get("/create_note")
def get_user_notes(username: str, note: str):
    if not username or not note:
        return {"msg": "exist variable"}
    elif username not in users:
        return {"msg": "user exists"}
    
    notes[username].append(note)
    print(notes)
    return {"msg": "note added"}


@app.get("/get_notes")
def get_user_notes(username: str):
    if username not in users:
        return {"msg": "user exists"}
    elif not notes[username]:
        return {"msg": "no notes"}
    return notes[username]


@app.get("/change_note")
def change_user_notes(username: str, note_num: int, new_note: str):
    if note_num > len(notes[username]):
        return {"msg": f"note not found"}
    elif username not in users:
        return {"msg": "user exists"}

    notes[username].pop(note_num -1)
    notes[username].append(new_note)
    print(notes)

    return {"msg": f"note deleted: {note}"}



@app.get("/delete_note")
def delete_user_notes(username: str, note_num: int):
    if note_num > len(notes[username]):
        return {"msg": f"note not found"}
    elif username not in users:
        return {"msg": "user exists"}
    notes[username].pop(note_num -1)
    print(notes)
    return {"msg": f"note deleted"}