comparison libervia/backend/models/core.py @ 4149:c36295487082

core: introduce Pydantic based models in `libervia.backend.models.core`
author Goffi <goffi@goffi.org>
date Wed, 22 Nov 2023 14:31:05 +0100
parents
children 98687eaa6a09
comparison
equal deleted inserted replaced
4148:a8a0fa678ce2 4149:c36295487082
1 #!/usr/bin/env python3
2
3 # Libervia common models
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 from typing import Annotated, Literal
20
21 from pydantic import BaseModel, Field, validator
22
23
24 class MessageData(dict):
25 pass
26
27
28 class MessageUpdateData(BaseModel):
29 type: str
30
31 def __init__(self, **kwargs):
32 if "type" not in kwargs:
33 kwargs["type"] = "reactions"
34 super().__init__(**kwargs)
35
36
37 class MessageEditData(MessageUpdateData):
38 message: dict[str, str] | None = Field(
39 None,
40 description=(
41 "Updated message content, can be in several languages (key is language code "
42 'or "" for default)'
43 ),
44 )
45 subject: dict[str, str] | None = Field(
46 None,
47 description=(
48 "Updated subject of the message, can be in several languages (key is "
49 'language code or "" for default)'
50 ),
51 )
52 mess_type: str | None = Field(
53 None,
54 description=(
55 "Updated type of the message (cf RFC 6121 §5.2.2) + C.MESS_TYPE_INFO (system "
56 "info)"
57 ),
58 )
59
60
61 class MessageReactionData(MessageUpdateData):
62 reactions: dict[str, list[str]] = Field(
63 description="Reaction to reacting entities mapping"
64 )