brestok commited on
Commit
944f2bb
·
1 Parent(s): e1c845b

Add reports API module with models and DTOs

Browse files

- Created a new reports API module with routing and views.
- Introduced data transfer objects (DTOs) for report structures, including `Stack`, `Roadmap`, and associated enums.
- Defined `ReportModel` for MongoDB integration, encapsulating report details.
- Implemented a POST endpoint for filtering reports based on specified criteria.

cbh/__init__.py CHANGED
@@ -21,29 +21,33 @@ def create_app() -> FastAPI:
21
 
22
  app.include_router(account_router, tags=["account"])
23
 
24
- from cbh.api.calls import calls_router
25
 
26
- app.include_router(calls_router, tags=["calls"])
27
 
28
- from cbh.api.reports import reports_router
29
 
30
- app.include_router(reports_router, tags=["reports"])
31
 
32
- from cbh.api.reps import reps_router
33
 
34
- app.include_router(reps_router, tags=["reps"])
35
 
36
- from cbh.api.security import security_router
37
 
38
- app.include_router(security_router, tags=["security"])
 
 
39
 
40
- from cbh.api.userinsights import userinsights_router
41
 
42
- app.include_router(userinsights_router, tags=["userinsights"])
 
 
43
 
44
  app.add_middleware(
45
  CORSMiddleware,
46
- allow_origin_regex=r"https?://([a-z0-9-]+\.)?(localhost|trainwitharena|cbhexp\.com)(:\d+)?",
47
  allow_credentials=True,
48
  allow_methods=["*"],
49
  allow_headers=["*"],
@@ -63,9 +67,7 @@ def create_app() -> FastAPI:
63
  """
64
  Execute startup tasks when the application starts.
65
  """
66
- from cbh.api.calls.services import run_call_listener
67
- #
68
- asyncio.create_task(run_call_listener())
69
 
70
  @app.get("/api/health")
71
  async def health():
 
21
 
22
  app.include_router(account_router, tags=["account"])
23
 
24
+ from cbh.api.ari import ari_router
25
 
26
+ app.include_router(ari_router, tags=["ari"])
27
 
28
+ from cbh.api.chats import chats_router
29
 
30
+ app.include_router(chats_router, tags=["chats"])
31
 
32
+ from cbh.api.messages import messages_router
33
 
34
+ app.include_router(messages_router, tags=["messages"])
35
 
36
+ from cbh.api.platforms import platforms_router
37
 
38
+ app.include_router(platforms_router, tags=["platforms"])
39
+
40
+ from cbh.api.reports import reports_router
41
 
42
+ app.include_router(reports_router, tags=["reports"])
43
 
44
+ from cbh.api.security import security_router
45
+
46
+ app.include_router(security_router, tags=["security"])
47
 
48
  app.add_middleware(
49
  CORSMiddleware,
50
+ allow_origin_regex=r"https?://([a-z0-9-]+\.)?(huggingface\.co|localhost|trainwitharena|cbhexp\.com)(:\d+)?",
51
  allow_credentials=True,
52
  allow_methods=["*"],
53
  allow_headers=["*"],
 
67
  """
68
  Execute startup tasks when the application starts.
69
  """
70
+ pass
 
 
71
 
72
  @app.get("/api/health")
73
  async def health():
cbh/api/platforms/db_requests.py CHANGED
@@ -6,7 +6,7 @@ from cbh.api.common.db_requests import get_all_objs
6
 
7
  async def filter_platforms_objs(
8
  request: FilterRequest[PlatformFilter],
9
- ) -> list[PlatformModel]:
10
  """
11
  Filter platforms objects.
12
  """
 
6
 
7
  async def filter_platforms_objs(
8
  request: FilterRequest[PlatformFilter],
9
+ ) -> tuple[list[PlatformModel], int]:
10
  """
11
  Filter platforms objects.
12
  """
cbh/api/platforms/models.py CHANGED
@@ -1,7 +1,7 @@
1
  from pydantic import Field
2
 
3
  from cbh.api.platforms.dto import Focus, ToolType, Level, Category, MonetizationPriority
4
- from cbh.core.database import MongoBaseModel
5
 
6
 
7
  class PlatformModel(MongoBaseModel):
@@ -48,3 +48,10 @@ class PlatformModel(MongoBaseModel):
48
  internalNotes: str = Field(
49
  description="Internal notes about when/how to recommend this tool"
50
  )
 
 
 
 
 
 
 
 
1
  from pydantic import Field
2
 
3
  from cbh.api.platforms.dto import Focus, ToolType, Level, Category, MonetizationPriority
4
+ from cbh.core.database import MongoBaseModel, MongoBaseShortenModel
5
 
6
 
7
  class PlatformModel(MongoBaseModel):
 
48
  internalNotes: str = Field(
49
  description="Internal notes about when/how to recommend this tool"
50
  )
51
+
52
+
53
+ class PlatformShorten(MongoBaseShortenModel):
54
+ name: str
55
+ description: str
56
+ price: str
57
+ website: str
cbh/api/reports/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from fastapi import APIRouter
2
+
3
+ reports_router = APIRouter(prefix="/reports", tags=["reports"])
4
+
5
+ from . import views
cbh/api/reports/dto.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from enum import Enum
2
+
3
+ from pydantic import BaseModel
4
+
5
+ from cbh.api.platforms.models import PlatformShorten
6
+
7
+
8
+ class StackType(Enum):
9
+ RECOMMENDED = 1
10
+ FASTEST = 2
11
+ CHEAPEST = 3
12
+
13
+
14
+ class ToolType(Enum):
15
+ RECOMMENDED = 1
16
+ ALTERNATIVE = 2
17
+
18
+
19
+ class ToolScore(Enum):
20
+ GREAT = 1
21
+ GOOD = 2
22
+ AVERAGE = 3
23
+ POOR = 4
24
+
25
+
26
+ class StackTool(BaseModel):
27
+ type: ToolType
28
+ platform: PlatformShorten
29
+ score: ToolScore
30
+
31
+
32
+ class Stack(BaseModel):
33
+ type: StackType
34
+ tools: list[StackTool]
35
+
36
+
37
+ class Roadmap(BaseModel):
38
+ duration: str
39
+ phaseName: str
40
+ description: str
41
+
cbh/api/reports/models.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from cbh.api.reports.dto import Roadmap, Stack
2
+ from cbh.core.database import MongoBaseModel
3
+
4
+
5
+ class ReportModel(MongoBaseModel):
6
+ name: str
7
+ review: str
8
+ stack: list[Stack]
9
+ roadmap: list[Roadmap]
10
+ deepAnalysis: str
11
+ monetization: str
12
+ risks: str
13
+ marketingPlan: str
14
+ nextSteps: str
cbh/api/reports/schemas.py ADDED
File without changes
cbh/api/reports/views.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import Depends
2
+ from cbh.api.account.models import AccountModel
3
+ from cbh.api.reports import reports_router
4
+ from cbh.api.reports.models import ReportModel
5
+ from cbh.api.common.schemas import AllObjectsResponse, Paging
6
+ from cbh.api.common.schemas import FilterRequest
7
+ from cbh.core.security import PermissionDependency
8
+ from cbh.core.wrappers import CbhResponseWrapper
9
+
10
+
11
+ @reports_router.post("/filter")
12
+ async def get_reports(
13
+ request: FilterRequest[ReportFilter],
14
+ _: AccountModel = Depends(PermissionDependency()),
15
+ ) -> CbhResponseWrapper[AllObjectsResponse[ReportModel]]:
16
+ reports, total_count = await filter_reports_objs(request)
17
+ return CbhResponseWrapper(
18
+ data=AllObjectsResponse(
19
+ data=reports,
20
+ paging=Paging(
21
+ pageSize=request.pageSize,
22
+ pageIndex=request.pageIndex,
23
+ totalCount=total_count,
24
+ ),
25
+ )
26
+ )