Skip to content

Commit

Permalink
Add mostly complete router coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolphpienaar committed Jun 5, 2024
1 parent cbe1bc5 commit b37c5c0
Showing 1 changed file with 182 additions and 11 deletions.
193 changes: 182 additions & 11 deletions pfmdb/routes/pfmdb_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from config import settings
from pftag import pftag
import pudb
from pudb.remote import set_trace

from pfmongo.models.responseModel import mongodbResponse
from models.iresponse import SmashesResponse
Expand All @@ -23,17 +24,17 @@


@router.post(
"/pfmongo/smash/{cmd}",
response_model=iresponse.PfmongoResponse,
"/pfmongo/smashes/{cmd}",
response_model=iresponse.SmashesResponse,
summary="""
POST a command to pfmongo smash.
POST a command to pfmongo smashes.
""",
)
async def pfmongo_cmdExec(
cmd: str,
database: str,
collection: str,
) -> iresponse.PfmongoResponse:
database: str = "",
collection: str = "",
) -> iresponse.SmashesResponse:
"""
Description
-----------
Expand All @@ -42,17 +43,18 @@ async def pfmongo_cmdExec(
Returns
-------
* `iresponse.PfmongoResponse`: The response from `pfmongo`.
* `iresponse.SmashesResponse`: The response from `smashes`.
"""
# pudb.set_trace()
resp: iresponse.PfmongoResponse = iresponse.PfmongoResponse()
resp = await pfmdb_controller.cmd_exec(cmd, database, collection)
resp: iresponse.SmashesResponse = pfmdb_controller.cmd_exec(
cmd, database, collection
)

return resp


@router.get(
"/pfmongo/database",
"/pfmongo",
response_model=SmashesResponse,
summary="""
GET the list of databases in the mongo server
Expand All @@ -76,8 +78,176 @@ async def pfmongo_databaseShowall() -> SmashesResponse:
return resp


@router.delete(
"/pfmongo/{database}",
response_model=SmashesResponse,
summary="""
DELETE the {database}
""",
)
async def pfmongo_databaseDel(database: str) -> SmashesResponse:
"""
Description
-----------
DELETE the {database}
Returns
-------
* `iresponse.SmashesResponse`: the response from `pfmongo`
"""
resp: SmashesResponse = pfmdb_controller.database_del(database)
return resp


@router.get(
"/pfmongo/{database}",
response_model=SmashesResponse,
summary="""
GET the list of collections for the {database}
""",
)
async def pfmongo_collectionShowall(database: str) -> SmashesResponse:
"""
Description
-----------
GET a list of collections for the given {database}.
Returns
-------
* `iresponse.SmashesResponse`: the response from `pfmongo`
"""
resp: SmashesResponse = pfmdb_controller.collection_showall(database)
return resp


@router.delete(
"/pfmongo/{database}/{collection}",
response_model=SmashesResponse,
summary="""
DELETE the {collection} in {database}
""",
)
async def pfmongo_collectionDel(database: str, collection: str) -> SmashesResponse:
"""
Description
-----------
DELETE the {collection} in {database}
Returns
-------
* `iresponse.SmashesResponse`: the response from `pfmongo`
"""
resp: SmashesResponse = pfmdb_controller.collection_del(database, collection)
return resp


@router.get(
"/pfmongo/{database}/{collection}",
response_model=SmashesResponse,
summary="""
GET the list of documents for the {database} {collection}
""",
)
async def pfmongo_documentShowall(database: str, collection: str) -> SmashesResponse:
"""
Description
-----------
GET the list of documents for the {database} {collection}
Returns
-------
* `iresponse.SmashesResponse`: the response from `pfmongo`
"""
resp: SmashesResponse = pfmdb_controller.document_showall(database, collection)
return resp


@router.delete(
"/pfmongo/{database}/{collection}/{document}",
response_model=SmashesResponse,
summary="""
DELETE a {document} in the {database} {collection}
""",
)
async def pfmongo_documentDel(
database: str, collection: str, document: str
) -> SmashesResponse:
"""
Description
-----------
DELEtE a {document} in the {database} {collection}
Returns
-------
* `iresponse.SmashesResponse`: the response from `pfmongo`
"""
resp: SmashesResponse = pfmdb_controller.document_del(
database, collection, document
)
return resp


@router.get(
"/pfmongo/{database}/{collection}/{document}",
response_model=SmashesResponse,
summary="""
GET a {document} in the {database} {collection}
""",
)
async def pfmongo_documentGet(
database: str, collection: str, document: str
) -> SmashesResponse:
"""
Description
-----------
GET a {document} in the {database} {collection}
Returns
-------
* `iresponse.SmashesResponse`: the response from `pfmongo`
"""
resp: SmashesResponse = pfmdb_controller.document_get(
database, collection, document
)
return resp


@router.post(
"/pfmongo/{database}/{collection}/search",
response_model=iresponse.SmashesResponse,
summary="""
POST a search across a collection, returning a list of documents.
""",
)
async def pfmongo_collectionSearch(
database: str, collection: str, term: str = ""
) -> iresponse.SmashesResponse:
"""
Description
-----------
POST a search across a collection, returning a list of documents.
Returns
-------
* `iresponse.SmashesResponse`: The response from `smashes`.
"""
# pudb.set_trace()
resp: iresponse.SmashesResponse = pfmdb_controller.collection_search(
database, collection, term
)

return resp


@router.get(
"/pfmongo/help",
"/help",
response_model=iresponse.PfmongoResponse,
summary="""
GET the overall help response from pfmongo
Expand All @@ -95,5 +265,6 @@ async def pfmongo_help() -> iresponse.PfmongoResponse:
* `iresponse.PfmongoResponse`: the response from `pfmongo`
"""
resp: iresponse.PfmongoResponse = iresponse.PfmongoResponse()
# set_trace(term_size=(254, 60), host="0.0.0.0", port=6900)
resp = await pfmdb_controller.baseHelp_get()
return resp

0 comments on commit b37c5c0

Please sign in to comment.