Skip to content

Commit 4af597c

Browse files
committed
feat(ht_email_repository): implement sendOtpEmail functionality
- Add HtEmailClient dependency for email sending operations - Implement sendOtpEmail method to delegate OTP email sending - Handle HtHttpException subtypes for error propagation - Update class documentation to reflect new repository purpose
1 parent 72cf0b4 commit 4af597c

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

lib/src/ht_email_repository.dart

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1+
import 'package:ht_email_client/ht_email_client.dart';
2+
import 'package:ht_shared/ht_shared.dart'; // For HtHttpException
3+
14
/// {@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).
39
/// {@endtemplate}
410
class HtEmailRepository {
511
/// {@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+
}
742
}

0 commit comments

Comments
 (0)