Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fishchimp/features/fetch unavailability testing #179

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ bcrypt = "==4.1.2"
boto3 = "==1.17.112"
botocore = "==1.20.112"
certifi = "==2024.2.2"
cffi = "==1.15.1"
cffi = "==1.16.0"
click = ">=7.1.2"
distlib = "==0.3.8"
filelock = "==3.13.1"
flask-cors = "==4.0.0"
flask-restful = "==0.3.10"
flask = "==3.0.2"
greenlet = "==3.0.1"
greenlet = "==3.0.3"
ics = "==0.7.2"
itsdangerous = ">=1.1.0"
jinja2 = ">=2.11.3"
jmespath = "==0.10.0"
mako = "==1.2.4"
mako = "==1.3.2"
markupsafe = ">=1.1.1"
minizinc = "==0.9.0"
mysqlclient = "==2.2.4"
pipenv = "*"
pycparser = "==2.21"
pyjwt = "==2.8.0"
python-dateutil = "==2.9.0.post0"
python-dotenv = "==1.0.0"
python-dotenv = "==1.0.1"
python-editor = "==1.0.4"
python-http-client = "==3.3.7"
pytz = "==2024.1"
Expand Down
256 changes: 123 additions & 133 deletions Pipfile.lock

Large diffs are not rendered by default.

89 changes: 43 additions & 46 deletions application.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
from flask import Flask
from flask_cors import CORS

from controllers import *

# Register the application

application = app = Flask(__name__)

# TODO: Tech Debt
# - CORS Should be specified at the host level per environment, not a global free-for-all. We do this to stop
# cross site scripting (XSS) attacks.
CORS(app)

# Register all controllers individually
app.register_blueprint(existing_requests_bp)
app.register_blueprint(new_request_bp)
app.register_blueprint(recommendation_bp)
app.register_blueprint(shift_request_bp)
app.register_blueprint(vehicle_request_bp)
app.register_blueprint(volunteer_bp)
app.register_blueprint(volunteer_all_bp)
app.register_blueprint(volunteer_availability_bp)
app.register_blueprint(volunteer_preferred_hours_bp)
app.register_blueprint(volunteer_shifts_bp)
app.register_blueprint(volunteer_status_bp)
app.register_blueprint(authentication_bp)
app.register_blueprint(reference_bp)
app.register_blueprint(user_role_bp)
app.register_blueprint(asset_type_role_bp)
app.register_blueprint(user_type_bp)
app.register_blueprint(tenancy_config_bp)
app.register_blueprint(tutorial_quiz_bp)
app.register_blueprint(email_bp)
app.register_blueprint(profile_bp)
app.register_blueprint(v2_bp)
app.register_blueprint(volunteer_unavailability_bp)
app.register_blueprint(user_bp)
app.register_blueprint(chatbot_bp)
app.register_blueprint(diet_requirement_retrieval_bp)


@app.route('/')
def main():
return {
'status': 'OK',
}

def create_app():
# Create the Flask application
app = Flask(__name__)

# Apply CORS settings to the application
CORS(app)

# Register all controllers individually
app.register_blueprint(existing_requests_bp)
app.register_blueprint(new_request_bp)
app.register_blueprint(recommendation_bp)
app.register_blueprint(shift_request_bp)
app.register_blueprint(vehicle_request_bp)
app.register_blueprint(volunteer_bp)
app.register_blueprint(volunteer_all_bp)
app.register_blueprint(volunteer_availability_bp)
app.register_blueprint(volunteer_preferred_hours_bp)
app.register_blueprint(volunteer_shifts_bp)
app.register_blueprint(volunteer_status_bp)
app.register_blueprint(authentication_bp)
app.register_blueprint(reference_bp)
app.register_blueprint(user_role_bp)
app.register_blueprint(asset_type_role_bp)
app.register_blueprint(user_type_bp)
app.register_blueprint(tenancy_config_bp)
app.register_blueprint(tutorial_quiz_bp)
app.register_blueprint(email_bp)
app.register_blueprint(profile_bp)
app.register_blueprint(v2_bp)
app.register_blueprint(volunteer_unavailability_bp)
app.register_blueprint(user_bp)
app.register_blueprint(chatbot_bp)
app.register_blueprint(diet_requirement_retrieval_bp)

# Define the main route
@app.route('/')
def main():
return {
'status': 'OK',
}

return app

if __name__ == '__main__':
import logging

logging.basicConfig(filename='error.log', level=logging.DEBUG)
app = create_app() # Create an app by calling the factory method
app.run(host='0.0.0.0')


26 changes: 25 additions & 1 deletion controllers/v2/unavailability/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import json
import uuid

from flask import jsonify
from flask_restful import reqparse, Resource, marshal_with, inputs

