Skip to content

Commit

Permalink
chg: [API] Added a new argument in order to let the user filter comme…
Browse files Browse the repository at this point in the history
…nts based on data in the meta JSON field.
  • Loading branch information
cedricbonhomme committed Aug 28, 2024
1 parent 0a95838 commit 00be25c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions website/web/api/v1/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
type=str,
help="Author of the comment.",
)
parser.add_argument(
"meta",
type=str,
help="Query for the meta JSON field.",
)

# Response marshalling
comment_params_model = {
Expand Down Expand Up @@ -143,6 +148,7 @@ def get(self) -> Tuple[ResultType, int]:
uuid = args.pop("uuid", None)
author = args.pop("author", None)
vuln_id = args.pop("vuln_id", None)
meta_query = args.pop("meta", None)

result: ResultType = {
"data": [],
Expand All @@ -163,6 +169,9 @@ def get(self) -> Tuple[ResultType, int]:
query = query.filter(Comment.author.has(login=author))
if vuln_id is not None:
query = query.filter(Comment.vulnerability.ilike("%" + vuln_id + "%"))
if meta_query is not None:
# example of value for meta_query: [{"tags": ["PoC"]}]
query = query.filter(Comment.meta.contains(meta_query))

query = query.order_by(Comment.timestamp.desc())
total = query.count()
Expand Down

0 comments on commit 00be25c

Please sign in to comment.