-
Notifications
You must be signed in to change notification settings - Fork 6
/
partial_update_utils.go
53 lines (43 loc) · 1.09 KB
/
partial_update_utils.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
package restli
import "github.com/PapaCharlie/go-restli/restlicodec"
const (
PatchField = "patch"
)
var RequiredPatchRecordFields = restlicodec.RequiredFields{PatchField}
type PartialUpdateFieldChecker struct {
RecordType string
HasDeletes bool
HasSets bool
}
func (c *PartialUpdateFieldChecker) CheckField(
checker restlicodec.KeyChecker,
fieldName string,
isDeleteSet bool,
isSetSet bool,
isPartialUpdateSet bool,
) error {
if !(isDeleteSet || isSetSet || isPartialUpdateSet) {
return nil
}
if checker.IsKeyExcluded(fieldName) {
return &IllegalPartialUpdateError{
Message: "Cannot delete/update/partial update read-only or create-ony",
Field: fieldName,
RecordType: c.RecordType,
}
}
if (isDeleteSet && isSetSet) || (isDeleteSet && isPartialUpdateSet) || (isSetSet && isPartialUpdateSet) {
return &IllegalPartialUpdateError{
Message: "Only one of set/update/partial update can be specified for",
Field: fieldName,
RecordType: c.RecordType,
}
}
if isDeleteSet {
c.HasDeletes = true
}
if isSetSet {
c.HasSets = true
}
return nil
}