AddPhone adds a phone to the phone API key
(ctx context.Context, userID entities.UserID, phoneAPIKeyID uuid.UUID, phoneID uuid.UUID)
| 170 | |
| 171 | // AddPhone adds a phone to the phone API key |
| 172 | func (service *PhoneAPIKeyService) AddPhone(ctx context.Context, userID entities.UserID, phoneAPIKeyID uuid.UUID, phoneID uuid.UUID) error { |
| 173 | ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) |
| 174 | defer span.End() |
| 175 | |
| 176 | phone, err := service.phoneRepository.LoadByID(ctx, userID, phoneID) |
| 177 | if err != nil { |
| 178 | msg := fmt.Sprintf("cannot load [%T] with ID [%s] for user [%s]", &entities.Phone{}, phoneID, userID.String()) |
| 179 | return stacktrace.Propagate(err, msg) |
| 180 | } |
| 181 | |
| 182 | phoneAPIKey, err := service.repository.Load(ctx, userID, phoneAPIKeyID) |
| 183 | if err != nil { |
| 184 | msg := fmt.Sprintf("cannot load [%T] with ID [%s] for user [%s]", &entities.PhoneAPIKey{}, phoneAPIKeyID, userID.String()) |
| 185 | return stacktrace.Propagate(err, msg) |
| 186 | } |
| 187 | |
| 188 | if err = service.repository.AddPhone(ctx, phoneAPIKey, phone); err != nil { |
| 189 | msg := fmt.Sprintf("cannot add [%T] with ID [%s] to phone API key with ID [%s] for user [%s]", phone, phone.ID, phoneAPIKey.ID, userID) |
| 190 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 191 | } |
| 192 | |
| 193 | ctxLogger.Info(fmt.Sprintf("added [%T] with ID [%s] to [%T] with ID [%s] for user ID [%s]", phone, phone.ID, phoneAPIKey, phoneAPIKeyID, userID)) |
| 194 | return nil |
| 195 | } |
| 196 | |
| 197 | func (service *PhoneAPIKeyService) generateRandomBytes(n int) ([]byte, error) { |
| 198 | b := make([]byte, n) |
nothing calls this directly
no test coverage detected