Skip to content

Commit 23e81f7

Browse files
Adds REST API endpoints for conversations and messages
Introduces new RESTful routes and OpenAPI specs to manage conversations and their messages, supporting create, list, update, delete, and retrieve operations. Refactors common path parameter logic for improved code reuse. Extends conversation types and schema definitions to enable more flexible conversational features.
1 parent 7eb1972 commit 23e81f7

File tree

6 files changed

+496
-42
lines changed

6 files changed

+496
-42
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
"""Helper script to automatically generate OAS
2+
3+
This OAS are the source of truth
4+
"""
5+
6+
# pylint: disable=redefined-outer-name
7+
# pylint: disable=unused-argument
8+
# pylint: disable=unused-variable
9+
# pylint: disable=too-many-arguments
10+
11+
12+
from typing import Annotated
13+
14+
from fastapi import APIRouter, Depends, status
15+
from models_library.api_schemas_webserver.conversations import (
16+
ConversationMessagePatch,
17+
ConversationMessageRestGet,
18+
ConversationPatch,
19+
ConversationRestGet,
20+
)
21+
from models_library.generics import Envelope
22+
from models_library.rest_pagination import Page
23+
from simcore_service_webserver._meta import API_VTAG
24+
from simcore_service_webserver.conversations._controller._common import (
25+
ConversationPathParams,
26+
)
27+
from simcore_service_webserver.conversations._controller.conversations_messages_rest import (
28+
_ConversationMessageCreateBodyParams,
29+
_ConversationMessagePathParams,
30+
_ListConversationMessageQueryParams,
31+
)
32+
from simcore_service_webserver.conversations._controller.conversations_rest import (
33+
_ConversationsCreateBodyParams,
34+
_GetConversationsQueryParams,
35+
_ListConversationsQueryParams,
36+
)
37+
38+
router = APIRouter(
39+
prefix=f"/{API_VTAG}",
40+
tags=[
41+
"conversations",
42+
],
43+
)
44+
45+
46+
#
47+
# API entrypoints PROJECTS/*/CONVERSATIONS/*
48+
#
49+
50+
51+
@router.post(
52+
"/conversations",
53+
response_model=Envelope[ConversationRestGet],
54+
status_code=status.HTTP_201_CREATED,
55+
)
56+
async def create_conversation(
57+
_body: Annotated[_ConversationsCreateBodyParams, Depends()],
58+
_query: Annotated[_GetConversationsQueryParams, Depends()],
59+
): ...
60+
61+
62+
@router.get(
63+
"/conversations",
64+
response_model=Page[ConversationRestGet],
65+
)
66+
async def list_conversations(
67+
_query: Annotated[_ListConversationsQueryParams, Depends()],
68+
): ...
69+
70+
71+
@router.put(
72+
"/conversations/{conversation_id}",
73+
response_model=Envelope[ConversationRestGet],
74+
)
75+
async def update_conversation(
76+
_params: Annotated[ConversationPathParams, Depends()],
77+
_body: Annotated[ConversationPatch, Depends()],
78+
_query: Annotated[_GetConversationsQueryParams, Depends()],
79+
): ...
80+
81+
82+
@router.delete(
83+
"/conversations/{conversation_id}",
84+
status_code=status.HTTP_204_NO_CONTENT,
85+
)
86+
async def delete_conversation(
87+
_params: Annotated[ConversationPathParams, Depends()],
88+
_query: Annotated[_GetConversationsQueryParams, Depends()],
89+
): ...
90+
91+
92+
@router.get(
93+
"/conversations/{conversation_id}",
94+
response_model=Envelope[ConversationRestGet],
95+
)
96+
async def get_conversation(
97+
_params: Annotated[ConversationPathParams, Depends()],
98+
_query: Annotated[_GetConversationsQueryParams, Depends()],
99+
): ...
100+
101+
102+
### Conversation Messages
103+
104+
105+
@router.post(
106+
"/conversations/{conversation_id}/messages",
107+
response_model=Envelope[ConversationMessageRestGet],
108+
status_code=status.HTTP_201_CREATED,
109+
)
110+
async def create_conversation_message(
111+
_params: Annotated[ConversationPathParams, Depends()],
112+
_body: _ConversationMessageCreateBodyParams,
113+
): ...
114+
115+
116+
@router.get(
117+
"/conversations/{conversation_id}/messages",
118+
response_model=Page[ConversationMessageRestGet],
119+
)
120+
async def list_conversation_messages(
121+
_params: Annotated[ConversationPathParams, Depends()],
122+
_query: Annotated[_ListConversationMessageQueryParams, Depends()],
123+
): ...
124+
125+
126+
@router.put(
127+
"/conversations/{conversation_id}/messages/{message_id}",
128+
response_model=Envelope[ConversationMessageRestGet],
129+
)
130+
async def update_conversation_message(
131+
_params: Annotated[_ConversationMessagePathParams, Depends()],
132+
_body: ConversationMessagePatch,
133+
): ...
134+
135+
136+
@router.delete(
137+
"/conversations/{conversation_id}/messages/{message_id}",
138+
status_code=status.HTTP_204_NO_CONTENT,
139+
)
140+
async def delete_conversation_message(
141+
_params: Annotated[_ConversationMessagePathParams, Depends()],
142+
): ...
143+
144+
145+
@router.get(
146+
"/conversations/{conversation_id}/messages/{message_id}",
147+
response_model=Envelope[ConversationMessageRestGet],
148+
)
149+
async def get_conversation_message(
150+
_params: Annotated[_ConversationMessagePathParams, Depends()],
151+
): ...

api/specs/web-server/openapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# core ---
2222
"_auth",
2323
"_auth_api_keys",
24+
"_conversations",
2425
"_groups",
2526
"_tags",
2627
"_tags_groups", # after _tags

0 commit comments

Comments
 (0)