Coverage for src/lexigram/admin/mapping/admin_mappings.py: 0%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 23:18 +0800

1"""Admin mapping registrations. 

2 

3Wires up all AdminObjectMapper mappings between admin domain objects. 

4Call :func:`register_admin_mappings` once during provider boot to make all 

5mappings available. 

6""" 

7 

8from __future__ import annotations 

9 

10from typing import TYPE_CHECKING, Any 

11 

12from lexigram.admin.auth.entity import AdminUserEntity 

13from lexigram.admin.auth.user import AdminUserRecord 

14 

15if TYPE_CHECKING: 

16 from lexigram.admin.mapping.mapper import AdminObjectMapper 

17 

18 

19def _entity_to_record(entity: AdminUserEntity) -> AdminUserRecord: 

20 """Map :class:`AdminUserEntity` → :class:`AdminUserRecord`.""" 

21 return entity.to_user() 

22 

23 

24def _entity_to_dict(entity: AdminUserEntity) -> dict[str, Any]: 

25 """Map :class:`AdminUserEntity` → plain dict.""" 

26 return { 

27 "id": entity.id, 

28 "username": entity.username, 

29 "email": entity.email, 

30 "roles": list(entity.roles), 

31 "permissions": list(entity.permissions), 

32 "is_active": entity.is_active, 

33 "is_verified": entity.is_verified, 

34 "created_at": entity.created_at.isoformat(), 

35 "updated_at": entity.updated_at.isoformat() if entity.updated_at else None, 

36 } 

37 

38 

39def _record_to_entity(record: AdminUserRecord) -> AdminUserEntity: 

40 """Map :class:`AdminUserRecord` → :class:`AdminUserEntity`.""" 

41 return AdminUserEntity.from_user(record) 

42 

43 

44def register_admin_mappings(mapper: AdminObjectMapper) -> None: 

45 """Register all admin domain object mappings on *mapper*. 

46 

47 Args: 

48 mapper: The :class:`~lexigram.admin.mapping.mapper.AdminObjectMapper` 

49 instance to register mappings on. 

50 """ 

51 mapper.register(AdminUserEntity, AdminUserRecord, _entity_to_record) 

52 mapper.register(AdminUserEntity, dict, _entity_to_dict) 

53 mapper.register(AdminUserRecord, AdminUserEntity, _record_to_entity) 

54 

55 

56__all__ = ["register_admin_mappings"]