Skip to content

Commit

Permalink
Feat: enable user see a summary of user data (#512)
Browse files Browse the repository at this point in the history
* Feat: enable user see a summary of user data

* chore: add data to already existing endpoint

---------

Co-authored-by: Mubangizi Allan <mubangizia22@gmail.com>
  • Loading branch information
khalifan-kfan and Mubangizi committed Jul 4, 2024
1 parent 5635807 commit af4deec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions api_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3716,7 +3716,7 @@ paths:
- name
items:
type: string

produces:
- application/json
responses:
Expand Down Expand Up @@ -3752,7 +3752,6 @@ paths:
500:
description: "Internal Server Error"


components:
securitySchemes:
bearerAuth:
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from flask_bcrypt import Bcrypt
from app.schemas import UserSchema, UserGraphSchema, ActivityLogSchema
from app.models.user import User
from app.models.project_users import ProjectFollowers
from app.models.role import Role
from app.helpers.confirmation import send_verification
from app.helpers.email import send_email
Expand All @@ -31,6 +32,7 @@
from bson.json_util import dumps
from app.models.app import App
from app.helpers.crane_app_logger import logger
from collections import Counter


class UsersView(Resource):
Expand Down Expand Up @@ -376,10 +378,22 @@ def get(self, user_id):

user_data, errors = user_schema.dumps(user)

# A count of the project records that they own in the ProjectFollowers' table is the count of users that follow their projects
count_of_projects_followers = (
db.session.query(func.count(ProjectFollowers.user_id))
.join(Project, ProjectFollowers.project_id == Project.id)
.filter(Project.owner_id == user_id)
.scalar()
)

user_data = json.loads(user_data)

user_data['projects_count'] = len(user.projects)
user_data['following_count'] = user.followed.count()
user_data['follower_count'] = user.followers.count()
user_data['followed_projects_count'] = len(user.followed_projects)
user_data['projects_followers_count'] = count_of_projects_followers

# Identify if the person making the details request follows the user or not
user_data['requesting_user_follows'] = user.is_followed_by(
current_user)
Expand Down

0 comments on commit af4deec

Please sign in to comment.