Create a new entities.PhoneAPIKey
(ctx context.Context, authContext entities.AuthContext, name string)
| 65 | |
| 66 | // Create a new entities.PhoneAPIKey |
| 67 | func (service *PhoneAPIKeyService) Create(ctx context.Context, authContext entities.AuthContext, name string) (*entities.PhoneAPIKey, error) { |
| 68 | ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) |
| 69 | defer span.End() |
| 70 | |
| 71 | apiKey, err := service.generateAPIKey(64) |
| 72 | if err != nil { |
| 73 | return nil, stacktrace.Propagate(err, "cannot generate API key") |
| 74 | } |
| 75 | |
| 76 | phoneAPIKey := &entities.PhoneAPIKey{ |
| 77 | ID: uuid.New(), |
| 78 | Name: name, |
| 79 | UserID: authContext.ID, |
| 80 | UserEmail: authContext.Email, |
| 81 | PhoneNumbers: pq.StringArray{}, |
| 82 | PhoneIDs: pq.StringArray{}, |
| 83 | APIKey: "pk_" + apiKey, |
| 84 | CreatedAt: time.Now().UTC(), |
| 85 | UpdatedAt: time.Now().UTC(), |
| 86 | } |
| 87 | |
| 88 | if err = service.repository.Create(ctx, phoneAPIKey); err != nil { |
| 89 | msg := fmt.Sprintf("cannot create PhoneAPIKey for user [%s]", authContext.ID) |
| 90 | return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 91 | } |
| 92 | |
| 93 | ctxLogger.Info(fmt.Sprintf("created [%T] with ID [%s] for user ID [%s]", phoneAPIKey, phoneAPIKey.ID, authContext.ID)) |
| 94 | return phoneAPIKey, nil |
| 95 | } |
| 96 | |
| 97 | // Delete an entities.PhoneAPIKey |
| 98 | func (service *PhoneAPIKeyService) Delete(ctx context.Context, userID entities.UserID, phoneAPIKeyID uuid.UUID) error { |
nothing calls this directly
no test coverage detected