This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
/
protocol_create_name_card_logs.go
124 lines (94 loc) · 3.24 KB
/
protocol_create_name_card_logs.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2019 The go-pttai Authors
// This file is part of the go-pttai library.
//
// The go-pttai library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-pttai library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-pttai library. If not, see <http://www.gnu.org/licenses/>.
package account
import (
"github.com/ailabstw/go-pttai/common/types"
pkgservice "github.com/ailabstw/go-pttai/service"
)
func (pm *ProtocolManager) handleCreateNameCardLogs(oplog *pkgservice.BaseOplog, info *ProcessUserInfo) ([]*pkgservice.BaseOplog, error) {
obj := NewEmptyNameCard()
pm.SetNameCardDB(obj)
opData := &UserOpCreateNameCard{}
return pm.HandleCreateObjectLog(
oplog,
obj,
opData,
info,
pm.existsInInfoCreateNameCard,
pm.newNameCardWithOplog,
nil,
pm.updateCreateNameCardInfo,
)
}
func (pm *ProtocolManager) handlePendingCreateNameCardLogs(oplog *pkgservice.BaseOplog, info *ProcessUserInfo) (types.Bool, []*pkgservice.BaseOplog, error) {
obj := NewEmptyNameCard()
pm.SetNameCardDB(obj)
opData := &UserOpCreateNameCard{}
return pm.HandlePendingCreateObjectLog(
oplog,
obj,
opData,
info,
pm.existsInInfoCreateNameCard,
pm.newNameCardWithOplog,
nil,
pm.updateCreateNameCardInfo,
)
}
func (pm *ProtocolManager) setNewestCreateNameCardLog(oplog *pkgservice.BaseOplog) (types.Bool, error) {
obj := NewEmptyNameCard()
pm.SetNameCardDB(obj)
return pm.SetNewestCreateObjectLog(oplog, obj)
}
func (pm *ProtocolManager) handleFailedCreateNameCardLog(oplog *pkgservice.BaseOplog) error {
obj := NewEmptyNameCard()
pm.SetNameCardDB(obj)
return pm.HandleFailedCreateObjectLog(oplog, obj, nil)
}
func (pm *ProtocolManager) handleFailedValidCreateNameCardLog(oplog *pkgservice.BaseOplog, info *ProcessUserInfo) error {
obj := NewEmptyNameCard()
pm.SetNameCardDB(obj)
return pm.HandleFailedValidCreateObjectLog(oplog, obj, nil)
}
/**********
* Customize
**********/
func (pm *ProtocolManager) newNameCardWithOplog(oplog *pkgservice.BaseOplog, theOpData pkgservice.OpData) pkgservice.Object {
obj := NewEmptyNameCard()
pm.SetNameCardDB(obj)
pkgservice.NewObjectWithOplog(obj, oplog)
return obj
}
func (pm *ProtocolManager) existsInInfoCreateNameCard(oplog *pkgservice.BaseOplog, theInfo pkgservice.ProcessInfo) (bool, error) {
info, ok := theInfo.(*ProcessUserInfo)
if !ok {
return false, pkgservice.ErrInvalidData
}
objID := oplog.ObjID
_, ok = info.CreateNameCardInfo[*objID]
if ok {
return true, nil
}
return false, nil
}
func (pm *ProtocolManager) updateCreateNameCardInfo(obj pkgservice.Object, oplog *pkgservice.BaseOplog, theOpData pkgservice.OpData, theInfo pkgservice.ProcessInfo) error {
info, ok := theInfo.(*ProcessUserInfo)
if !ok {
return pkgservice.ErrInvalidData
}
info.CreateNameCardInfo[*oplog.ObjID] = oplog
return nil
}