Skip to content

Commit

Permalink
Merge pull request #890 from johnson-oragui/fix/profile-resource
Browse files Browse the repository at this point in the history
fix: Fixed user profile information retrieval
  • Loading branch information
trevorjob authored Aug 14, 2024
2 parents 07790af + 523b8b4 commit 5abdecd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/core/dependencies/email/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2 style="color: #121a26; font-size: 1.5rem; font-weight: 600;">HNG Boilerplate
<tr>
<td>
<hr style="border: 1px dashed #969696; margin-bottom: 1.5rem;">
<p style="color: #5B5B5D; font-size: 0.875rem; font-weight: 400;">Need help? <a href="{{support_link}}" style="color: #111; font-weight: 600; text-decoration: underline;">Contact our customer support</a></p>
<p style="color: #5B5B5D; font-size: 0.875rem; font-weight: 400;">Need help? <a href="https://anchor-python.teams.hng.tech/help-center" style="color: #111; font-weight: 600; text-decoration: underline;">Contact our customer support</a></p>
<p style="color: #5B5B5D; font-size: 0.875rem; font-weight: 400;">You are receiving this email because you signed up at Boilerplate.com. Want to change how you receive these emails? <a href="{{unsubscribe_link}}" style="color: #111; font-weight: 600; text-decoration: underline;">Update your preferences or unsubscribe from this list.</a></p>
</td>
</tr>
Expand Down
1 change: 0 additions & 1 deletion api/v1/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ def to_dict(self):
"recovery_email": self.recovery_email,
"created_at": self.created_at.isoformat(),
"updated_at": self.updated_at.isoformat(),
"user": self.user.to_dict() if self.user else None,
}
14 changes: 7 additions & 7 deletions api/v1/routes/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@


@profile.get(
"/current-user", status_code=status.HTTP_200_OK, response_model=success_response
"/{user_id}", status_code=status.HTTP_200_OK, response_model=success_response
)
def get_current_user_profile(
db: Session = Depends(get_db),
current_user: User = Depends(user_service.get_current_user),
def get_current_user_profile(user_id: str,
db: Session = Depends(get_db),
current_user: User = Depends(user_service.get_current_user)
):
"""Endpoint to get current user profile details"""

profile = profile_service.fetch_by_user_id(db, user_id=current_user.id)
profile = profile_service.fetch_by_user_id(db, user_id=user_id)

return success_response(
status_code=status.HTTP_201_CREATED,
message="User profile create successfully",
status_code=status.HTTP_200_OK,
message="User profile retrieved successfully",
data=profile.to_dict(),
)

Expand Down
18 changes: 18 additions & 0 deletions api/v1/services/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ def create(self, db: Session, schema: CreateUpdateOrganisation, user: User):
)
db.execute(stmt)
db.commit()
admin_role = db.query(Role).filter_by(name="admin").first()
if not admin_role:
admin_role = Role(
name="admin",
description="Organization Admin",
is_builtin=True
)
db.add(admin_role)
db.commit()
else:
user_role_stmt = user_organisation_roles.insert().values(
user_id=user.id,
organisation_id=new_organisation.id,
role_id=admin_role.id,
is_owner=True,
)
db.execute(user_role_stmt)
db.commit()

return new_organisation

Expand Down
4 changes: 3 additions & 1 deletion api/v1/services/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class RegionService(Service):

def create(self, db: Session, schema: RegionCreate, user_id: str):
'''Create a new Region'''

region_exists = db.query(Region).filter_by(user_id=user_id).first()
if region_exists:
self.update(db, region_exists.id, schema)
new_region = Region(**schema.model_dump(), user_id=user_id)
db.add(new_region)
db.commit()
Expand Down
11 changes: 9 additions & 2 deletions api/v1/services/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from api.utils.settings import settings
from api.utils.db_validators import check_model_existence
from api.v1.models.associations import user_organisation_association
from api.v1.models.user import User
from api.v1.models import User, Profile, Region
from api.v1.models.data_privacy import DataPrivacySetting
from api.v1.models.token_login import TokenLogin
from api.v1.schemas import user
Expand Down Expand Up @@ -153,8 +153,15 @@ def create(self, db: Session, schema: user.UserCreate):

# create data privacy setting
data_privacy = DataPrivacySetting(user_id=user.id)
profile = Profile(
user_id=user.id
)
region = Region(
user_id=user.id,
region='Empty'
)

db.add(data_privacy)
db.add_all([data_privacy, profile, region])
db.commit()
db.refresh(data_privacy)

Expand Down

0 comments on commit 5abdecd

Please sign in to comment.