Skip to content

Commit

Permalink
chore: add data to already existing endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
khalifan-kfan committed Jul 4, 2024
1 parent 6f6ceee commit bee0c87
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 78 deletions.
31 changes: 1 addition & 30 deletions api_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -724,33 +724,6 @@ paths:
500:
description: "Internal Server Error"

"/users/profile_summary/{user_id}":
get:
tags:
- users
consumes:
- application/json
produces:
- application/json
parameters:
- in: header
name: Authorization
required: true
description: "Bearer [token]"
- in: path
name: user_id
required: true
type: string
responses:
200:
description: "Success"
404:
description: "User not found"
400:
description: "Bad request"
500:
description: "Internal Server Error"

"/activity_feed":
get:
tags:
Expand Down Expand Up @@ -3722,7 +3695,6 @@ paths:
500:
description: "Internal Server Error"


"/projects/tags":
post:
tags:
Expand All @@ -3743,7 +3715,7 @@ paths:
- name
items:
type: string

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


components:
securitySchemes:
bearerAuth:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .users import (
UsersView, UserLoginView, UserEmailVerificationView, UserFollowersView, UserFollowView,
EmailVerificationRequest, ForgotPasswordView, ResetPasswordView, UserDisableView, UserEnableView,
UserDetailView, AdminLoginView, OAuthView, UserDataSummaryView, UserAdminUpdateView, InActiveUsersView, UserProfileSummaryView)
UserDetailView, AdminLoginView, OAuthView, UserDataSummaryView, UserAdminUpdateView, InActiveUsersView)
from .deployments import DeploymentsView
from .clusters import (
ClustersView, ClusterDetailView, ClusterNamespacesView,
Expand Down
56 changes: 12 additions & 44 deletions app/controllers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,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 Expand Up @@ -1266,47 +1278,3 @@ def get(self, user_id):
status='success',
data=dict(followers=json.loads(users_data))
), 200


class UserProfileSummaryView(Resource):

@ jwt_required
def get(self, user_id):
"""
Returns metrics about a user's following information and their resource counts.
"""
try:
user = User.get_by_id(user_id)

if not user:
return dict(status='fail', message='User not found'), 404

print('hdf')

project_app_counts = Counter(len(project.apps)
for project in user.projects)
# 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 = {
'projects_count': len(user.projects),
'following_count': user.followed.count(),
'follower_count': user.followers.count(),
'followed_projects_count': len(user.followed_projects),
'projects_followers_count': count_of_projects_followers,
'apps_count': project_app_counts.total()
}
print(user_data)

return dict(
status='success',
data=user_data
), 200

except Exception as e:
return dict(status='fail', message=str(e)), 500
4 changes: 1 addition & 3 deletions app/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
BillingInvoiceView, BillingInvoiceNotificationView, SystemSummaryView, CreditDetailView, ProjectUsersView, ProjectUsersTransferView, AppReviseView,
ProjectUsersHandleInviteView, ClusterProjectsView, ProjectDisableView, ProjectEnableView, AppRedeployView, AppDisableView, AppEnableView,
ProjectTagsView, ProjectTagsDetailView,
UserDisableView, UserEnableView, AppDockerWebhookListenerView, UserFollowersView, UserFollowView, ProjectFollowingView, ActivityFeedView, UserProfileSummaryView)
UserDisableView, UserEnableView, AppDockerWebhookListenerView, UserFollowersView, UserFollowView, ProjectFollowingView, ActivityFeedView)
from app.controllers.app import AppRevisionsView
from app.controllers.billing_invoice import BillingInvoiceDetailView
from app.controllers.receipts import BillingReceiptsDetailView, BillingReceiptsView
Expand Down Expand Up @@ -46,8 +46,6 @@

api.add_resource(UserFollowView, '/users/<string:user_id>/following')
api.add_resource(UserFollowersView, '/users/<string:user_id>/followers')
api.add_resource(UserProfileSummaryView,
'/users/profile_summary/<string:user_id>')

# Activity Feed
api.add_resource(ActivityFeedView, '/activity_feed')
Expand Down

0 comments on commit bee0c87

Please sign in to comment.