/
unsubscribe.go
53 lines (38 loc) · 1.41 KB
/
unsubscribe.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
package main
import (
"context"
"errors"
"github.com/gogo/protobuf/types"
"github.com/gogo/status"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"github.com/elojah/game_02/pkg/account"
"github.com/elojah/game_02/pkg/account/dto"
gerrors "github.com/elojah/game_02/pkg/errors"
)
func (h handler) Unsubscribe(ctx context.Context, request *dto.Auth) (*types.Empty, error) {
logger := log.With().Str("method", "unsubscribe").Logger()
// #Request processing
if request == nil {
err := gerrors.ErrNullRequest{}
logger.Error().Err(err).Msg("null request")
return &types.Empty{}, status.New(codes.InvalidArgument, err.Error()).Err()
}
// #Check credentials
if _, err := h.account.Authorize(ctx, request.ID, request.Token); err != nil {
if errors.As(err, &gerrors.ErrInvalidCredentials{}) {
logger.Error().Err(err).Msg("invalid credentials")
return &types.Empty{}, status.New(codes.Unauthenticated, err.Error()).Err()
}
logger.Error().Err(err).Msg("failed to authenticate")
return &types.Empty{}, status.New(codes.Internal, err.Error()).Err()
}
// #Delete player and all data account associated...
// #Delete account
if err := h.account.Delete(ctx, account.Filter{ID: request.ID}); err != nil {
logger.Error().Err(err).Msg("failed to delete account")
return &types.Empty{}, status.New(codes.Internal, err.Error()).Err()
}
logger.Info().Msg("success")
return &types.Empty{}, nil
}