/
get_document.go
64 lines (55 loc) · 1.85 KB
/
get_document.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
57
58
59
60
61
62
63
64
package document
import (
"context"
"errors"
"github.com/edgar-care/edgarlib/graphql"
"github.com/edgar-care/edgarlib/graphql/server/model"
)
type GetDocumentByIdResponse struct {
Document model.Document
Code int
Err error
}
type GetDocumentsResponse struct {
Documents []model.Document
Code int
Err error
}
func GetDocument(id string) GetDocumentByIdResponse {
gqlClient := graphql.CreateClient()
var res model.Document
document, err := graphql.GetDocumentById(context.Background(), gqlClient, id)
if err != nil {
return GetDocumentByIdResponse{model.Document{}, 400, errors.New("id does not correspond to a document")}
}
res = model.Document{
ID: document.GetDocumentById.Id,
OwnerID: document.GetDocumentById.Owner_id,
Name: document.GetDocumentById.Name,
DocumentType: model.DocumentType(document.GetDocumentById.Document_type),
Category: model.Category(document.GetDocumentById.Category),
IsFavorite: document.GetDocumentById.Is_favorite,
DownloadURL: document.GetDocumentById.Download_url,
}
return GetDocumentByIdResponse{res, 200, nil}
}
func GetDocuments(id string) GetDocumentsResponse {
gqlClient := graphql.CreateClient()
var res []model.Document
documents, err := graphql.GetPatientDocument(context.Background(), gqlClient, id)
if err != nil {
return GetDocumentsResponse{[]model.Document{}, 400, errors.New("invalid input: " + err.Error())}
}
for _, document := range documents.GetPatientDocument {
res = append(res, model.Document{
ID: document.Id,
OwnerID: document.Owner_id,
Name: document.Name,
DocumentType: model.DocumentType(document.Document_type),
Category: model.Category(document.Category),
IsFavorite: document.Is_favorite,
DownloadURL: document.Download_url,
})
}
return GetDocumentsResponse{res, 200, nil}
}