from domain.entity import unavailability_time
from .response_models import volunteer_unavailability_time
from domain import session_scope, UserType
from repository.volunteer_unavailability_v2 import *
from repository.unavailability_repository import *
from services.jwk import requires_auth, is_user_or_has_role
from controllers.v2.v2_blueprint import v2_api

Expand Down Expand Up @@ -43,7 +48,7 @@ def delete(self, user_id, event_id):
return {"message": "Unavailability event not found."}, 404
except Exception as e:
# HTTP 500 Internal Server Error
return {"description": "Internal server error", "error": str(e)}, 500
return {"message": "Internal server error", "error": str(e)}, 500


class VolunteerUnavailabilityV2(Resource):
Expand All @@ -64,7 +69,26 @@ def get(self, user_id):
def post(self, user_id):
try:
args = edit_parser.parse_args()
# Check if start time is earlier than end time.
if args['start'] >= args['end']:
return {"message": "Start time must be earlier than end time"}, 400 # HTTP 400 Bad Request

with session_scope() as session:
# checks if new time frame overlaps with any existing in the database for specific userId
overlapping_events = session.query(UnavailabilityTime).filter(
UnavailabilityTime.userId == user_id,
UnavailabilityTime.start < args['end'],
UnavailabilityTime.end > args['start'],
UnavailabilityTime.periodicity == args['periodicity']
).all()
if overlapping_events:
overlapping_details = []
for event in overlapping_events:
overlapping_details.append({
"eventId": event.eventId})
return {"message": "Time frames overlap with existing events",
"overlapping_events": overlapping_details}, 400 # HTTP 400 Bad Request

eventId = create_event(
session,
user_id,
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ blinker==1.7.0; python_version >= '3.8'
boto3==1.17.112; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
botocore==1.20.112; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
certifi==2024.2.2; python_version >= '3.6'
cffi==1.15.1
cffi==1.16.0; python_version >= '3.8'
click==8.1.7; python_version >= '3.7'
distlib==0.3.8
exceptiongroup==1.2.0; python_version < '3.11'
filelock==3.13.1; python_version >= '3.8'
flask==3.0.2; python_version >= '3.8'
flask-cors==4.0.0
flask-restful==0.3.10
greenlet==3.0.1; python_version >= '3.7'
greenlet==3.0.3; python_version >= '3.7'
ics==0.7.2
importlib-metadata==7.0.1; python_version < '3.9'
importlib-resources==6.1.1; python_version < '3.9'
iniconfig==2.0.0; python_version >= '3.7'
itsdangerous==2.1.2; python_version >= '3.7'
jinja2==3.1.3; python_version >= '3.7'
jmespath==0.10.0; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
mako==1.2.4; python_version >= '3.7'
mako==1.3.2; python_version >= '3.8'
markupsafe==2.1.5; python_version >= '3.7'
minizinc==0.9.0; python_version >= '3.7' and python_version < '4.0'
mysqlclient==2.2.4; python_version >= '3.8'
Expand All @@ -36,9 +36,9 @@ platformdirs==4.2.0; python_version >= '3.8'
pluggy==1.4.0; python_version >= '3.8'
pycparser==2.21; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
pyjwt==2.8.0; python_version >= '3.7'
pytest==8.0.2; python_version >= '3.8'
pytest==8.0.1; python_version >= '3.8'
python-dateutil==2.9.0.post0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
python-dotenv==1.0.0; python_version >= '3.8'
python-dotenv==1.0.1; python_version >= '3.8'
python-editor==1.0.4
python-http-client==3.3.7; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
pytz==2024.1
Expand Down
27 changes: 0 additions & 27 deletions services/optimiser/input_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,30 +348,3 @@ def get_position_qualification(session, position_id):
qualification_id = qualification[0]
return qualification_id


# This can be called by api from postman, to test easily
def test_vehicle_list(session, request_id):
v_l = get_vehicle_list(session, request_id)
for v in v_l:
get_position_list(session, v)

# print("get_postion_role", get_position_role(session,720))
# print("get_APR_matrix", get_input_rolerequirements(session,361))
# get_position_qualification(session,756)
# print("get_APQ_matrix",get_input_qualrequirements(session,361))
# print("get_position_list_all",get_position_list_all(session,360))
# print("get_position_vehicle",get_position_vehicle(session,863))
# print("get_posrequirements_matrix",get_input_posrequirements(session,360))
# get_input_qualability(session)
# print(get_qualification_list(session))
# print(get_input_qualability(session))
# get_role_list(session)
# print(get_input_roleability(session))
# print(get_vehicle_time(session,369))
# print(get_input_availability(session,360))
# print(time_unavailability_list(session,31))
# print(get_input_availability(session,360))
# print(get_input_clashes(session,323))


return 1
64 changes: 0 additions & 64 deletions services/optimiser/testing/test_shift.py

This file was deleted.

61 changes: 0 additions & 61 deletions services/optimiser/testing_for_scheduler.py

This file was deleted.

File renamed without changes.
Loading