storage: Migrate to typed_endpoint.

This commit is contained in:
Kenneth Rodrigues
2024-06-06 18:08:28 +05:30
committed by Tim Abbott
parent 199d641fae
commit 07d0854ed3
2 changed files with 13 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
from typing import Dict, List, Optional
from django.http import HttpRequest, HttpResponse
from pydantic import Json
from zerver.lib.bot_storage import (
StateError,
@@ -10,17 +11,17 @@ from zerver.lib.bot_storage import (
set_bot_storage,
)
from zerver.lib.exceptions import JsonableError
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.validator import check_dict, check_list, check_string
from zerver.lib.typed_endpoint import typed_endpoint
from zerver.models import UserProfile
@has_request_variables
@typed_endpoint
def update_storage(
request: HttpRequest,
user_profile: UserProfile,
storage: Dict[str, str] = REQ(json_validator=check_dict([], value_validator=check_string)),
*,
storage: Json[Dict[str, str]],
) -> HttpResponse:
try:
set_bot_storage(user_profile, list(storage.items()))
@@ -29,11 +30,12 @@ def update_storage(
return json_success(request)
@has_request_variables
@typed_endpoint
def get_storage(
request: HttpRequest,
user_profile: UserProfile,
keys: Optional[List[str]] = REQ(json_validator=check_list(check_string), default=None),
*,
keys: Json[Optional[List[str]]] = None,
) -> HttpResponse:
if keys is None:
keys = get_keys_in_bot_storage(user_profile)
@@ -44,11 +46,12 @@ def get_storage(
return json_success(request, data={"storage": storage})
@has_request_variables
@typed_endpoint
def remove_storage(
request: HttpRequest,
user_profile: UserProfile,
keys: Optional[List[str]] = REQ(json_validator=check_list(check_string), default=None),
*,
keys: Json[Optional[List[str]]] = None,
) -> HttpResponse:
if keys is None:
keys = get_keys_in_bot_storage(user_profile)