Skip to content

Commit 8b79707

Browse files
review @pcrespov
1 parent 923ee21 commit 8b79707

File tree

8 files changed

+53
-49
lines changed

8 files changed

+53
-49
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from pydantic import Field
55

66
from ..conversations import (
7-
ConversationDB,
7+
ConversationGetDB,
88
ConversationID,
9-
ConversationMessageDB,
9+
ConversationMessageGetDB,
1010
ConversationMessageID,
1111
ConversationMessageType,
1212
ConversationType,
@@ -30,7 +30,7 @@ class ConversationRestGet(OutputSchema):
3030
modified: datetime
3131

3232
@classmethod
33-
def from_domain_model(cls, domain: ConversationDB) -> Self:
33+
def from_domain_model(cls, domain: ConversationGetDB) -> Self:
3434
return cls(
3535
conversation_id=domain.conversation_id,
3636
product_name=domain.product_name,
@@ -60,7 +60,7 @@ class ConversationMessageRestGet(OutputSchema):
6060
modified: datetime
6161

6262
@classmethod
63-
def from_domain_model(cls, domain: ConversationMessageDB) -> Self:
63+
def from_domain_model(cls, domain: ConversationMessageGetDB) -> Self:
6464
return cls(
6565
message_id=domain.message_id,
6666
conversation_id=domain.conversation_id,

packages/models-library/src/models_library/conversations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ConversationMessageType(StrAutoEnum):
3333
#
3434

3535

36-
class ConversationDB(BaseModel):
36+
class ConversationGetDB(BaseModel):
3737
conversation_id: ConversationID
3838
product_name: ProductName
3939
name: str
@@ -48,7 +48,7 @@ class ConversationDB(BaseModel):
4848
model_config = ConfigDict(from_attributes=True)
4949

5050

51-
class ConversationMessageDB(BaseModel):
51+
class ConversationMessageGetDB(BaseModel):
5252
message_id: ConversationMessageID
5353
conversation_id: ConversationID
5454
user_group_id: GroupID

services/web/server/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.63.0
1+
0.64.0

services/web/server/src/simcore_service_webserver/conversations/_conversation_message_repository.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
from aiohttp import web
55
from models_library.conversations import (
66
ConversationID,
7-
ConversationMessageDB,
7+
ConversationMessageGetDB,
88
ConversationMessageID,
99
ConversationMessagePatchDB,
1010
ConversationMessageType,
1111
)
1212
from models_library.groups import GroupID
1313
from models_library.rest_ordering import OrderBy, OrderDirection
14+
from models_library.rest_pagination import PageTotalCount
1415
from pydantic import NonNegativeInt
1516
from simcore_postgres_database.models.conversation_messages import conversation_messages
1617
from simcore_postgres_database.utils_repos import (
@@ -29,7 +30,7 @@
2930

3031

3132
_SELECTION_ARGS = get_columns_from_db_model(
32-
conversation_messages, ConversationMessageDB
33+
conversation_messages, ConversationMessageGetDB
3334
)
3435

3536

@@ -41,7 +42,7 @@ async def create(
4142
user_group_id: GroupID,
4243
content: str,
4344
type_: ConversationMessageType,
44-
) -> ConversationMessageDB:
45+
) -> ConversationMessageGetDB:
4546
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
4647
result = await conn.execute(
4748
conversation_messages.insert()
@@ -56,7 +57,7 @@ async def create(
5657
.returning(*_SELECTION_ARGS)
5758
)
5859
row = result.one()
59-
return ConversationMessageDB.model_validate(row)
60+
return ConversationMessageGetDB.model_validate(row)
6061

6162

6263
async def list_(
@@ -69,7 +70,7 @@ async def list_(
6970
limit: NonNegativeInt,
7071
# ordering
7172
order_by: OrderBy,
72-
) -> tuple[int, list[ConversationMessageDB]]:
73+
) -> tuple[PageTotalCount, list[ConversationMessageGetDB]]:
7374

7475
base_query = (
7576
select(*_SELECTION_ARGS)
@@ -98,8 +99,8 @@ async def list_(
9899
total_count = await conn.scalar(count_query)
99100

100101
result = await conn.stream(list_query)
101-
items: list[ConversationMessageDB] = [
102-
ConversationMessageDB.model_validate(row) async for row in result
102+
items: list[ConversationMessageGetDB] = [
103+
ConversationMessageGetDB.model_validate(row) async for row in result
103104
]
104105

105106
return cast(int, total_count), items
@@ -111,7 +112,7 @@ async def get(
111112
*,
112113
conversation_id: ConversationID,
113114
message_id: ConversationMessageID,
114-
) -> ConversationMessageDB:
115+
) -> ConversationMessageGetDB:
115116
select_query = (
116117
select(*_SELECTION_ARGS)
117118
.select_from(conversation_messages)
@@ -128,7 +129,7 @@ async def get(
128129
raise ConversationMessageErrorNotFoundError(
129130
conversation_id=conversation_id, message_id=message_id
130131
)
131-
return ConversationMessageDB.model_validate(row)
132+
return ConversationMessageGetDB.model_validate(row)
132133

133134

134135
async def update(
@@ -138,7 +139,7 @@ async def update(
138139
conversation_id: ConversationID,
139140
message_id: ConversationMessageID,
140141
updates: ConversationMessagePatchDB,
141-
) -> ConversationMessageDB:
142+
) -> ConversationMessageGetDB:
142143
# NOTE: at least 'touch' if updated_values is empty
143144
_updates = {
144145
**updates.model_dump(exclude_unset=True),
@@ -160,7 +161,7 @@ async def update(
160161
raise ConversationMessageErrorNotFoundError(
161162
conversation_id=conversation_id, message_id=message_id
162163
)
163-
return ConversationMessageDB.model_validate(row)
164+
return ConversationMessageGetDB.model_validate(row)
164165

165166

166167
async def delete(

services/web/server/src/simcore_service_webserver/conversations/_conversation_message_service.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
from models_library.basic_types import IDStr
77
from models_library.conversations import (
88
ConversationID,
9-
ConversationMessageDB,
9+
ConversationMessageGetDB,
1010
ConversationMessageID,
1111
ConversationMessagePatchDB,
1212
ConversationMessageType,
1313
)
1414
from models_library.rest_ordering import OrderBy, OrderDirection
15+
from models_library.rest_pagination import PageTotalCount
1516
from models_library.users import UserID
1617

1718
from ..users.api import get_user_primary_group_id
@@ -28,7 +29,7 @@ async def create_message(
2829
# Creation attributes
2930
content: str,
3031
type_: ConversationMessageType,
31-
) -> ConversationMessageDB:
32+
) -> ConversationMessageGetDB:
3233
_user_group_id = await get_user_primary_group_id(app, user_id=user_id)
3334

3435
return await _conversation_message_repository.create(
@@ -45,7 +46,7 @@ async def get_message(
4546
*,
4647
conversation_id: ConversationID,
4748
message_id: ConversationMessageID,
48-
) -> ConversationMessageDB:
49+
) -> ConversationMessageGetDB:
4950
return await _conversation_message_repository.get(
5051
app, conversation_id=conversation_id, message_id=message_id
5152
)
@@ -58,7 +59,7 @@ async def update_message(
5859
message_id: ConversationMessageID,
5960
# Update attributes
6061
updates: ConversationMessagePatchDB,
61-
) -> ConversationMessageDB:
62+
) -> ConversationMessageGetDB:
6263
return await _conversation_message_repository.update(
6364
app,
6465
conversation_id=conversation_id,
@@ -87,7 +88,7 @@ async def list_messages_for_conversation(
8788
# pagination
8889
offset: int = 0,
8990
limit: int = 20,
90-
) -> tuple[int, list[ConversationMessageDB]]:
91+
) -> tuple[PageTotalCount, list[ConversationMessageGetDB]]:
9192
return await _conversation_message_repository.list_(
9293
app,
9394
conversation_id=conversation_id,

services/web/server/src/simcore_service_webserver/conversations/_conversation_repository.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from aiohttp import web
55
from models_library.conversations import (
6-
ConversationDB,
6+
ConversationGetDB,
77
ConversationID,
88
ConversationPatchDB,
99
ConversationType,
@@ -12,6 +12,7 @@
1212
from models_library.products import ProductName
1313
from models_library.projects import ProjectID
1414
from models_library.rest_ordering import OrderBy, OrderDirection
15+
from models_library.rest_pagination import PageTotalCount
1516
from pydantic import NonNegativeInt
1617
from simcore_postgres_database.models.conversations import conversations
1718
from simcore_postgres_database.utils_repos import (
@@ -29,7 +30,7 @@
2930
_logger = logging.getLogger(__name__)
3031

3132

32-
_SELECTION_ARGS = get_columns_from_db_model(conversations, ConversationDB)
33+
_SELECTION_ARGS = get_columns_from_db_model(conversations, ConversationGetDB)
3334

3435

3536
async def create(
@@ -41,7 +42,7 @@ async def create(
4142
user_group_id: GroupID,
4243
type_: ConversationType,
4344
product_name: ProductName,
44-
) -> ConversationDB:
45+
) -> ConversationGetDB:
4546
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
4647
result = await conn.execute(
4748
conversations.insert()
@@ -57,7 +58,7 @@ async def create(
5758
.returning(*_SELECTION_ARGS)
5859
)
5960
row = result.one()
60-
return ConversationDB.model_validate(row)
61+
return ConversationGetDB.model_validate(row)
6162

6263

6364
async def list_project_conversations(
@@ -70,7 +71,7 @@ async def list_project_conversations(
7071
limit: NonNegativeInt,
7172
# ordering
7273
order_by: OrderBy,
73-
) -> tuple[int, list[ConversationDB]]:
74+
) -> tuple[PageTotalCount, list[ConversationGetDB]]:
7475

7576
base_query = (
7677
select(*_SELECTION_ARGS)
@@ -99,8 +100,8 @@ async def list_project_conversations(
99100
total_count = await conn.scalar(count_query)
100101

101102
result = await conn.stream(list_query)
102-
items: list[ConversationDB] = [
103-
ConversationDB.model_validate(row) async for row in result
103+
items: list[ConversationGetDB] = [
104+
ConversationGetDB.model_validate(row) async for row in result
104105
]
105106

106107
return cast(int, total_count), items
@@ -111,7 +112,7 @@ async def get(
111112
connection: AsyncConnection | None = None,
112113
*,
113114
conversation_id: ConversationID,
114-
) -> ConversationDB:
115+
) -> ConversationGetDB:
115116
select_query = (
116117
select(*_SELECTION_ARGS)
117118
.select_from(conversations)
@@ -123,7 +124,7 @@ async def get(
123124
row = result.one_or_none()
124125
if row is None:
125126
raise ConversationErrorNotFoundError(conversation_id=conversation_id)
126-
return ConversationDB.model_validate(row)
127+
return ConversationGetDB.model_validate(row)
127128

128129

129130
async def update(
@@ -132,7 +133,7 @@ async def update(
132133
*,
133134
conversation_id: ConversationID,
134135
updates: ConversationPatchDB,
135-
) -> ConversationDB:
136+
) -> ConversationGetDB:
136137
# NOTE: at least 'touch' if updated_values is empty
137138
_updates = {
138139
**updates.model_dump(exclude_unset=True),
@@ -149,7 +150,7 @@ async def update(
149150
row = result.one_or_none()
150151
if row is None:
151152
raise ConversationErrorNotFoundError(conversation_id=conversation_id)
152-
return ConversationDB.model_validate(row)
153+
return ConversationGetDB.model_validate(row)
153154

154155

155156
async def delete(

services/web/server/src/simcore_service_webserver/conversations/_conversation_service.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
from aiohttp import web
66
from models_library.basic_types import IDStr
77
from models_library.conversations import (
8-
ConversationDB,
8+
ConversationGetDB,
99
ConversationID,
1010
ConversationPatchDB,
1111
ConversationType,
1212
)
1313
from models_library.products import ProductName
1414
from models_library.projects import ProjectID
1515
from models_library.rest_ordering import OrderBy, OrderDirection
16+
from models_library.rest_pagination import PageTotalCount
1617
from models_library.users import UserID
1718

1819
from ..users.api import get_user_primary_group_id
@@ -30,7 +31,7 @@ async def create_conversation(
3031
# Creation attributes
3132
name: str,
3233
type_: ConversationType,
33-
) -> ConversationDB:
34+
) -> ConversationGetDB:
3435
if project_uuid is None:
3536
raise NotImplementedError
3637

@@ -50,7 +51,7 @@ async def get_conversation(
5051
app: web.Application,
5152
*,
5253
conversation_id: ConversationID,
53-
) -> ConversationDB:
54+
) -> ConversationGetDB:
5455
return await _conversation_repository.get(
5556
app,
5657
conversation_id=conversation_id,
@@ -63,7 +64,7 @@ async def update_conversation(
6364
conversation_id: ConversationID,
6465
# Update attributes
6566
updates: ConversationPatchDB,
66-
) -> ConversationDB:
67+
) -> ConversationGetDB:
6768
return await _conversation_repository.update(
6869
app,
6970
conversation_id=conversation_id,
@@ -89,7 +90,7 @@ async def list_conversations_for_project(
8990
# pagination
9091
offset: int = 0,
9192
limit: int = 20,
92-
) -> tuple[int, list[ConversationDB]]:
93+
) -> tuple[PageTotalCount, list[ConversationGetDB]]:
9394
return await _conversation_repository.list_project_conversations(
9495
app,
9596
project_uuid=project_uuid,

0 commit comments

Comments
 (0)