Skip to content

Commit 2b501ab

Browse files
review @pcrespov
1 parent 3aea0c9 commit 2b501ab

File tree

9 files changed

+71
-94
lines changed

9 files changed

+71
-94
lines changed

api/specs/web-server/_projects_comments.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import Literal
1212

1313
from _common import assert_handler_signature_against_model
14-
from fastapi import APIRouter
14+
from fastapi import APIRouter, status
1515
from models_library.generics import Envelope
1616
from models_library.projects import ProjectID
1717
from models_library.projects_comments import CommentID, ProjectsCommentsAPI
@@ -41,7 +41,7 @@
4141
"/projects/{project_uuid}/comments",
4242
response_model=Envelope[dict[Literal["comment_id"], CommentID]],
4343
description="Create a new comment for a specific project. The request body should contain the comment contents and user information.",
44-
status_code=201,
44+
status_code=status.HTTP_201_CREATED,
4545
deprecated=True,
4646
)
4747
async def create_project_comment(
@@ -91,7 +91,7 @@ async def update_project_comment(
9191
@router.delete(
9292
"/projects/{project_uuid}/comments/{comment_id}",
9393
description="Delete a specific comment associated with a project.",
94-
status_code=204,
94+
status_code=status.HTTP_204_NO_CONTENT,
9595
deprecated=True,
9696
)
9797
async def delete_project_comment(project_uuid: ProjectID, comment_id: CommentID): ...

api/specs/web-server/_projects_conversations.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,34 @@
99
# pylint: disable=too-many-arguments
1010

1111

12-
from _common import assert_handler_signature_against_model
13-
from fastapi import APIRouter
12+
from typing import Annotated
13+
14+
from fastapi import APIRouter, Depends, status
1415
from models_library.api_schemas_webserver.projects_conversations import (
1516
ConversationMessageRestGet,
1617
ConversationRestGet,
1718
)
18-
from models_library.conversations import ConversationID, ConversationMessageID
1919
from models_library.generics import Envelope
20-
from models_library.projects import ProjectID
2120
from models_library.rest_pagination import Page
22-
from pydantic import NonNegativeInt
2321
from simcore_service_webserver._meta import API_VTAG
22+
from simcore_service_webserver.projects._controller._rest_schemas import (
23+
ProjectPathParams,
24+
)
25+
26+
# from simcore_service_webserver.projects._controller.conversations_rest import (
27+
# _ProjectConversationsPathParams,
28+
# _ListProjectConversationMessagesQueryParams,
29+
# _ProjectConversationMessagesCreateBodyParams,
30+
# _ProjectConversationMessagesPutBodyParams,
31+
# )
2432
from simcore_service_webserver.projects._controller.conversations_rest import (
33+
_ListProjectConversationMessagesQueryParams,
2534
_ListProjectConversationsQueryParams,
2635
_ProjectConversationMessagesCreateBodyParams,
2736
_ProjectConversationMessagesPutBodyParams,
2837
_ProjectConversationsCreateBodyParams,
38+
_ProjectConversationsMessagesPathParams,
39+
_ProjectConversationsPathParams,
2940
_ProjectConversationsPutBodyParams,
3041
)
3142

@@ -46,10 +57,11 @@
4657
@router.post(
4758
"/projects/{project_id}/conversations",
4859
response_model=Envelope[ConversationRestGet],
49-
status_code=201,
60+
status_code=status.HTTP_201_CREATED,
5061
)
5162
async def create_project_conversation(
52-
project_id: ProjectID, body: _ProjectConversationsCreateBodyParams
63+
_params: Annotated[ProjectPathParams, Depends()],
64+
_body: _ProjectConversationsCreateBodyParams,
5365
): ...
5466

5567

@@ -58,32 +70,27 @@ async def create_project_conversation(
5870
response_model=Page[ConversationRestGet],
5971
)
6072
async def list_project_conversations(
61-
project_id: ProjectID, limit: int = 20, offset: NonNegativeInt = 0
73+
_params: Annotated[ProjectPathParams, Depends()],
74+
_query: Annotated[_ListProjectConversationsQueryParams, Depends()],
6275
): ...
6376

6477

65-
assert_handler_signature_against_model(
66-
list_project_conversations, _ListProjectConversationsQueryParams
67-
)
68-
69-
7078
@router.put(
7179
"/projects/{project_id}/conversations/{conversation_id}",
7280
response_model=Envelope[ConversationRestGet],
7381
)
7482
async def update_project_conversation(
75-
project_id: ProjectID,
76-
conversation_id: ConversationID,
77-
body: _ProjectConversationsPutBodyParams,
83+
_params: Annotated[_ProjectConversationsPathParams, Depends()],
84+
_body: _ProjectConversationsPutBodyParams,
7885
): ...
7986

8087

8188
@router.delete(
8289
"/projects/{project_id}/conversations/{conversation_id}",
83-
status_code=204,
90+
status_code=status.HTTP_204_NO_CONTENT,
8491
)
8592
async def delete_project_conversation(
86-
project_id: ProjectID, conversation_id: ConversationID
93+
_params: Annotated[_ProjectConversationsPathParams, Depends()],
8794
): ...
8895

8996

@@ -92,19 +99,21 @@ async def delete_project_conversation(
9299
response_model=Envelope[ConversationRestGet],
93100
)
94101
async def get_project_conversation(
95-
project_id: ProjectID, conversation_id: ConversationID
102+
_params: Annotated[_ProjectConversationsPathParams, Depends()],
96103
): ...
97104

98105

106+
### Conversation Messages
107+
108+
99109
@router.post(
100110
"/projects/{project_id}/conversations/{conversation_id}/messages",
101111
response_model=Envelope[ConversationMessageRestGet],
102-
status_code=201,
112+
status_code=status.HTTP_201_CREATED,
103113
)
104114
async def create_project_conversation_message(
105-
project_id: ProjectID,
106-
conversation_id: ConversationID,
107-
body: _ProjectConversationMessagesCreateBodyParams,
115+
_params: Annotated[_ProjectConversationsPathParams, Depends()],
116+
_body: _ProjectConversationMessagesCreateBodyParams,
108117
): ...
109118

110119

@@ -113,10 +122,8 @@ async def create_project_conversation_message(
113122
response_model=Page[ConversationMessageRestGet],
114123
)
115124
async def list_project_conversation_messages(
116-
project_id: ProjectID,
117-
conversation_id: ConversationID,
118-
limit: int = 20,
119-
offset: NonNegativeInt = 0,
125+
_params: Annotated[_ProjectConversationsPathParams, Depends()],
126+
_query: Annotated[_ListProjectConversationMessagesQueryParams, Depends()],
120127
): ...
121128

122129

@@ -125,21 +132,17 @@ async def list_project_conversation_messages(
125132
response_model=Envelope[ConversationMessageRestGet],
126133
)
127134
async def update_project_conversation_message(
128-
project_id: ProjectID,
129-
conversation_id: ConversationID,
130-
message_id: ConversationMessageID,
131-
body: _ProjectConversationMessagesPutBodyParams,
135+
_params: Annotated[_ProjectConversationsMessagesPathParams, Depends()],
136+
_body: _ProjectConversationMessagesPutBodyParams,
132137
): ...
133138

134139

135140
@router.delete(
136141
"/projects/{project_id}/conversations/{conversation_id}/messages/{message_id}",
137-
status_code=204,
142+
status_code=status.HTTP_204_NO_CONTENT,
138143
)
139144
async def delete_project_conversation_message(
140-
project_id: ProjectID,
141-
conversation_id: ConversationID,
142-
message_id: ConversationMessageID,
145+
_params: Annotated[_ProjectConversationsMessagesPathParams, Depends()],
143146
): ...
144147

145148

@@ -148,7 +151,5 @@ async def delete_project_conversation_message(
148151
response_model=Envelope[ConversationMessageRestGet],
149152
)
150153
async def get_project_conversation_message(
151-
project_id: ProjectID,
152-
conversation_id: ConversationID,
153-
message_id: ConversationMessageID,
154+
_params: Annotated[_ProjectConversationsMessagesPathParams, Depends()],
154155
): ...

packages/models-library/src/models_library/api_schemas_webserver/projects_conversations.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from ..projects import ProjectID
1717
from ._base import InputSchema, OutputSchema
1818

19+
### PROJECT CONVERSATION -------------------------------------------------------------------
20+
1921

2022
class ConversationRestGet(OutputSchema):
2123
conversation_id: ConversationID
@@ -41,6 +43,13 @@ def from_domain_model(cls, domain: ConversationDB) -> Self:
4143
)
4244

4345

46+
class ConversationPatch(InputSchema):
47+
name: str | None = None
48+
49+
50+
### PROJECT CONVERSATION MESSAGES ---------------------------------------------------------------
51+
52+
4453
class ConversationMessageRestGet(OutputSchema):
4554
message_id: ConversationMessageID
4655
conversation_id: ConversationID
@@ -63,9 +72,5 @@ def from_domain_model(cls, domain: ConversationMessageDB) -> Self:
6372
)
6473

