-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_class_router.py
More file actions
83 lines (69 loc) · 2.5 KB
/
object_class_router.py
File metadata and controls
83 lines (69 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""Object Class management routers.
Copyright (c) 2024 MultiFactor
License: https://github.com/MultiDirectoryLab/MultiDirectory/blob/main/LICENSE
"""
from typing import Annotated
from dishka.integrations.fastapi import FromDishka
from fastapi import Depends, Query, status
from api.ldap_schema import LimitedListType, error_map
from api.ldap_schema.adapters.object_class import ObjectClassFastAPIAdapter
from api.ldap_schema.attribute_type_router import ldap_schema_router
from api.ldap_schema.schema import (
ObjectClassPaginationSchema,
ObjectClassSchema,
ObjectClassUpdateSchema,
)
from api.utils import require_master_db
from ldap_protocol.utils.pagination import PaginationParams
@ldap_schema_router.post(
"/object_class",
status_code=status.HTTP_201_CREATED,
error_map=error_map,
dependencies=[Depends(require_master_db)],
)
async def create_one_object_class(
request_data: ObjectClassSchema[None],
adapter: FromDishka[ObjectClassFastAPIAdapter],
) -> None:
"""Create a new Object Class."""
await adapter.create(request_data)
@ldap_schema_router.get(
"/object_class/{object_class_name}",
error_map=error_map,
)
async def get_one_object_class(
object_class_name: str,
adapter: FromDishka[ObjectClassFastAPIAdapter],
) -> ObjectClassSchema[int]:
"""Retrieve a one Object Class."""
return await adapter.get(object_class_name)
@ldap_schema_router.get("/object_classes", error_map=error_map)
async def get_list_object_classes_with_pagination(
adapter: FromDishka[ObjectClassFastAPIAdapter],
params: Annotated[PaginationParams, Query()],
) -> ObjectClassPaginationSchema:
"""Retrieve a list of all object classes with paginate."""
return await adapter.get_list_paginated(params=params)
@ldap_schema_router.patch(
"/object_class/{object_class_name}",
error_map=error_map,
dependencies=[Depends(require_master_db)],
)
async def modify_one_object_class(
object_class_name: str,
request_data: ObjectClassUpdateSchema,
adapter: FromDishka[ObjectClassFastAPIAdapter],
) -> None:
"""Modify an Object Class."""
await adapter.update(object_class_name, request_data)
@ldap_schema_router.post(
"/object_class/delete",
error_map=error_map,
dependencies=[Depends(require_master_db)],
)
async def delete_bulk_object_classes(
object_classes_names: LimitedListType,
adapter: FromDishka[ObjectClassFastAPIAdapter],
) -> None:
"""Delete Object Classes by their names."""
await adapter.delete_bulk(object_classes_names)