-
Notifications
You must be signed in to change notification settings - Fork 0
/
favorite_document.go
34 lines (28 loc) · 1.02 KB
/
favorite_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
package document
import (
"context"
"errors"
"github.com/edgar-care/edgarlib/graphql"
"github.com/edgar-care/edgarlib/graphql/server/model"
)
func Updatefavorite(id string, favorite bool) UpdateDocumentResponse {
gqlClient := graphql.CreateClient()
document, err := graphql.GetDocumentById(context.Background(), gqlClient, id)
if err != nil {
return UpdateDocumentResponse{model.Document{}, 400, errors.New("id does not correspond to a document")}
}
updatedDocument, err := graphql.UpdateDocument(context.Background(), gqlClient, id, document.GetDocumentById.Name, favorite)
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,
IsFavorite: updatedDocument.UpdateDocument.Is_favorite,
},
Code: 201,
Err: nil,
}
}