-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
186 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.