Skip to content

Commit

Permalink
Adding search functionality to users and apps (#412)
Browse files Browse the repository at this point in the history
* Adding search functionality to users and apps

* resolve app status check (#413)

Co-authored-by: Mutegeki Henry <hmutegeki@Henrys-MacBook-Pro.local>

* Fix codecov support issue(Deprecated) (#415)

* - purge codecov requirement

* - test deploy pipeline

* - test and deploy

* - remove codecov upload

* Adding search functionality to users and apps

---------

Co-authored-by: Henry Mutegeki <36065782+MutegekiHenry@users.noreply.github.com>
Co-authored-by: Mutegeki Henry <hmutegeki@Henrys-MacBook-Pro.local>
Co-authored-by: e-ian <36891299+e-ian@users.noreply.github.com>
Co-authored-by: e-ian <ianemma70@gmail.com>
  • Loading branch information
5 people authored May 25, 2023
1 parent 73aba51 commit 2c62ca4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
8 changes: 8 additions & 0 deletions api_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ paths:
name: Authorization
required: true
description: "Bearer [token]"
- in: query
name: keywords
type: string
description: Enter keywords if searching
- in: query
name: page
type: integer
Expand Down Expand Up @@ -2364,6 +2368,10 @@ paths:
name: project_id
required: true
type: string
- in: query
name: keywords
type: string
description: Enter keywords if searching
- in: query
name: page
type: integer
Expand Down
25 changes: 20 additions & 5 deletions app/controllers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ def get(self, project_id):
current_user_roles = get_jwt_claims()['roles']
page = request.args.get('page', 1, type=int)
per_page = request.args.get('per_page', 10, type=int)
keywords = request.args.get('keywords' , '')
app_schema = AppSchema(many=True)

project = Project.get_by_id(project_id)
Expand All @@ -817,11 +818,25 @@ def get(self, project_id):
kube_token = cluster.token
kube_client = create_kube_clients(kube_host, kube_token)

paginated = App.find_all(
project_id=project_id, paginate=True, page=page, per_page=per_page)
pagination = paginated.pagination
apps = paginated.items
apps_data, errors = app_schema.dumps(apps)
if (keywords == ''):
paginated = App.find_all(
project_id=project_id, paginate=True, page=page, per_page=per_page)
pagination = paginated.pagination
apps = paginated.items
apps_data, errors = app_schema.dumps(apps)

else :
paginated = App.query.filter(App.name.ilike('%'+keywords+'%')).paginate(page=page, per_page=per_page, error_out=False)
pagination = {
'total': paginated.total,
'pages': paginated.pages,
'page': paginated.page,
'per_page': paginated.per_page,
'next': paginated.next_num,
'prev': paginated.prev_num
}
apps = paginated.items
apps_data, errors = app_schema.dumps(apps)

# if errors:
# return dict(status='fail', message=errors), 500
Expand Down
25 changes: 20 additions & 5 deletions app/controllers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,32 @@ def get(self):
user_schema = UserSchema(many=True)
page = request.args.get('page', 1,type=int)
per_page = request.args.get('per_page', 10, type=int)

users = User.find_all(paginate=True, page=page, per_page=per_page)

users_data, errors = user_schema.dumps(users.items)
keywords = request.args.get('keywords' , '')

if (keywords == ''):
paginated = User.find_all(paginate=True, page=page, per_page=per_page)
users = paginated.items
pagination = paginated.pagination
else :
paginated = User.query.filter(User.name.ilike('%'+keywords+'%')).paginate(page=page, per_page=per_page, error_out=False)
users = paginated.items
pagination = {
'total': paginated.total,
'pages': paginated.pages,
'page': paginated.page,
'per_page': paginated.per_page,
'next': paginated.next_num,
'prev': paginated.prev_num
}

users_data, errors = user_schema.dumps(users)

if errors:
return dict(status='fail', message=errors), 400

return dict(
status='success',
data=dict(pagination=users.pagination, users=json.loads(users_data))
data=dict(pagination=pagination, users=json.loads(users_data))
), 200


Expand Down

0 comments on commit 2c62ca4

Please sign in to comment.