-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.go
More file actions
58 lines (53 loc) · 1.89 KB
/
data.go
File metadata and controls
58 lines (53 loc) · 1.89 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
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"time"
"github.com/google/uuid"
)
const (
DoesNotExist = iota + 100 // 100 does not exit
IncompleteRequest // 101 incomplete request
UnsupportedMethod // 102 unsupported method
InsertError // 103 insert error
Accepted // 104 request accepted
Updated // 105 requested updated
Deleted // 106 request deleted
InProgress // 107 request in progress
SyncMetadata // 108 synching metadata
SyncProvenance // 109 synching provenance records
Completed // 110 request completed
Failed // 111 request failed
)
// SyncRequest represents SyncService request data payload
type SyncRequest struct {
UUID string `json:"uuid"`
Did string `json:"did,omitempty"`
SourceURL string `json:"source_url"`
SourceToken string `json:"source_token"`
TargetURL string `json:"target_url"`
TargetToken string `json:"target_token"`
Status string `json:"status"`
StatusCode int `json:"status_code"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Btrs []string `json:"btrs,omitempty"`
Continuous bool `json:"continuous"`
}
// RequestRecord creates new request record for database out of payload
func (p *SyncRequest) RequestRecord() map[string]any {
rec := make(map[string]any)
rec["source_url"] = p.SourceURL
rec["target_url"] = p.TargetURL
rec["source_token"] = p.SourceToken
rec["target_token"] = p.TargetToken
if p.UUID != "" {
rec["uuid"] = p.UUID
} else {
uuid, _ := uuid.NewRandom()
rec["uuid"] = uuid.String()
}
rec["status"] = "sync request is accepted"
rec["status_code"] = Accepted
rec["created_at"] = time.Now().Format(time.RFC3339)
rec["continuous"] = p.Continuous
return rec
}