-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_document.go
48 lines (41 loc) · 1.46 KB
/
update_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
package document
import (
"context"
"errors"
"github.com/edgar-care/edgarlib/graphql"
"github.com/edgar-care/edgarlib/graphql/server/model"
)
type CreateDocumentInput struct {
ID string `json:"id"`
OwnerID string `json:"owner_id"`
Name string `json:"name"`
DocumentType string `json:"document_type"`
Category string `json:"category"`
IsFavorite bool `json:"is_favorite"`
DownloadURL string `json:"download_url"`
}
type UpdateDocumentResponse struct {
Document model.Document
Code int
Err error
}
func UpdateDocument(newDocumentInfo CreateDocumentInput, id string) UpdateDocumentResponse {
gqlClient := graphql.CreateClient()
updatedDocument, err := graphql.UpdateDocument(context.Background(), gqlClient, id, newDocumentInfo.Name, newDocumentInfo.IsFavorite)
if err != nil {
return UpdateDocumentResponse{Document: model.Document{}, Code: 500, Err: errors.New("unable to update document")}
}
return UpdateDocumentResponse{
Document: model.Document{
ID: updatedDocument.UpdateDocument.Id,
OwnerID: updatedDocument.UpdateDocument.Owner_id,
Name: updatedDocument.UpdateDocument.Name,
DocumentType: model.DocumentType(updatedDocument.UpdateDocument.Document_type),
Category: model.Category(updatedDocument.UpdateDocument.Category),
IsFavorite: updatedDocument.UpdateDocument.Is_favorite,
DownloadURL: updatedDocument.UpdateDocument.Download_url,
},
Code: 201,
Err: nil,
}
}