11# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
22# SPDX-License-Identifier: Apache-2.0
3- from pydantic import BaseModel , ConfigDict , Field , computed_field , constr
3+ import re
4+ from typing import Annotated
5+
6+ from pydantic import BaseModel , ConfigDict , Field , StringConstraints , computed_field
47
58from syncmaster .schemas .v1 .page import PageSchema
69
10+ ALLOWED_PATTERN = re .compile (r"^[-_ a-zA-Z0-9]+$" )
11+ RESTRICTED_PATTERN = re .compile (r"[^\w\d]+" )
12+
13+ QueueName = Annotated [
14+ str ,
15+ StringConstraints (min_length = 3 , max_length = 128 , pattern = ALLOWED_PATTERN ), # noqa: WPS432
16+ ]
17+
718
819class CreateQueueSchema (BaseModel ):
9- name : constr (max_length = 128 , pattern = r"^[-_a-zA-Z0-9]+$" ) = Field ( # noqa: F722, WPS432
10- ...,
20+ name : QueueName = Field (
1121 description = "Queue name that allows letters, numbers, dashes, and underscores" ,
1222 )
13- group_id : int = Field (..., description = "Queue owner group id" )
23+ group_id : int = Field (description = "Queue owner group id" )
1424 description : str = Field (default = "" , description = "Additional description" )
1525
1626 @computed_field
1727 @property
1828 def slug (self ) -> str :
19- return f"{ self .group_id } -{ self .name } "
29+ short_name = RESTRICTED_PATTERN .sub ("_" , self .name .lower ())
30+ return f"{ self .group_id } -{ short_name } "
2031
2132
2233class ReadQueueSchema (BaseModel ):
@@ -34,4 +45,5 @@ class QueuePageSchema(PageSchema):
3445
3546
3647class UpdateQueueSchema (BaseModel ):
37- description : str | None = None
48+ name : QueueName
49+ description : str = ""
0 commit comments