diff --git a/.gitignore b/.gitignore index 894a44c..ba580ef 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ +.git.exe +.vscode +iReporterAPI2.exe diff --git a/README.md b/README.md index 41a8457..a8fdf16 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # iReporterAPI -Corruption is a huge bane to Africa’s development. African countries must develop novel and localised solutions that will curb this menace, hence the birth of iReporter. iReporter enables any/every citizen to bring any form of corruption to the notice of appropriate authorities and the general public. Users can also report on things that needs government intervention +Corruption is a huge bane to Africa’s development. African countries must develop novel and localised solutions that will curb this menace, hence the birth of iReporter. iReporter enables any/every citizen to bring any form of corruption to the notice of appropriate authorities and the general public. Users can also report on things that needs government intervention. iReporter is an App that is aimed at solving this. diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..238373f --- /dev/null +++ b/api/__init__.py @@ -0,0 +1,3 @@ +from flask import Flask +from api import routes +app = Flask(__name__) \ No newline at end of file diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..159115f --- /dev/null +++ b/api/models.py @@ -0,0 +1,33 @@ +from datetime import datetime + +my_red_flags = [] + + +class Redflag: + + def __init__(self, createdBy, _type, place, status, Images, Videos, comment): + + self._id = len(my_red_flags) + 1 + self.createdOn = datetime.now() + self.createdBy = createdBy + self.type = _type + self.location = place + self.status = status + self.Images = Images + self.Videos = Videos + self.comment = comment + + def format_record(self): + + return { + + "id": self._id, + "createdOn": self.createdOn, + "createdBy": self.createdBy, + "type": self.type, + "location": self.location, + "status": self.status, + "Images": self.Images, + "Videos": self.Videos, + "comment": self.comment + } diff --git a/api/routes.py b/api/routes.py new file mode 100644 index 0000000..9eca579 --- /dev/null +++ b/api/routes.py @@ -0,0 +1,107 @@ +from flask import Flask, jsonify, request +from api.models import Redflag, my_red_flags + + +app = Flask(__name__) + +@app.route("/") +def hello_world(): + return "Hello Kato" + + +#API end point to create a red-flag record +@app.route("/api/v1/red-flags", methods=["POST"]) +def create_redflag(): + if not request.json: + return jsonify({ + "Error": "There is no data returned from the request", + "status": 400 + }), 400 + data = request.get_json() + if 'createdBy' not in data or 'comment' not in data or 'type' not in data or 'location' not in data or 'status' not in data: + return jsonify({'status': 400, 'Error': 'The information is missing'}), 400 + red_flag = Redflag( + data["createdBy"], data["type"], + data["location"], data["status"], data["Images"], + data["Videos"], data["comment"] + ) + my_red_flags.append( + red_flag.format_record() + ) + if len(my_red_flags) == 0: + return jsonify({ + "status": 400, + "Error": "Invalid request" + }) + return jsonify({ + "status": 201, + "data": [{ + "id": red_flag._id, + "Message": "Created red-flag record" + }]}), 200 + + + +#API end point to fetch all records +@app.route("/api/v1/red-flags", methods=["GET"]) +def get_all_red_flags(): + if len(my_red_flags) > 0: + return jsonify({ + "status": 200, + "data": [red_flag for red_flag in my_red_flags] + }) + return jsonify({ + "status": 400, + "Error": "There are no records" + }) + +#API end point to fetch a specific record +@app.route("/api/v1/red-flags/", methods=["GET"]) +def get_a_redflag(flag_id): + red_flag_record= [red_flag for red_flag in my_red_flags if red_flag['id'] == flag_id] + if red_flag_record: + return jsonify({ + "status": 200, + "redflag": red_flag_record + }), 200 + return jsonify({ + "status": 404, + "Error": " Invalid record" + }) + + +# API end point to delete a specific record +@app.route("/api/v1/red-flags/", methods=["DELETE"]) +def delete_red_flag(flag_id): + red_flag_record = [flag for flag in my_red_flags if flag['id'] == flag_id] + if len(my_red_flags) == 0: + return jsonify({ + "status": "400", + "Error": "Invalid request" + }) + my_red_flags.remove(red_flag_record[0]) + return jsonify({ + 'result': True + }), 200 + + + + + + + + + + + + + + + + + + + + + + diff --git a/app.py b/app.py new file mode 100644 index 0000000..2d9ecd3 --- /dev/null +++ b/app.py @@ -0,0 +1,4 @@ +from api.routes import app + +if __name__ == "__main__": + app.run(debug = True) \ No newline at end of file diff --git a/coverage.yml b/coverage.yml new file mode 100644 index 0000000..5ae0821 --- /dev/null +++ b/coverage.yml @@ -0,0 +1 @@ +repo_token: CjaAwOWxXj8kSfulofMGrBmaW7uBGCv58 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6f02fb6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +Click==7.0 +Flask==1.0.2 +itsdangerous==1.1.0 +Jinja2==2.10 +MarkupSafe==1.1.0 +Werkzeug==0.14.1