forked from dullage/flatnotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
45 lines (32 loc) · 1.13 KB
/
models.py
File metadata and controls
45 lines (32 loc) · 1.13 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
from typing import List, Optional
from pydantic import Field
from pydantic.functional_validators import AfterValidator
from typing_extensions import Annotated
from helpers import CustomBaseModel, is_valid_filename, strip_whitespace
class NoteBase(CustomBaseModel):
title: str
class NoteCreate(CustomBaseModel):
title: Annotated[
str,
AfterValidator(strip_whitespace),
AfterValidator(is_valid_filename),
]
content: Optional[str] = Field(None)
class Note(CustomBaseModel):
title: str
content: Optional[str] = Field(None)
last_modified: float
class NoteUpdate(CustomBaseModel):
new_title: Annotated[
Optional[str],
AfterValidator(strip_whitespace),
AfterValidator(is_valid_filename),
] = Field(None)
new_content: Optional[str] = Field(None)
class SearchResult(CustomBaseModel):
title: str
last_modified: float
score: Optional[float] = Field(None)
title_highlights: Optional[str] = Field(None)
content_highlights: Optional[str] = Field(None)
tag_matches: Optional[List[str]] = Field(None)