Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 10 additions & 8 deletions app/api/dao/organization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import ast
from typing import Dict
from http import HTTPStatus
from flask import json
from sqlalchemy import func
Expand All @@ -22,11 +23,12 @@ class OrganizationDAO:
"""Data Access Object for Organization functionalities"""

@staticmethod
def get_organization(representative_id, representative_name):
def get_organization(representative_id: int, representative_name: str):
"""Retrieves the organization that is represented by the user which ID is passed as parameter.

Arguments:
representative_id: The ID of the user who represents the organization.
representative_name: Name of the user who represents the organization.

Returns:
The OrganizationModel class represented by the user whose ID was searched.
Expand All @@ -35,11 +37,11 @@ def get_organization(representative_id, representative_name):
return get_organization(representative_id, representative_name)

@staticmethod
def update_organization(data):
def update_organization(data: Dict):
"""Creates or updates the organization that is represented by the user which ID is passed as parameter.

Arguments:
representative_id: The ID of the user who represents the organization.
data: Dictionary of organization information.

Returns:
A dictionary containing "message" which indicates whether or not
Expand Down Expand Up @@ -91,15 +93,15 @@ def update_organization(data):
return messages.NOT_ORGANIZATION_REPRESENTATIVE, HTTPStatus.FORBIDDEN

@staticmethod
def list_organizations(name, page, per_page, token):
def list_organizations(name: str, page: str, per_page: str, token: str):

"""Retrieves a list of organizations with the specified ID.

Arguments:
user_id: The ID of the user to be listed.
name: The search query for name of the organizations to be found.
page: The page of organizations to be returned
per_page: The number of organizations to return per page
token: Bearer Token

Returns:
A list of organizations matching conditions and the HTTP response code.
Expand Down Expand Up @@ -199,7 +201,7 @@ def list_organizations(name, page, per_page, token):
return e, HTTPStatus.BAD_REQUEST


def update(organization, data, success_message, status_code):
def update(organization: OrganizationModel, data: Dict, success_message: str, status_code: int):
organization.rep_department = data["representative_department"]
organization.about = data["about"]
organization.phone = data["phone"]
Expand All @@ -211,7 +213,7 @@ def update(organization, data, success_message, status_code):
return success_message, status_code


def get_organization(user_id, user_name):
def get_organization(user_id: int, user_name: str):
representative_additional_info = UserExtensionModel.find_by_user_id(user_id)
try:
if representative_additional_info.is_organization_rep:
Expand Down Expand Up @@ -245,4 +247,4 @@ def get_organization(user_id, user_name):

@http_response_namedtuple_converter
def get_named_tuple_result(result):
return result
return result
8 changes: 4 additions & 4 deletions app/api/resources/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class ProgramsList(Resource):
HTTPStatus.INTERNAL_SERVER_ERROR.value, f"{messages.INTERNAL_SERVER_ERROR}"
)
@organizations_ns.expect(auth_header_parser, validate=True)
def get(cls, organization_id):
def get(cls, organization_id: int):
"""
Returns list of all programs where organization ID is passed as parameter.

Expand Down Expand Up @@ -349,7 +349,7 @@ class Program(Resource):
HTTPStatus.OK.value, "Successful request", get_program_response_model
)
@organizations_ns.expect(auth_header_parser, validate=True)
def get(cls, organization_id, program_id):
def get(cls, organization_id: int, program_id: int):
"""
Returns a program which program ID and organization ID are passed as parameters.

Expand Down Expand Up @@ -393,7 +393,7 @@ def get(cls, organization_id, program_id):
@organizations_ns.expect(
auth_header_parser, update_program_request_model, validate=True
)
def put(cls, organization_id, program_id):
def put(cls, organization_id: int, program_id: int):
"""
Updates a program where program ID and organization id are passed as parameters.

Expand Down Expand Up @@ -435,4 +435,4 @@ def put(cls, organization_id, program_id):
return is_not_valid, HTTPStatus.BAD_REQUEST

return ProgramDAO.update_program(organization_id, program_id, data)
return is_wrong_token
return is_wrong_token
8 changes: 5 additions & 3 deletions app/api/validations/organization.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Dict

from app import messages
from app.utils.bitschema_utils import OrganizationStatus, Timezone, Zone, ProgramStatus
from app.utils.validation_utils import is_email_valid, is_phone_valid
from app.database.models.bit_schema.program import ProgramModel


def validate_update_organization(data):
def validate_update_organization(data: Dict):
try:
email = data["email"]
phone = data["phone"]
Expand All @@ -30,7 +32,7 @@ def validate_update_organization(data):
return messages.ORGANIZATION_OR_PROGRAM_STATUS_FIELD_IS_MISSING


def validate_update_program(data):
def validate_update_program(data: Dict):
if "program_name" not in data:
return messages.PROGRAM_NAME_IS_MISSING

Expand All @@ -56,4 +58,4 @@ def validate_update_program(data):
except ValueError:
return messages.PROGRAM_STATUS_INPUT_IS_INVALID
except KeyError:
return messages.ORGANIZATION_OR_PROGRAM_STATUS_FIELD_IS_MISSING
return messages.ORGANIZATION_OR_PROGRAM_STATUS_FIELD_IS_MISSING