Skip to content

Commit

Permalink
refactore code
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Jul 30, 2024
1 parent aa65c21 commit fc3be92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
26 changes: 16 additions & 10 deletions newsroom/oauth_clients/clients_async.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from content_api import MONGO_PREFIX
from typing import Optional, Annotated, List, Dict, Union
from superdesk.core.resources import ResourceModel, ResourceConfig, MongoResourceConfig
import logging
from pydantic import Field
from datetime import datetime
from typing import Optional, Annotated, List, Dict


from superdesk.core.resources import ResourceModel, ResourceConfig, MongoResourceConfig, validators
from superdesk.core.resources.service import AsyncResourceService
from superdesk.core.web import EndpointGroup
from pydantic import Field
import logging
from bson import ObjectId


from content_api import MONGO_PREFIX


class ClientResource(ResourceModel):
id: Annotated[Union[str, ObjectId], Field(alias="_id")] = None
name: str
name: Annotated[
Optional[str],
validators.validate_iunique_value_async(resource_name="oauth_clients", field_name="name"),
]
password: str
last_active: Optional[str] = None
last_active: Optional[datetime] = None
etag: Annotated[Optional[str], Field(alias="_etag")] = None


Expand All @@ -21,7 +27,7 @@ class ClientService(AsyncResourceService[ClientResource]):

resource_name = "oauth_clients"

async def get_all_client(self) -> List[Dict]:
async def get_all_clients(self) -> List[Dict]:
try:
# Collect all items asynchronously
clients = [client async for client in self.get_all()]
Expand Down
3 changes: 2 additions & 1 deletion newsroom/oauth_clients/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


async def get_settings_data():
data = await ClientService().get_all_client()
data = await ClientService().get_all_clients()
return {
"oauth_clients": data,
}
Expand Down Expand Up @@ -54,6 +54,7 @@ async def create(request: Request) -> Response:

password = gen_password()
doc = {
"_id": ObjectId(),
"name": client.get("name"),
"password": bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode(),
}
Expand Down

0 comments on commit fc3be92

Please sign in to comment.