Skip to content

Commit 7c60f0a

Browse files
committed
refactor(ht_email_repository): Improve OTP email sending method
- Improved method documentation. - Added templateId parameter. - Used templateData for OTP code. - Simplified error handling. - Improved code clarity.
1 parent 4f2067a commit 7c60f0a

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/src/ht_email_repository.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,33 @@ class HtEmailRepository {
1717

1818
final HtEmailClient _emailClient;
1919

20-
/// Sends a One-Time Password (OTP) email via the email client.
20+
/// Sends a One-Time Password (OTP) email by calling the underlying client.
2121
///
22-
/// Delegates the call to the injected [HtEmailClient].
22+
/// This method abstracts the specific details of sending an OTP email. It
23+
/// constructs the required `templateData` and calls the generic
24+
/// `sendTransactionalEmail` method on the injected [HtEmailClient].
2325
///
24-
/// Throws [HtHttpException] subtypes on failure, as propagated
25-
/// from the client.
26+
/// - [recipientEmail]: The email address of the recipient.
27+
/// - [otpCode]: The One-Time Password to be sent.
28+
/// - [templateId]: The ID of the transactional email template to use.
29+
///
30+
/// Throws [HtHttpException] subtypes on failure, as propagated from the
31+
/// client.
2632
Future<void> sendOtpEmail({
2733
required String recipientEmail,
2834
required String otpCode,
35+
required String templateId,
2936
}) async {
3037
try {
31-
await _emailClient.sendOtpEmail(
38+
await _emailClient.sendTransactionalEmail(
3239
recipientEmail: recipientEmail,
33-
otpCode: otpCode,
40+
templateId: templateId,
41+
templateData: {
42+
'otp_code': otpCode,
43+
},
3444
);
3545
} on HtHttpException {
3646
rethrow; // Propagate client-level exceptions
3747
}
38-
// Catch-all for unexpected errors is generally avoided here,
39-
// relying on the client's defined exceptions.
4048
}
4149
}

0 commit comments

Comments
 (0)