Added new end point, edited getEmails to be Async all and return 202 status code

This commit is contained in:
heyethereum
2024-08-04 19:37:16 +08:00
parent 0fde70a4b6
commit 76036a2d91
17 changed files with 593 additions and 27 deletions

View File

@@ -1,7 +1,6 @@
package com.safeqr.app.qrcode.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.safeqr.app.qrcode.entity.EmailEntity;
import com.safeqr.app.qrcode.entity.QRCodeEntity;
import com.safeqr.app.qrcode.entity.URLEntity;
import com.safeqr.app.qrcode.service.URLVerificationService;
@@ -12,8 +11,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.net.URISyntaxException;
@EqualsAndHashCode(callSuper = true)
@Data
public final class URLModel extends QRCodeModel<URLEntity> {

View File

@@ -68,13 +68,18 @@ public class QRCodeTypeService {
}
// Get scanned qrcode details
public BaseScanResponse getScannedQRCodeDetails(UUID qrCodeId){
return BaseScanResponse.builder().qrcode(getScannedQRCodeDetailsInModel(qrCodeId)).build();
}
public QRCodeModel<?> getScannedQRCodeDetailsInModel(UUID qrCodeId){
// Find scanned qr code in qr code table
QRCodeEntity qrCodeEntity = qrCodeRepository.findById(qrCodeId)
.orElseThrow(() -> new ResourceNotFoundExceptions("QR Code not found with id: " + qrCodeId));
logger.info("qrCodeEntity: {}", qrCodeEntity);
QRCodeModel<?> qrCodeModel = qrCodeFactoryProvider.createQRCodeInstance(qrCodeEntity);
logger.info("Retrieved details: {}", qrCodeModel.getDetails());
return BaseScanResponse.builder().qrcode(qrCodeModel).build();
return qrCodeModel;
}
// Process Scanned QR Code
@@ -109,6 +114,28 @@ public class QRCodeTypeService {
return BaseScanResponse.builder().qrcode(qrCodeModel).build();
}
@Transactional
public QRCodeModel<?> scanGmailDecodedContents(String userId, String data) {
logger.info("Scan Gmail content: userId={}, data={}", userId, data);
// Get the QR Code Type
QRCodeTypeEntity qrType = getQRCodeType(data);
// Insert the QR Code into main qrcode table
QRCodeEntity scannedQR = qrCodeRepository.save(QRCodeEntity.builder()
.userId(userId)
.contents(data)
.info(qrType)
.createdAt(LocalDateTime.now())
.build());
// Create the QR Code Instance based on the QR Code Type & insert into the respective table
QRCodeModel<?> qrCodeModel = qrCodeFactoryProvider.createQRCodeInstance(scannedQR);
qrCodeModel.setDetails();
return qrCodeModel;
}
// Returns Default type as text if it does not fit into any of the category
private QRCodeTypeEntity getQRCodeType(String data) {
return configs.stream()

View File

@@ -30,8 +30,9 @@ public class URLVerificationService {
public URLEntity getURLEntityByQRCodeId(UUID qrCodeId) {
logger.info("qrCodeId retrieving: {}", qrCodeId);
return urlRepository.findByQrCodeId(qrCodeId)
.orElseThrow(() -> new ResourceNotFoundExceptions("URL not found for QR Code id: " + qrCodeId));
// return urlRepository.findByQrCodeId(qrCodeId)
// .orElseThrow(() -> new ResourceNotFoundExceptions("URL not found for QR Code id: " + qrCodeId));
return urlRepository.findByQrCodeId(qrCodeId).orElse(null);
}
public void insertDB(URLEntity urlEntity) {