UpdateSubscription updates a subscription for an entities.User
(ctx context.Context, params *events.UserSubscriptionUpdatedPayload)
| 507 | |
| 508 | // UpdateSubscription updates a subscription for an entities.User |
| 509 | func (service *UserService) UpdateSubscription(ctx context.Context, params *events.UserSubscriptionUpdatedPayload) error { |
| 510 | ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) |
| 511 | defer span.End() |
| 512 | |
| 513 | user, err := service.repository.Load(ctx, params.UserID) |
| 514 | if err != nil { |
| 515 | msg := fmt.Sprintf("could not get [%T] with with ID [%s]", user, params.UserID) |
| 516 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 517 | } |
| 518 | |
| 519 | if params.SubscriptionStatus != "active" { |
| 520 | msg := fmt.Sprintf("subscription status is [%s] for [%T] with with ID [%s]", params.SubscriptionStatus, user, params.UserID) |
| 521 | ctxLogger.Info(msg) |
| 522 | return nil |
| 523 | } |
| 524 | |
| 525 | user.SubscriptionID = ¶ms.SubscriptionID |
| 526 | user.SubscriptionName = params.SubscriptionName |
| 527 | user.SubscriptionEndsAt = params.SubscriptionEndsAt |
| 528 | user.SubscriptionRenewsAt = ¶ms.SubscriptionRenewsAt |
| 529 | user.SubscriptionStatus = ¶ms.SubscriptionStatus |
| 530 | |
| 531 | if err = service.repository.Update(ctx, user); err != nil { |
| 532 | msg := fmt.Sprintf("could not update [%T] with with ID [%s] after subscription update", user, params.UserID) |
| 533 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 534 | } |
| 535 | |
| 536 | return nil |
| 537 | } |
| 538 | |
| 539 | // DeleteAuthUser deletes an entities.AuthContext from firebase |
| 540 | func (service *UserService) DeleteAuthUser(ctx context.Context, userID entities.UserID) error { |
no test coverage detected