Skip to content

Commit

Permalink
country endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
oyeniyipa committed Feb 24, 2025
1 parent a29d9aa commit f493562
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
30 changes: 28 additions & 2 deletions core/api/people_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

from core import services as core_services
from core.schemas import Error
from core.schemas.peoplefinder import MinimalPeopleFinderProfile
from core.schemas.peoplefinder import CountrySchema, MinimalPeopleFinderProfile
from core.schemas.profiles import (
PeopleFinderProfileRequestSchema,
PeopleFinderProfileResponseSchema,
)
from profiles.models.combined import Profile
from profiles.models.generic import Country
from profiles.models.peoplefinder import PeopleFinderProfile


router = Router()
profile_router = Router()
country_router = Router()
router.add_router("person", profile_router)
router.add_router("country", country_router)


@profile_router.get(
Expand Down Expand Up @@ -82,8 +85,31 @@ def update_profile(
intermediate_languages=profile_request.intermediate_languages,
previous_experience=profile_request.previous_experience,
)
return 200, core_services.get_profile_by_slug(slug=slug)
return 200, core_services.get_peoplefinder_profile_by_slug(slug=slug)
except Profile.DoesNotExist:
return 404, {"message": "Profile does not exist"}
except PeopleFinderProfile.DoesNotExist:
return 404, {"message": "People finder profile does not exist"}


@country_router.get(
"{slug}",
response={
200: CountrySchema,
404: Error,
},
)
def get_country(request, slug: str) -> tuple[int, Country | dict]:
try:
# Use get by slug from core
profile = core_services.get_peoplefinder_profile_by_slug(slug=slug)
country = profile.country.__dict__
return 200, country
except PeopleFinderProfile.DoesNotExist:
return 404, {
"message": "People finder profile does not exist",
}
except AttributeError:
return 404, {
"message": "Country is not set for the people finder profile",
}
19 changes: 18 additions & 1 deletion core/schemas/peoplefinder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from dataclasses import dataclass
from typing import Optional

from ninja import Schema
from ninja import ModelSchema, Schema

from profiles.models import PeopleFinderProfile
from profiles.models.generic import Country


@dataclass
Expand Down Expand Up @@ -47,3 +48,19 @@ def resolve_email(obj: PeopleFinderProfile):
@staticmethod
def resolve_contact_email(obj: PeopleFinderProfile):
return obj.contact_email.address


class CountrySchema(ModelSchema):
class Meta:
model = Country
fields = [
"reference_id",
"name",
"type",
"iso_1_code",
"iso_2_code",
"iso_3_code",
"overseas_region",
"start_date",
"end_date",
]
9 changes: 0 additions & 9 deletions core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ def get_identity_by_id(id: str, include_inactive: bool = False) -> Profile:
)


def get_profile_by_slug(
slug: str, include_inactive: bool = False
) -> PeopleFinderProfile:
"""
Retrieve a peoplefinder profile by its slug.
"""
return profile_services.get_by_slug(slug=slug, include_inactive=include_inactive)


def create_peoplefinder_profile(
slug: str,
sso_email_id: str,
Expand Down

0 comments on commit f493562

Please sign in to comment.