Skip to content

Commit

Permalink
Add projects generic schema
Browse files Browse the repository at this point in the history
  • Loading branch information
LanternNassi committed Jul 22, 2024
1 parent 66acad9 commit ab06371
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
27 changes: 27 additions & 0 deletions api_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,33 @@ paths:
500:
description: "Internal Server Error"

"/search":
get:
tags:
- generic
consumes:
- application/json
parameters:
- in: header
name: Authorization
required: true
type: string
- in: query
name: keywords
type: string
description: Kyewords to search

produces:
- application/json
responses:
200:
description: "Success"
400:
description: "Bad request"
500:
description: "Internal Server Error"


components:
securitySchemes:
bearerAuth:
Expand Down
1 change: 1 addition & 0 deletions app/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
from .project_users import ProjectUsersView, ProjectUsersTransferView, ProjectUsersHandleInviteView, ProjectFollowingView
from .activity_feed import ActivityFeedView
from .tags import TagsView, TagsDetailView, TagFollowingView
from .generic_search import GenericSearchView
23 changes: 23 additions & 0 deletions app/controllers/generic_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from app.models.project import Project
from app.schemas.project import ProjectListSchema
from flask import current_app
from flask_restful import Resource, request
from app.models.project import Project
from flask_jwt_extended import jwt_required
import json


class GenericSearchView(Resource):
@jwt_required
def get(self):
keywords = request.args.get('keywords', '')

#Schemas
projectSchema = ProjectListSchema(many=True)

# projects
projects = Project.query.filter(Project.name.ilike('%'+keywords+'%')).order_by(Project.date_created.desc())

project_data , errors = projectSchema.dumps(projects)

return dict(projects=json.loads(project_data)) , 200
5 changes: 4 additions & 1 deletion app/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
UserAdminUpdateView, AppRevertView, ProjectGetCostsView, TransactionRecordView, CreditTransactionRecordView, CreditPurchaseTransactionRecordView,
BillingInvoiceView, BillingInvoiceNotificationView, SystemSummaryView, CreditDetailView, ProjectUsersView, ProjectUsersTransferView, AppReviseView,
ProjectUsersHandleInviteView, ClusterProjectsView, ProjectDisableView, ProjectEnableView, AppRedeployView, AppDisableView, AppEnableView,
TagsView, TagsDetailView, TagFollowingView,
TagsView, TagsDetailView, TagFollowingView,GenericSearchView,
UserDisableView, UserEnableView, AppDockerWebhookListenerView, UserFollowersView, UserFollowView, ProjectFollowingView, ActivityFeedView)
from app.controllers.app import AppRevisionsView
from app.controllers.billing_invoice import BillingInvoiceDetailView
Expand Down Expand Up @@ -52,6 +52,9 @@
# Deployments
api.add_resource(DeploymentsView, '/deployments', endpoint='deployments')

#Generic search
api.add_resource(GenericSearchView, '/search')

# Clusters
api.add_resource(ClustersView, '/clusters', endpoint='clusters')
api.add_resource(ClusterDetailView, '/clusters/<string:cluster_id>')
Expand Down

0 comments on commit ab06371

Please sign in to comment.