-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvitations.go
47 lines (36 loc) · 1.02 KB
/
invitations.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
package bhap
import (
"context"
"google.golang.org/appengine/datastore"
)
const InvitationEntityName = "Invitation"
type Invitation struct {
Email string
UID string
EmailSent bool
}
// UnsentInvitations returns all invitations that have yet to be emailed.
func UnsentInvitations(ctx context.Context) ([]Invitation, []*datastore.Key, error) {
var results []Invitation
query := datastore.NewQuery(InvitationEntityName).
Filter("EmailSent =", false)
keys, err := query.GetAll(ctx, &results)
if err != nil {
return nil, nil, err
}
return results, keys, nil
}
// InvitationByUID returns the invitation with the corresponding UID.
func InvitationByUID(ctx context.Context, uid string) (Invitation, *datastore.Key, error) {
var results []Invitation
query := datastore.NewQuery(InvitationEntityName).
Filter("UID =", uid)
keys, err := query.GetAll(ctx, &results)
if err != nil {
return Invitation{}, nil, err
}
if len(results) == 0 {
return Invitation{}, nil, nil
}
return results[0], keys[0], nil
}