group name validation changed to accept all alphanumeric characters, fixed no groups reply

This commit is contained in:
miloszowi 2021-10-08 17:35:03 +02:00
parent b451569ddb
commit fb223556cb
2 changed files with 6 additions and 5 deletions

View File

@ -50,7 +50,7 @@ class GroupRepository:
Group(chat_id, group_name, group[self.count])
)
if not groups:
if not result:
raise NotFoundException
return result

View File

@ -4,13 +4,14 @@ from exception.invalidArgumentException import InvalidArgumentException
class GroupNameValidator:
MAX_GROUP_NAME_LENGTH: int = 20
@staticmethod
def validate(group: str) -> None:
group = group.lower()
if len(group) > 0 and not re.match(r"^[A-Za-z]+$", group):
raise InvalidArgumentException(re.escape('Group name must contain only letters.'))
if len(group) > 0 and not re.match('^\w+$', group):
raise InvalidArgumentException(re.escape('Special characters are not allowed.'))
if len(group) > 20:
raise InvalidArgumentException(re.escape(f'Group name length can not be greater than 20.'))
if len(group) > GroupNameValidator.MAX_GROUP_NAME_LENGTH:
raise InvalidArgumentException(re.escape(f'Group name length can not be greater than {GroupNameValidator.MAX_GROUP_NAME_LENGTH}.'))