added other types of qrcodes like phone, sms, email, wifi

This commit is contained in:
heyethereum
2024-07-18 00:47:01 +08:00
parent 3e0ad7db2d
commit 686c4f939e
35 changed files with 612 additions and 132 deletions

View File

@@ -0,0 +1,23 @@
package com.safeqr.app.qrcode.service;
import com.safeqr.app.qrcode.entity.EmailEntity;
import com.safeqr.app.qrcode.repository.EmailRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class EmailVerificationService {
private final EmailRepository emailRepository;
private static final Logger logger = LoggerFactory.getLogger(EmailVerificationService.class);
@Autowired
public EmailVerificationService(EmailRepository emailRepository) {
this.emailRepository = emailRepository;
}
public void insertDB(EmailEntity EmailEntity) {
emailRepository.save(EmailEntity);
}
}

View File

@@ -0,0 +1,23 @@
package com.safeqr.app.qrcode.service;
import com.safeqr.app.qrcode.entity.PhoneEntity;
import com.safeqr.app.qrcode.repository.PhoneRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PhoneVerificationService {
private final PhoneRepository phoneRepository;
private static final Logger logger = LoggerFactory.getLogger(PhoneVerificationService.class);
@Autowired
public PhoneVerificationService(PhoneRepository phoneRepository) {
this.phoneRepository = phoneRepository;
}
public void insertDB(PhoneEntity PhoneEntity) {
phoneRepository.save(PhoneEntity);
}
}

View File

