write sms type to db

This commit is contained in:
ltiongku
2024-08-14 19:44:18 +08:00
parent 334b3867ec
commit 9adb53e7ab
5 changed files with 37 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
package com.safeqr.app.qrcode.service;
import com.safeqr.app.exceptions.InvalidFormatExceptions;
import com.safeqr.app.exceptions.ResourceNotFoundExceptions;
import com.safeqr.app.qrcode.entity.SMSEntity;
import com.safeqr.app.qrcode.repository.SMSRepository;
@@ -29,4 +30,25 @@ public class SMSVerificationService {
smsRepository.save(smsEntity);
}
public void parseSMSString(SMSEntity smsEntity, String smsto) throws IllegalArgumentException{
// Remove the "SMSTO:" prefix
String data = smsto.substring(6);
// Split the data into phone number and message
String[] parts = data.split(":", 2);
// If both phone number and message are available
if (parts.length == 2) {
String phone = parts[0];
String message = parts[1];
// Populate the SMSEntity object
smsEntity.setPhone(phone);
smsEntity.setMessage(message);
} else {
// Handle the case where the format is invalid
throw new InvalidFormatExceptions("Invalid SMSTO format. Expected format: SMSTO:<phone>:<message>");
}
}
}