-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign_up_mutation.go
77 lines (61 loc) · 1.56 KB
/
sign_up_mutation.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
package community_api_go
import (
"context"
"github.com/214alphadev/community-api-go/scalars"
cd "github.com/214alphadev/community-bl"
vo "github.com/214alphadev/community-bl/value_objects"
)
type signUpResponse struct {
error error
member *Member
}
func (r signUpResponse) Error() *string {
switch r.error {
case nil:
return nil
default:
e := r.error.Error()
return &e
}
}
func (r signUpResponse) Member() *Member {
return r.member
}
type ProperNameInput struct {
FirstName string
LastName string
}
type signUpInput struct {
Username scalars.Username
EmailAddress scalars.EmailAddress
ProperName ProperNameInput
ProfilePicture *scalars.ProfilePicture
}
func (r *rootResolver) SignUp(ctx context.Context, args struct{ Input signUpInput }) (signUpResponse, error) {
input := args.Input
properName, err := vo.NewProperName(input.ProperName.FirstName, input.ProperName.LastName)
if err != nil {
return signUpResponse{}, err
}
metadata := cd.MetadataEntity{
ProperName: properName,
}
if args.Input.ProfilePicture != nil {
metadata.ProfileImage = &args.Input.ProfilePicture.Base64String
}
member, err := r.community.SignUp(args.Input.Username.Username, args.Input.EmailAddress.EmailAddress, metadata)
switch err {
case nil:
m := newMemberTypeFromEntity(member, member)
return signUpResponse{member: &m}, nil
default:
switch err.Error() {
case "UsernameTaken":
return signUpResponse{error: err}, nil
case "EmailAddressTaken":
return signUpResponse{error: err}, nil
default:
return signUpResponse{}, err
}
}
}