/
document_page_serializers.go
56 lines (45 loc) · 1.22 KB
/
document_page_serializers.go
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
package web
import (
"github.com/labstack/echo/v4"
"github.com/concepts-system/go-paperless/domain"
)
type documentPageResponse struct {
PageNumber uint `json:"pageNumber,omitempty"`
State string `json:"state"`
Fingerprint string `json:"fingerprint"`
Type string `json:"type"`
Text string `json:"text,omitempty"`
}
type (
documentPageSerializer struct {
C echo.Context
includeText bool
*domain.DocumentPage
}
documentPageListSerializer struct {
C echo.Context
Pages []domain.DocumentPage
}
)
// Response returns the API response for a document page.
func (s documentPageSerializer) Response() documentPageResponse {
var text string
if s.includeText {
text = string(s.Text)
}
return documentPageResponse{
PageNumber: uint(s.PageNumber),
Fingerprint: string(s.Fingerprint),
State: string(s.State),
Type: string(s.Type),
Text: text,
}
}
// Response returns the API response for a list of document pages.
func (s documentPageListSerializer) Response() []interface{} {
response := make([]interface{}, len(s.Pages))
for i, document := range s.Pages {
response[i] = documentPageSerializer{s.C, false, &document}.Response()
}
return response
}