@@ -28,24 +28,25 @@ public class QRCodeTypeService {
private static final Logger logger = LoggerFactory.getLogger(QRCodeTypeService.class);
private final QRCodeFactoryProvider qrCodeFactoryProvider;
private final QRCodeTypeRepository qrCodeTypeRepository;
private final ScanHistoryRepository scanHistoryRepository;
private final QRCodeRepository qrCodeRepository;
private final SafeBrowsingService safeBrowsingService;
@Autowired
public QRCodeTypeService(QRCodeFactoryProvider qrCodeFactoryProvider) {
public QRCodeTypeService(QRCodeFactoryProvider qrCodeFactoryProvider,
QRCodeTypeRepository qrCodeTypeRepository,
ScanHistoryRepository scanHistoryRepository,
QRCodeRepository qrCodeRepository,
SafeBrowsingService safeBrowsingService
) {
this.qrCodeFactoryProvider = qrCodeFactoryProvider;
this.qrCodeTypeRepository = qrCodeTypeRepository;
this.scanHistoryRepository = scanHistoryRepository;
this.qrCodeRepository = qrCodeRepository;
this.safeBrowsingService = safeBrowsingService;
}
@Autowired
private QRCodeTypeRepository qrCodeTypeRepository;
@Autowired
private ScanHistoryRepository scanHistoryRepository;
@Autowired
private QRCodeRepository qrCodeRepository;
@Autowired
private SafeBrowsingService safeBrowsingService;
private List<QRCodeTypeEntity> configs;
private QRCodeTypeEntity defaultQRCodeTypeEntity;
@@ -88,9 +89,9 @@ public class QRCodeTypeService {
.scanStatus(ScanHistoryEntity.ScanStatus.ACTIVE)
.build());
}
// Create the QR Code Instance based on the QR Code Type & insert into the respective table
QRCodeModel qrCodeModel = qrCodeFactoryProvider.createQRCodeInstance(scannedQR, qrType);
qrCodeModel.insertDB();
qrCodeModel.setDetails();
return BaseScanResponse.builder().qrcode(qrCodeModel).build();
}
@@ -101,29 +102,6 @@ public class QRCodeTypeService {
.orElse(defaultQRCodeTypeEntity);
}
// private BaseScanResponse insertIntoRespectiveTable(QRCodeEntity qrCodeEntity, QRCodeTypeEntity qrCodeTypeEntity) {
// String contents = qrCodeEntity.getContents();
// try {
// QRCodeURLEntity urlObj = urlVerificationService.breakdownURL(contents);
// List<String> redirectChain = urlVerificationService.countAndTrackRedirects(contents);
// urlObj.setQrCodeId(qrCodeEntity.getId());
// urlObj.setRedirect(redirectChain.size() - 1);
// urlObj.setRedirectChain(redirectChain);
//
// // Insert into URL table
// urlRepository.save(urlObj);
//
// return URLResponse.builder().scannedQRCode(qrCodeEntity).qrCode(qrCodeTypeEntity).details(urlObj).build();
// } catch (IOException | URISyntaxException e) {
// logger.error("Error: ", e);
// }
//
// return BaseScanResponse.builder()
// .scannedQRCode(qrCodeEntity)
// .qrCode(qrCodeTypeEntity)
// .build();
// }
public Mono<String> detectType(QRCodePayload payload) {
String data = payload.getData();

View File

@@ -0,0 +1,23 @@
package com.safeqr.app.qrcode.service;
import com.safeqr.app.qrcode.entity.SMSEntity;
import com.safeqr.app.qrcode.repository.SMSRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SMSVerificationService {
private final SMSRepository smsRepository;
private static final Logger logger = LoggerFactory.getLogger(SMSVerificationService.class);
@Autowired
public SMSVerificationService(SMSRepository smsRepository) {
this.smsRepository = smsRepository;
}
public void insertDB(SMSEntity SMSEntity) {
smsRepository.save(SMSEntity);
}
}

View File

@@ -1,10 +1,22 @@
package com.safeqr.app.qrcode.service;
import com.safeqr.app.qrcode.entity.TextEntity;
import com.safeqr.app.qrcode.repository.TextRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TextVerificationService {
private final TextRepository textRepository;
@Autowired
public TextVerificationService(TextRepository textRepository) {
this.textRepository = textRepository;
}
public void insertDB(TextEntity textEntity) {
textRepository.save(textEntity);
}
private static final Logger logger = LoggerFactory.getLogger(TextVerificationService.class);
}

View File

@@ -3,9 +3,11 @@ package com.safeqr.app.qrcode.service;
import com.safeqr.app.constants.CommonConstants;
import com.safeqr.app.qrcode.dto.QRCodePayload;
import com.safeqr.app.qrcode.dto.URLVerificationResponse;
import com.safeqr.app.qrcode.entity.QRCodeURLEntity;
import com.safeqr.app.qrcode.entity.URLEntity;
import com.safeqr.app.qrcode.repository.URLRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
@@ -18,12 +20,20 @@ import java.util.Map;
@Service
public class URLVerificationService {
private static final Logger logger = LoggerFactory.getLogger(URLVerificationService.class);
private final URLRepository urlRepository;
@Autowired
public URLVerificationService(URLRepository urlRepository) {
this.urlRepository = urlRepository;
}
public void insertDB(URLEntity urlEntity) {
urlRepository.save(urlEntity);
}
// Function to breakdown URL into subdomain, domain, topLevelDomain, query params, fragment
public QRCodeURLEntity breakdownURL(String urlString) throws MalformedURLException, URISyntaxException {
public URLEntity breakdownURL(String urlString) throws MalformedURLException, URISyntaxException {
URI uri = new URI(urlString);
URL url = uri.toURL();
QRCodeURLEntity urlObj = new QRCodeURLEntity();
URLEntity urlObj = new URLEntity();
String host = url.getHost();
// split host into subdomain, domain, topLevelDomain

View File

@@ -0,0 +1,23 @@
package com.safeqr.app.qrcode.service;
import com.safeqr.app.qrcode.entity.WifiEntity;
import com.safeqr.app.qrcode.repository.WifiRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class WifiVerificationService {
private final WifiRepository wifiRepository;
private static final Logger logger = LoggerFactory.getLogger(WifiVerificationService.class);
@Autowired
public WifiVerificationService(WifiRepository wifiRepository) {
this.wifiRepository = wifiRepository;
}
public void insertDB(WifiEntity WifiEntity) {
wifiRepository.save(WifiEntity);
}
}