Coverage for app/ddd/domain/model/user.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-15 01:44 +0000

1# from app.ddd.domain.factory import UserReportFactory 

2import uuid 

3from collections.abc import Mapping 

4from datetime import datetime 

5from typing import Any 

6 

7from pydantic import Field 

8 

9from app.core.base import BaseEntity, BaseValueObject 

10from app.ddd.domain import UserRoleEnum 

11 

12 

13class UserReport(BaseEntity): 

14 user_report_id: str = Field(default_factory=lambda: str(uuid.uuid4())) # デフォルトでアプリID採番 

15 title: str 

16 content: str 

17 created_user_id: str 

18 created_at: datetime | None = None 

19 updated_at: datetime | None = None 

20 

21 def _id(self) -> str: 

22 return self.user_report_id 

23 

24 

25class UserId(BaseValueObject): 

26 root: str 

27 

28class User(BaseEntity): 

29 user_id: str 

30 # user_password: SecretStr 

31 user_password: str 

32 # hashed_password: str = Field("hogehoge") 

33 user_name: str 

34 user_role_code: UserRoleEnum 

35 # user_role_name: str 

36 created_at: datetime | None = None 

37 updated_at: datetime | None = None 

38 

39 user_reports: list[UserReport] = Field([]) 

40 

41 def _id(self) -> str: 

42 return self.user_id 

43 

44 def add_report(self, **kwargs: Mapping[str, Any]) -> UserReport: 

45 user_report = UserReport( 

46 created_user_id = self.user_id, 

47 **kwargs 

48 ) 

49 self.user_reports.append(user_report) 

50 return user_report 

51 

52 

53