Skip to content

Commit

Permalink
Fixed linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalS99 committed Jan 17, 2023
1 parent 6daa3da commit 9a17c75
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 131 deletions.
23 changes: 14 additions & 9 deletions backend/application.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
""" Main server file """
import json
from datetime import datetime
from flask_cors import CORS
from flask import Flask, session, Response
from flask_session import Session
from flask_cors import CORS
from datetime import datetime
from utils import get_connection, config_app


sauron = Flask(__name__)
PATH = "config.json"
sauron = config_app(sauron, path=PATH)
CORS(sauron)
path = "config.json"

sauron = config_app(sauron, path=path)
conn = get_connection()
Session(sauron)


#pylint: disable=wrong-import-position
from experience import experience_api
from bio import bio_api
from projects import projects_api
Expand All @@ -29,11 +30,12 @@

@sauron.route("/sauron/health", methods = ["GET"])
def health():
t = str(datetime.now())
""" Server health """
_t = str(datetime.now())
msg = {
"name": "Sauron-Service",
"health": "Excellent",
"at time": t
"at time": _t
}
session.clear()
result = Response(json.dumps(msg), status=200, content_type="application/json")
Expand All @@ -42,12 +44,15 @@ def health():

@sauron.route("/sauron/login", methods = ["POST"])
def login():
""" Manage Login """
pass

sauron.route("/sauron/logout", methods = ["GET"])
def logout():
""" Manage Logout """
pass


if __name__ == "__main__":
sauron.run('0.0.0.0', port = 5011, debug=True)
sauron.run('0.0.0.0', port = 5011, debug=True)

59 changes: 34 additions & 25 deletions backend/bio.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,94 @@
""" This file manages routes for bio """
import json
import uuid
from datetime import datetime
from flask import Blueprint, Response, request
import requests
from datetime import datetime
from utils import get_connection
from model import Bio
import uuid

bio_api = Blueprint('bio_api', __name__)
conn = get_connection()
table = "Bio"
TABLE = "Bio"
URL = "http://localhost:5011/"


@bio_api.route("/health", methods = ["GET"])
@bio_api.route("/health", methods=["GET"])
def test():
t = str(datetime.now())
""" Test """
_t = str(datetime.now())
msg = {
"name": "Sauron-Bio-Service",
"health": "Excellent",
"at time": t
"at time": _t
}
result = Response(json.dumps(msg), status=200, content_type="application/json")
result = Response(json.dumps(msg), status=200,
content_type="application/json")
return result

@bio_api.route("/get", methods = ["GET"])

@bio_api.route("/get", methods=["GET"])
def get_bio():
""" Get bio info """
cursor = conn.cursor()
cursor.execute("SELECT * FROM {}".format(table))
cursor.execute("SELECT * FROM {}".format(TABLE))
query_result = cursor.fetchall()

if len(query_result) == 0:
return "No bio exists", 404

return {"data": Bio(*query_result[0].values()).__dict__}


@bio_api.route("/add", methods = ["POST"])
@bio_api.route("/add", methods=["POST"])
def add_bio():
""" Add bio """
data = request.json
msg = requests.get(URL + "/sauron/backend/bio/get")
msg = requests.get(URL + "/sauron/backend/bio/get", timeout=5)
if msg.status_code == 200:
return "Bio already exists", 400
try:
id = str(uuid.uuid4())
query = "INSERT INTO {} VALUES ('{}', '{}')".format(table, id, data['data'])
try:
id_ = str(uuid.uuid4())
query = "INSERT INTO {} VALUES ('{}', '{}')".format(
TABLE, id_, data['data'])
cursor = conn.cursor()
cursor.execute(query)
conn.commit()
except:
except Exception:
conn.rollback()
return "Failed to add bio", 500
return "Added bio", 200


@bio_api.route("/update", methods = ["PUT"])
@bio_api.route("/update", methods=["PUT"])
def update_bio():
""" Update bio """
data = request.json
msg = requests.get(URL + "/sauron/backend/bio/get")
msg = requests.get(URL + "/sauron/backend/bio/get", timeout=5)
if msg.status_code == 400:
return "Bio does not exist", 400
id = msg.json()['data']['id']
id_ = msg.json()['data']['id']
try:
query = "UPDATE {} SET bio = '{}' where id = '{}'".format(table, data['data'], id)
query = "UPDATE {} SET bio = '{}' where id = '{}'".format(
TABLE, data['data'], id_)
cursor = conn.cursor()
cursor.execute(query)
conn.commit()
except:
except Exception:
conn.rollback()
return "Failed to update bio", 500

return "Updated bio", 200


@bio_api.route("/delete", methods = ["DELETE"])
@bio_api.route("/delete", methods=["DELETE"])
def remove_bio():
""" Remove bio """
cursor = conn.cursor()
cursor.execute("DELETE FROM {}".format(table))
cursor.execute("DELETE FROM {}".format(TABLE))
query_result = cursor.fetchall()

if len(query_result) == 0:
return "Deleted", 200

return None

return None
70 changes: 40 additions & 30 deletions backend/experience.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,98 @@
""" This file manages routes for experience """
import json
from flask import Blueprint, Response
import requests
from datetime import datetime
import requests
from flask import Blueprint, Response
from utils import get_connection
from model import Experience


