@@ -5,36 +5,149 @@ import (
55 "time"
66
77 "github.com/golang/geo/s2"
8- dsserr "github.com/interuss/dss/pkg/errors"
98 dssmodels "github.com/interuss/dss/pkg/models"
109 ridmodels "github.com/interuss/dss/pkg/rid/models"
1110 "github.com/interuss/stacktrace"
1211)
1312
14- func (r * repo ) GetISA (_ context.Context , id dssmodels.ID , forUpdate bool ) (* ridmodels.IdentificationServiceArea , error ) {
15- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "GetISA not implemented for raftstore" )
13+ type getISAPayload struct {
14+ ID dssmodels.ID
15+ ForUpdate bool
1616}
1717
18- func (r * repo ) DeleteISA (_ context.Context , isa * ridmodels.IdentificationServiceArea ) (* ridmodels.IdentificationServiceArea , error ) {
19- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "DeleteISA not implemented for raftstore" )
18+ func (r * repo ) GetISA (ctx context.Context , id dssmodels.ID , forUpdate bool ) (* ridmodels.IdentificationServiceArea , error ) {
19+ result , err := r .consensus .ProposeValue (ctx , storeID , getISA , & getISAPayload {ID : id , ForUpdate : forUpdate }, true )
20+ if err != nil {
21+ return nil , err
22+ }
23+
24+ if result == nil {
25+ return nil , nil
26+ }
27+
28+ isa , ok := result .(* ridmodels.IdentificationServiceArea )
29+ if ! ok {
30+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
31+ }
32+
33+ return isa , nil
2034}
2135
22- func (r * repo ) InsertISA (_ context.Context , isa * ridmodels.IdentificationServiceArea ) (* ridmodels.IdentificationServiceArea , error ) {
23- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "InsertISA not implemented for raftstore" )
36+ func (r * repo ) DeleteISA (ctx context.Context , isa * ridmodels.IdentificationServiceArea ) (* ridmodels.IdentificationServiceArea , error ) {
37+ result , err := r .consensus .ProposeValue (ctx , storeID , deleteISA , isa , false )
38+ if err != nil {
39+ return nil , err
40+ }
41+
42+ if result == nil {
43+ return nil , nil
44+ }
45+
46+ isa , ok := result .(* ridmodels.IdentificationServiceArea )
47+ if ! ok {
48+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
49+ }
50+
51+ return isa , nil
2452}
2553
26- func (r * repo ) UpdateISA (_ context.Context , isa * ridmodels.IdentificationServiceArea ) (* ridmodels.IdentificationServiceArea , error ) {
27- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "UpdateISA not implemented for raftstore" )
54+ func (r * repo ) InsertISA (ctx context.Context , isa * ridmodels.IdentificationServiceArea ) (* ridmodels.IdentificationServiceArea , error ) {
55+ result , err := r .consensus .ProposeValue (ctx , storeID , insertISA , isa , false )
56+ if err != nil {
57+ return nil , err
58+ }
59+
60+ if result == nil {
61+ return nil , nil
62+ }
63+
64+ isa , ok := result .(* ridmodels.IdentificationServiceArea )
65+ if ! ok {
66+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
67+ }
68+
69+ return isa , nil
2870}
2971
30- func (r * repo ) SearchISAs (_ context.Context , cells s2.CellUnion , earliest * time.Time , latest * time.Time ) ([]* ridmodels.IdentificationServiceArea , error ) {
31- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "SearchISAs not implemented for raftstore" )
72+ func (r * repo ) UpdateISA (ctx context.Context , isa * ridmodels.IdentificationServiceArea ) (* ridmodels.IdentificationServiceArea , error ) {
73+ result , err := r .consensus .ProposeValue (ctx , storeID , updateISA , isa , false )
74+ if err != nil {
75+ return nil , err
76+ }
77+
78+ if result == nil {
79+ return nil , nil
80+ }
81+
82+ isa , ok := result .(* ridmodels.IdentificationServiceArea )
83+ if ! ok {
84+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
85+ }
86+
87+ return isa , nil
3288}
3389
34- func (r * repo ) ListExpiredISAs (_ context.Context , writer string , threshold time.Time ) ([]* ridmodels.IdentificationServiceArea , error ) {
35- return nil , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "ListExpiredISAs not implemented for raftstore" )
90+ type searchISAsPayload struct {
91+ Cells s2.CellUnion
92+ Earliest * time.Time
93+ Latest * time.Time
3694}
3795
38- func (r * repo ) CountISAs (_ context.Context ) (int64 , error ) {
39- return 0 , stacktrace .NewErrorWithCode (dsserr .NotImplemented , "CountISAs not implemented for raftstore" )
96+ func (r * repo ) SearchISAs (ctx context.Context , cells s2.CellUnion , earliest * time.Time , latest * time.Time ) ([]* ridmodels.IdentificationServiceArea , error ) {
97+ result , err := r .consensus .ProposeValue (ctx , storeID , searchISAs , & searchISAsPayload {Cells : cells , Earliest : earliest , Latest : latest }, true )
98+ if err != nil {
99+ return nil , err
100+ }
101+
102+ if result == nil {
103+ return nil , nil
104+ }
105+
106+ isa , ok := result .([]* ridmodels.IdentificationServiceArea )
107+ if ! ok {
108+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
109+ }
110+
111+ return isa , nil
112+ }
113+
114+ type listExpiredISAsPayload struct {
115+ Writer string
116+ Threshold time.Time
117+ }
118+
119+ func (r * repo ) ListExpiredISAs (ctx context.Context , writer string , threshold time.Time ) ([]* ridmodels.IdentificationServiceArea , error ) {
120+ result , err := r .consensus .ProposeValue (ctx , storeID , listExpiredISAs , & listExpiredISAsPayload {Writer : writer , Threshold : threshold }, true )
121+ if err != nil {
122+ return nil , err
123+ }
124+
125+ if result == nil {
126+ return nil , nil
127+ }
128+
129+ isa , ok := result .([]* ridmodels.IdentificationServiceArea )
130+ if ! ok {
131+ return nil , stacktrace .NewError ("invalid result type: %T" , result )
132+ }
133+
134+ return isa , nil
135+ }
136+
137+ func (r * repo ) CountISAs (ctx context.Context ) (int64 , error ) {
138+ result , err := r .consensus .ProposeValue (ctx , storeID , countISAs , nil , true )
139+ if err != nil {
140+ return 0 , err
141+ }
142+
143+ if result == nil {
144+ return 0 , nil
145+ }
146+
147+ count , ok := result .(int64 )
148+ if ! ok {
149+ return 0 , stacktrace .NewError ("invalid result type: %T" , result )
150+ }
151+
152+ return count , nil
40153}
0 commit comments