|
| 1 | +import 'package:ht_email_client/ht_email_client.dart'; |
| 2 | +import 'package:ht_shared/ht_shared.dart'; // For HtHttpException |
| 3 | + |
1 | 4 | /// {@template ht_email_repository}
|
2 |
| -/// A Very Good Project created by Very Good CLI. |
| 5 | +/// A repository that handles email sending operations. |
| 6 | +/// |
| 7 | +/// This repository interacts with an underlying [HtEmailClient] |
| 8 | +/// to send emails, such as One-Time Passwords (OTPs). |
3 | 9 | /// {@endtemplate}
|
4 | 10 | class HtEmailRepository {
|
5 | 11 | /// {@macro ht_email_repository}
|
6 |
| - const HtEmailRepository(); |
| 12 | + /// |
| 13 | + /// Requires an instance of [HtEmailClient] to handle the actual |
| 14 | + /// email sending operations. |
| 15 | + const HtEmailRepository({ |
| 16 | + required HtEmailClient emailClient, |
| 17 | + }) : _emailClient = emailClient; |
| 18 | + |
| 19 | + final HtEmailClient _emailClient; |
| 20 | + |
| 21 | + /// Sends a One-Time Password (OTP) email via the email client. |
| 22 | + /// |
| 23 | + /// Delegates the call to the injected [HtEmailClient]. |
| 24 | + /// |
| 25 | + /// Throws [HtHttpException] subtypes on failure, as propagated |
| 26 | + /// from the client. |
| 27 | + Future<void> sendOtpEmail({ |
| 28 | + required String recipientEmail, |
| 29 | + required String otpCode, |
| 30 | + }) async { |
| 31 | + try { |
| 32 | + await _emailClient.sendOtpEmail( |
| 33 | + recipientEmail: recipientEmail, |
| 34 | + otpCode: otpCode, |
| 35 | + ); |
| 36 | + } on HtHttpException { |
| 37 | + rethrow; // Propagate client-level exceptions |
| 38 | + } |
| 39 | + // Catch-all for unexpected errors is generally avoided here, |
| 40 | + // relying on the client's defined exceptions. |
| 41 | + } |
7 | 42 | }
|
0 commit comments