experience_api = Blueprint('experience_api', __name__)
conn = get_connection()
URL = "http://localhost:5011"
table = "Experience"
TABLE = "Experience"


@experience_api.route("/health", methods = ["GET"])
@experience_api.route("/health", methods=["GET"])
def test():
t = str(datetime.now())
""" Test """
_t = str(datetime.now())
msg = {
"name": "Sauron-Experience-Service",
"health": "Excellent",
"at time": t
"at time": _t
}
result = Response(json.dumps(msg), status=200, content_type="application/json")
result = Response(json.dumps(msg), status=200,
content_type="application/json")
return result

@experience_api.route("/get/all", methods = ["GET"])

@experience_api.route("/get/all", methods=["GET"])
def get_all_experiences():
""" Get all experiences """
cursor = conn.cursor()
cursor.execute("SELECT * FROM {}".format(table))
cursor.execute("SELECT * FROM {}".format(TABLE))
query_result = cursor.fetchall()

if query_result is None:
return "No experience exists", 404

data = []

for exp in query_result:
data.append({"data": Experience(*exp.values()).__dict__})
return data

@experience_api.route("/get/<id>", methods = ["GET"])
def get_experience_by_id(id):

@experience_api.route("/get/<id>", methods=["GET"])
def get_experience_by_id(id_):
""" Get experience by ID """
cursor = conn.cursor()
cursor.execute("SELECT * FROM {} where id='{}'".format(table, id))
cursor.execute("SELECT * FROM {} where id='{}'".format(TABLE, id_))
query_result = cursor.fetchone()

if query_result is None:
return "Experience does not exist", 404

return {"data": Experience(*query_result.values()).__dict__}



# TODO: ADD and UPDATE
@experience_api.route("/add/<id>", methods = ["POST"])
def add_experience(id):
@experience_api.route("/add", methods=["POST"])
def add_experience():
""" Add experience """
pass


@experience_api.route("/update/<id>", methods = ["PUT"])
def update_experience(id):
@experience_api.route("/update", methods=["PUT"])
def update_experience():
""" Update experience by ID """
pass

@experience_api.route("/delete/all", methods = ["DELETE"])

@experience_api.route("/delete/all", methods=["DELETE"])
def remove_all_experiences():
""" Remove all experiences """
cursor = conn.cursor()
cursor.execute("DELETE FROM {}".format(table))
cursor.execute("DELETE FROM {}".format(TABLE))
query_result = cursor.fetchall()

if len(query_result) == 0:
return "Deleted", 200

return None

@experience_api.route("/delete/<id>", methods = ["DELETE"])
def remove_experience_by_id(id):

@experience_api.route("/delete/<id>", methods=["DELETE"])
def remove_experience_by_id(id_):
""" Remove experience by ID """
cursor = conn.cursor()
msg = requests.get(URL + "/sauron/backend/exp/get/{}".format(id))
if msg.status_code == 404:
msg = requests.get(
"{}/sauron/backend/exp/get/{}".format(URL, id_), timeout=5)
if msg.status_code == 404:
return msg.text, 404
cursor.execute("DELETE FROM {} where id='{}'".format(table, id))
cursor.execute("DELETE FROM {} where id='{}'".format(TABLE, id_))
query_result = cursor.fetchone()

if query_result is None:
return id, 200

return None
return id_, 200

return None
4 changes: 2 additions & 2 deletions backend/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def test():
"""
Test
"""
t = str(datetime.now())
_t = str(datetime.now())
msg = {
"name": "Sauron-Link-Service",
"health": "Excellent",
"at time": t
"at time": _t
}
result = Response(json.dumps(msg), status=200,
content_type="application/json")
Expand Down
41 changes: 27 additions & 14 deletions backend/model.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
class Experience:
def __init__(self, id, role, company, type, location, logo, start_date, end_date, desc, tech) -> None:
self.id = id
""" Model for Experience """

def __init__(
self, _id, role, company, _type, location, logo, start_date, end_date, desc, tech
) -> None:
self._id = _id
self.role = role
self.company = company
self.type = type
self._type = _type
self.location = location
self.logo = logo
self.start_date = start_date
self.end_date = end_date
self.desc = desc
self.tech = tech
self.tech = tech


class Bio:
def __init__(self, id, bio) -> None:
self.id = id
""" Model for Bio """

def __init__(self, _id, bio) -> None:
self._id = _id
self.bio = bio


class Projects:
def __init__(self, id, title, desc, link) -> None:
self.id = id
""" Model for Projects """

def __init__(self, _id, title, desc, link) -> None:
self._id = _id
self.title = title
self.desc = desc
self.link = link


class Photo:
def __init__(self, id, photo_name, photo_url) -> None:
self.id = id
""" Model for Photo """

def __init__(self, _id, photo_name, photo_url) -> None:
self._id = _id
self.photo_name = photo_name
self.photo_url = photo_url


class Links:
def __init__(self, id, name, link) -> None:
self.id = id
""" Model for Links """

def __init__(self, _id, name, link) -> None:
self._id = _id
self.name = name
self.link = link
self.link = link
Loading

0 comments on commit 9a17c75

Please sign in to comment.