write sms type to db
This commit is contained in:
@@ -16,4 +16,8 @@ public class GlobalExceptionHandler {
|
||||
public ResponseEntity<ErrorResponse> handleResourceAlreadyExistsException(ResourceAlreadyExists e) {
|
||||
return new ResponseEntity<>(new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value()), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@ExceptionHandler(InvalidFormatExceptions.class)
|
||||
public ResponseEntity<ErrorResponse> handleInvalidFormatException(InvalidFormatExceptions e) {
|
||||
return new ResponseEntity<>(new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value()), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.safeqr.app.exceptions;
|
||||
|
||||
public class InvalidFormatExceptions extends RuntimeException {
|
||||
public InvalidFormatExceptions(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ public final class SMSModel extends QRCodeModel<SMSEntity> {
|
||||
@Override
|
||||
public void setDetails() {
|
||||
details = SMSEntity.builder().qrCodeId(data.getId()).build();
|
||||
|
||||
smsVerificationService.parseSMSString(details, data.getContents());
|
||||
// Insert into sms table
|
||||
smsVerificationService.insertDB(details);
|
||||
}
|
||||
|
||||
@@ -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>");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.safeqr.app.user.service;
|
||||
|
||||
import com.safeqr.app.exceptions.ResourceAlreadyExists;
|
||||
import com.safeqr.app.exceptions.ResourceNotFoundExceptions;
|
||||
import com.safeqr.app.qrcode.entity.ScanBookmarkEntity;
|
||||
|
||||
import com.safeqr.app.qrcode.entity.ScanHistoryEntity;
|
||||
import com.safeqr.app.qrcode.repository.ScanBookmarkRepository;
|
||||
import com.safeqr.app.qrcode.repository.ScanHistoryRepository;
|
||||
@@ -14,7 +14,7 @@ import com.safeqr.app.user.repository.UserRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user