6574

66-
class ConversationPatch(InputSchema):
67-
name: str | None = None
68-
69-
7075
class ConversationMessagePatch(InputSchema):
7176
content: str | None = None

packages/postgres-database/src/simcore_postgres_database/models/conversations.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class ConversationType(enum.Enum):
2828
"name",
2929
sa.String,
3030
nullable=False,
31-
doc="project reference for this table",
3231
),
3332
sa.Column(
3433
"project_uuid",

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4865,8 +4865,11 @@ paths:
48654865
required: false
48664866
schema:
48674867
type: integer
4868+
minimum: 1
4869+
exclusiveMaximum: true
48684870
default: 20
48694871
title: Limit
4872+
maximum: 50
48704873
- name: offset
48714874
in: query
48724875
required: false
@@ -5030,8 +5033,11 @@ paths:
50305033
required: false
50315034
schema:
50325035
type: integer
5036+
minimum: 1
5037+
exclusiveMaximum: true
50335038
default: 20
50345039
title: Limit
5040+
maximum: 50
50355041
- name: offset
50365042
in: query
50375043
required: false
@@ -17136,7 +17142,6 @@ components:
1713617142
title: Name
1713717143
type:
1713817144
$ref: '#/components/schemas/ConversationType'
17139-
additionalProperties: false
1714017145
type: object
1714117146
required:
1714217147
- name
@@ -17147,7 +17152,6 @@ components:
1714717152
name:
1714817153
type: string
1714917154
title: Name
17150-
additionalProperties: false
1715117155
type: object
1715217156
required:
1715317157
- name
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from ..errors import WebServerBaseError
22

33

4-
class ConbersationError(WebServerBaseError, ValueError): ...
4+
class ConversationError(WebServerBaseError, ValueError): ...
55

66

7-
class ConversationErrorNotFoundError(ConbersationError):
7+
class ConversationErrorNotFoundError(ConversationError):
88
msg_template = "Conversation {conversation_id} not found"
99

1010

11-
class ConversationMessageErrorNotFoundError(ConbersationError):
11+
class ConversationMessageErrorNotFoundError(ConversationError):
1212
msg_template = "Conversation {conversation_id} message {message_id} not found"

services/web/server/src/simcore_service_webserver/projects/_controller/conversations_rest.py

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from aiohttp import web
4+
from models_library.api_schemas_webserver._base import InputSchema
45
from models_library.api_schemas_webserver.projects_conversations import (
56
ConversationMessageRestGet,
67
ConversationRestGet,
@@ -11,14 +12,12 @@
1112
ConversationMessageType,
1213
ConversationType,
1314
)
14-
from models_library.projects import ProjectID
1515
from models_library.rest_pagination import (
16-
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE,
17-
MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE,
1816
Page,
17+
PageQueryParameters,
1918
)
2019
from models_library.rest_pagination_utils import paginate_data
21-
from pydantic import BaseModel, ConfigDict, Field, NonNegativeInt
20+
from pydantic import BaseModel, ConfigDict
2221
from servicelib.aiohttp import status
2322
from servicelib.aiohttp.requests_validation import (
2423
parse_request_body_as,
@@ -46,34 +45,20 @@
4645
#
4746

4847

49-
class _ProjectConversationsPathParams(BaseModel):
50-
project_id: ProjectID
48+
class _ProjectConversationsPathParams(ProjectPathParams):
5149
conversation_id: ConversationID
52-
model_config = ConfigDict(extra="forbid")
5350

5451

55-
class _ListProjectConversationsQueryParams(BaseModel):
56-
limit: int = Field(
57-
default=DEFAULT_NUMBER_OF_ITEMS_PER_PAGE,
58-
description="maximum number of items to return (pagination)",
59-
ge=1,
60-
lt=MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE,
61-
)
62-
offset: NonNegativeInt = Field(
63-
default=0, description="index to the first item to return (pagination)"
64-
)
65-
model_config = ConfigDict(extra="forbid")
52+
class _ListProjectConversationsQueryParams(PageQueryParameters): ...
6653

6754

68-
class _ProjectConversationsCreateBodyParams(BaseModel):
55+
class _ProjectConversationsCreateBodyParams(InputSchema):
6956
name: str
7057
type: ConversationType
71-
model_config = ConfigDict(extra="forbid")
7258

7359

74-
class _ProjectConversationsPutBodyParams(BaseModel):
60+
class _ProjectConversationsPutBodyParams(InputSchema):
7561
name: str
76-
model_config = ConfigDict(extra="forbid")
7762

7863

7964
@routes.post(
@@ -225,23 +210,12 @@ async def get_project_conversation(request: web.Request):
225210
#
226211

227212

228-
class _ProjectConversationsMessagesPathParams(BaseModel):
229-
project_id: ProjectID
230-
conversation_id: ConversationID
213+
class _ProjectConversationsMessagesPathParams(_ProjectConversationsPathParams):
231214
message_id: ConversationMessageID
232215
model_config = ConfigDict(extra="forbid")
233216

234217

235-
class _ListProjectConversationMessagesQueryParams(BaseModel):
236-
limit: int = Field(
237-
default=DEFAULT_NUMBER_OF_ITEMS_PER_PAGE,
238-
description="maximum number of items to return (pagination)",
239-
ge=1,
240-
lt=MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE,
241-
)
242-
offset: NonNegativeInt = Field(
243-
default=0, description="index to the first item to return (pagination)"
244-
)
218+
class _ListProjectConversationMessagesQueryParams(PageQueryParameters):
245219
model_config = ConfigDict(extra="forbid")
246220

247221

services/web/server/src/simcore_service_webserver/projects/_conversations_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from ..conversations import conversations_service
2020
from ._access_rights_service import check_user_project_permission
2121

22-
log = logging.getLogger(__name__)
22+
_logger = logging.getLogger(__name__)
2323

2424

2525
#

0 commit comments

Comments
 (0)