@@ -43,13 +43,34 @@ type invitationServiceServerImpl struct {
43
43
}
44
44
45
45
func (s * invitationServiceServerImpl ) ListInvitations (ctx context.Context , req * api_pb.ListInvitationsRequest ) (* api_pb.ListInvitationsResponse , error ) {
46
- // TODO: Not yet implemented.
47
- return nil , status .Error (codes .Unimplemented , "TODO: You should implement it!" )
46
+ _ , err := s .getAdmin (ctx )
47
+ if err != nil {
48
+ return nil , err
49
+ }
50
+
51
+ is := s .InvitationStore (ctx )
52
+ invs , err := is .ListInvitations ()
53
+ if err != nil {
54
+ return nil , errors .WithStack (err )
55
+ }
56
+
57
+ resp := & api_pb.ListInvitationsResponse {
58
+ Invitations : invitationsToResponse (invs ),
59
+ }
60
+ return resp , nil
48
61
}
49
62
50
63
func (s * invitationServiceServerImpl ) GetInvitation (ctx context.Context , req * api_pb.GetInvitationRequest ) (* api_pb.Invitation , error ) {
51
- // TODO: Not yet implemented.
52
- return nil , status .Error (codes .Unimplemented , "TODO: You should implement it!" )
64
+ is := s .InvitationStore (ctx )
65
+ inv , err := is .GetInvitation (req .GetToken ())
66
+ if err != nil {
67
+ if errors .Cause (err ) == sql .ErrNoRows {
68
+ return nil , util .ErrNotFound
69
+ }
70
+ return nil , err
71
+ }
72
+
73
+ return invitationToResponse (inv ), nil
53
74
}
54
75
55
76
func (s * invitationServiceServerImpl ) CreateInvitation (ctx context.Context , req * api_pb.CreateInvitationRequest ) (* api_pb.Invitation , error ) {
@@ -83,8 +104,21 @@ func (s *invitationServiceServerImpl) CreateInvitation(ctx context.Context, req
83
104
}
84
105
85
106
func (s * invitationServiceServerImpl ) DeleteInvitation (ctx context.Context , req * api_pb.DeleteInvitationRequest ) (* empty.Empty , error ) {
86
- // TODO: Not yet implemented.
87
- return nil , status .Error (codes .Unimplemented , "TODO: You should implement it!" )
107
+ _ , err := s .getAdmin (ctx )
108
+ if err != nil {
109
+ return nil , err
110
+ }
111
+
112
+ is := s .InvitationStore (ctx )
113
+ err = is .DeleteInvitation (int64 (req .GetInvitationId ()))
114
+ if err != nil {
115
+ if errors .Cause (err ) == sql .ErrNoRows {
116
+ return nil , util .ErrNotFound
117
+ }
118
+ return nil , err
119
+ }
120
+
121
+ return & empty.Empty {}, nil
88
122
}
89
123
90
124
func (s * invitationServiceServerImpl ) getAdmin (ctx context.Context ) (* record.User , error ) {
@@ -105,6 +139,15 @@ func (s *invitationServiceServerImpl) getAdmin(ctx context.Context) (*record.Use
105
139
return u , nil
106
140
}
107
141
142
+ func invitationsToResponse (invs []* record.Invitation ) []* api_pb.Invitation {
143
+ resp := make ([]* api_pb.Invitation , 0 , len (invs ))
144
+ for _ , i := range invs {
145
+ resp = append (resp , invitationToResponse (i ))
146
+ }
147
+
148
+ return resp
149
+ }
150
+
108
151
func invitationToResponse (inv * record.Invitation ) * api_pb.Invitation {
109
152
return & api_pb.Invitation {
110
153
InvitationId : uint32 (inv .ID ),
0 commit comments