Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ZIT-P22/IP-Atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonKohli committed Feb 8, 2024
2 parents 5056e96 + 9cc2301 commit 3e1163e
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion ip-atlas/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,57 @@ def write_to_db(db, data):
elif db == "host_tag":
host_tag = HostTag(host_id=data["host_id"], tag_id=data["tag_id"])
db.session.add(host_tag)
db.session.commit()
elif db == "portFB":
portFB = PortFB(host_id=data["host_id"], portFB_number=data["portFB_number"])
db.session.add(portFB)
else:
print("Error: Database not found")


# function which deletes the given data from the database
def delete_from_db(db, id):
if db == "host":
host = Host.query.filter_by(id=id).first()
host.deleted = True
elif db == "port":
port = Port.query.filter_by(id=id).first()
db.session.delete(port)
elif db == "tag":
tag = Tag.query.filter_by(id=id).first()
tag.deleted = True
elif db == "host_tag":
host_tag = HostTag.query.filter_by(id=id).first()
db.session.delete(host_tag)
elif db == "portFB":
portFB = PortFB.query.filter_by(id=id).first()
db.session.delete(portFB)
else:
print("Error: Database not found")


# function which updates the given data in the database
def edit_db(db, data):
if db == "host":
host = Host.query.filter_by(id=data["id"]).first()
host.hostname = data["name"]
host.ipv4 = data["ipv4"]
host.ipv6 = data["ipv6"]
elif db == "port":
port = Port.query.filter_by(id=data["id"]).first()
port.port_number = data["port_number"]
elif db == "tag":
tag = Tag.query.filter_by(id=data["id"]).first()
tag.tag_name = data["tag_name"]
elif db == "host_tag":
host_tag = HostTag.query.filter_by(id=data["id"]).first()
host_tag.host_id = data["host_id"]
host_tag.tag_id = data["tag_id"]
elif db == "portFB":
portFB = PortFB.query.filter_by(id=data["id"]).first()
portFB.portFB_number = data["portFB_number"]
else:
print("Error: Database not found")




0 comments on commit 3e1163e

Please sign in to comment.