ExpireSubscription finishes a subscription for an entities.User
(ctx context.Context, params *events.UserSubscriptionExpiredPayload)
| 482 | |
| 483 | // ExpireSubscription finishes a subscription for an entities.User |
| 484 | func (service *UserService) ExpireSubscription(ctx context.Context, params *events.UserSubscriptionExpiredPayload) error { |
| 485 | ctx, span := service.tracer.Start(ctx) |
| 486 | defer span.End() |
| 487 | |
| 488 | user, err := service.repository.Load(ctx, params.UserID) |
| 489 | if err != nil { |
| 490 | msg := fmt.Sprintf("could not get [%T] with with ID [%s]", user, params.UserID) |
| 491 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 492 | } |
| 493 | |
| 494 | user.SubscriptionID = nil |
| 495 | user.SubscriptionName = entities.SubscriptionNameFree |
| 496 | user.SubscriptionRenewsAt = nil |
| 497 | user.SubscriptionStatus = nil |
| 498 | user.SubscriptionEndsAt = nil |
| 499 | |
| 500 | if err = service.repository.Update(ctx, user); err != nil { |
| 501 | msg := fmt.Sprintf("could not update [%T] with with ID [%s] after expired subscription update", user, params.UserID) |
| 502 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 503 | } |
| 504 | |
| 505 | return nil |
| 506 | } |
| 507 | |
| 508 | // UpdateSubscription updates a subscription for an entities.User |
| 509 | func (service *UserService) UpdateSubscription(ctx context.Context, params *events.UserSubscriptionUpdatedPayload) error { |
no test coverage detected