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
| package profile
type Service struct { Mongo *dao.Mongo Logger *zap.Logger }
func (s *Service) GetProfile(c context.Context, req *rentalpb.GetProfileRequest) (*rentalpb.Profile, error) { aid, err := auth.AccountIDFromContext(c) if err != nil { return nil, err } p, err := s.Mongo.GetProfile(c, aid) if err != nil { if err == mongo.ErrNoDocuments { return &rentalpb.Profile{}, nil } s.Logger.Error("cannot get Profile", zap.Error(err)) return nil, status.Error(codes.Internal, "") } return p, nil }
func (s *Service) SubmitProfile(c context.Context, req *rentalpb.Identity) (*rentalpb.Profile, error) { aid, err := auth.AccountIDFromContext(c) if err != nil { return nil, err } p := &rentalpb.Profile{ Identity: req, IdentityStatus: rentalpb.IdentityStatus_PENDING, } err = s.Mongo.UpdateProfile(c, aid, rentalpb.IdentityStatus_UNSUBMITTED, p) if err != nil { if err == mongo.ErrNoDocuments { return &rentalpb.Profile{}, nil } s.Logger.Error("cannot get Profile", zap.Error(err)) return nil, status.Error(codes.Internal, "") } return p, nil } func (s *Service) ClearProfile(c context.Context, req *rentalpb.ClearProfileRequest) (*rentalpb.Profile, error) { aid, err := auth.AccountIDFromContext(c) if err != nil { return nil, err } p := &rentalpb.Profile{} err = s.Mongo.UpdateProfile(c, aid, rentalpb.IdentityStatus_VERIFIED, p) if err != nil { if err == mongo.ErrNoDocuments { return &rentalpb.Profile{}, nil } s.Logger.Error("cannot get Profile", zap.Error(err)) return nil, status.Error(codes.Internal, "") } return p, nil }
|