diff --git a/core/api/people_finder.py b/core/api/people_finder.py index e0d1f9b1..999817e5 100644 --- a/core/api/people_finder.py +++ b/core/api/people_finder.py @@ -93,17 +93,17 @@ def update_profile( @router.get( - "ukstafflocations/", + "uk_staff_locations/", response={ 200: list[UkStaffLocationSchema], 404: Error, }, ) -def get_uk_staff_location(request) -> tuple[int, list[dict] | dict]: +def get_uk_staff_locations(request) -> tuple[int, list[dict] | dict]: try: - locations = [location for location in UkStaffLocation.objects.all()] - if len(locations) > 0: - return 200, locations + uk_staff_locations = core_services.get_uk_staff_locations() + if len(uk_staff_locations) > 0: + return 200, uk_staff_locations else: return 404, {"message": "No UK staff locations to display"} except Exception as unknown_error: diff --git a/core/services.py b/core/services.py index dc52f2ae..f4926f29 100644 --- a/core/services.py +++ b/core/services.py @@ -275,3 +275,7 @@ def delete_identity(profile: Profile) -> None: if not all_remaining_profiles: user = user_services.get_by_id(sso_email_id=profile_id, include_inactive=True) user_services.delete_from_database(user=user) + + +def get_uk_staff_locations() -> list[dict]: + return profile_services.get_uk_staff_locations() diff --git a/profiles/services/__init__.py b/profiles/services/__init__.py index e988c52b..6638c4d0 100644 --- a/profiles/services/__init__.py +++ b/profiles/services/__init__.py @@ -10,7 +10,6 @@ from profiles.exceptions import NonCombinedProfileExists from profiles.models.combined import Profile -from profiles.models.generic import Country, UkStaffLocation from profiles.models.peoplefinder import PeopleFinderProfile from profiles.models.staff_sso import StaffSSOProfile from profiles.services import combined, peoplefinder, staff_sso @@ -392,3 +391,7 @@ def delete(profile_id: str) -> dict[str, models.Model]: del all_profiles["combined"] return all_profiles + + +def get_uk_staff_locations() -> list[dict]: + return peoplefinder.get_uk_staff_locations() diff --git a/profiles/services/peoplefinder.py b/profiles/services/peoplefinder.py index 46ee3705..8fddd1dd 100644 --- a/profiles/services/peoplefinder.py +++ b/profiles/services/peoplefinder.py @@ -421,3 +421,8 @@ def delete_from_database( ) peoplefinder_profile.delete() + + +def get_uk_staff_locations() -> list[dict]: + locations = [location for location in UkStaffLocation.objects.all()] + return locations diff --git a/profiles/tests/test_services_peoplefinder.py b/profiles/tests/test_services_peoplefinder.py index a3c3abad..aede5900 100644 --- a/profiles/tests/test_services_peoplefinder.py +++ b/profiles/tests/test_services_peoplefinder.py @@ -111,3 +111,14 @@ def test_get_by_id(peoplefinder_profile): with pytest.raises(PeopleFinderProfile.DoesNotExist) as ex: peoplefinder_services.get_by_slug(slug="550e8400-e29b-41d4-a716-446655440000") assert str(ex.value.args[0]) == "PeopleFinderProfile matching query does not exist." + + +def test_get_uk_staff_locations(): + locations = peoplefinder_services.get_uk_staff_locations() + # Check if code, name, organisation and building_name exists in the location dict + assert { + "code": "location_1", + "name": "OAB_UK", + "organisation": "DBT", + "building_name": "OAB", + }.items() <= locations[0].__dict__.items()