Coverage for src/kwai/api/v1/club/schemas/upload.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module for defining the JSON:API resource for an upload.""" 

2 

3from types import NoneType 

4from typing import Self 

5 

6from pydantic import BaseModel 

7 

8from kwai.api.v1.club.schemas.resources import ( 

9 UploadResourceIdentifier, 

10) 

11from kwai.core.json_api import Document, ResourceData, ResourceMeta 

12from kwai.modules.club.domain.file_upload import FileUploadEntity 

13 

14 

15class UploadAttributes(BaseModel): 

16 """Attributes for the upload JSON:API resource.""" 

17 

18 filename: str 

19 remark: str 

20 preview: bool 

21 

22 

23class UploadResource( 

24 UploadResourceIdentifier, ResourceData[UploadAttributes, NoneType] 

25): 

26 """A JSON:API resource for an upload.""" 

27 

28 

29class UploadDocument(Document[UploadResource, NoneType]): 

30 """A JSON:API document for an upload.""" 

31 

32 @classmethod 

33 def create(cls, upload: FileUploadEntity) -> Self: 

34 """Create a document for an upload.""" 

35 upload_resource = UploadResource( 

36 id=str(upload.uuid), 

37 attributes=UploadAttributes( 

38 filename=upload.filename, remark=upload.remark, preview=upload.preview 

39 ), 

40 meta=ResourceMeta( 

41 created_at=str(upload.traceable_time.created_at), 

42 updated_at=str(upload.traceable_time.updated_at), 

43 ), 

44 ) 

45 

46 return cls(data=upload_resource)