-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into revert-63-revert-56-update-expo-packages
- Loading branch information
Showing
93 changed files
with
5,246 additions
and
3,184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
backend/core/src/Core.Application/Commands/CustomerCommands/DeleteCustomerCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 Quantoz Technology B.V. and contributors. Licensed | ||
// under the Apache License, Version 2.0. See the NOTICE file at the root | ||
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
using Core.Domain.Repositories; | ||
using MediatR; | ||
|
||
namespace Core.Application.Commands.CustomerCommands | ||
{ | ||
public class DeleteCustomerCommand : IRequest | ||
{ | ||
public string CustomerCode { get; set; } | ||
|
||
public string IP { get; set; } | ||
|
||
public DeleteCustomerCommand(string customerCode, string iP) | ||
{ | ||
CustomerCode = customerCode; | ||
IP = iP; | ||
} | ||
} | ||
|
||
public class DeleteCustomerCommandHandler : IRequestHandler<DeleteCustomerCommand> | ||
{ | ||
private readonly ICustomerRepository _customerRepository; | ||
|
||
public DeleteCustomerCommandHandler( | ||
ICustomerRepository customerRepository) | ||
{ | ||
_customerRepository = customerRepository; | ||
} | ||
|
||
public async Task Handle(DeleteCustomerCommand request, CancellationToken cancellationToken) | ||
{ | ||
var customer = await _customerRepository.GetAsync(request.CustomerCode, cancellationToken); | ||
|
||
await _customerRepository.DeleteAsync(customer, request.IP); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
backend/core/src/Core.Application/Commands/CustomerCommands/OTPCodeByEmailCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2023 Quantoz Technology B.V. and contributors. Licensed | ||
// under the Apache License, Version 2.0. See the NOTICE file at the root | ||
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
using Core.Domain; | ||
using Core.Domain.Abstractions; | ||
using Core.Domain.Exceptions; | ||
using Core.Domain.Repositories; | ||
using MediatR; | ||
|
||
namespace Core.Application.Commands.CustomerCommands | ||
{ | ||
public class OTPCodeByEmailCommand : IRequest | ||
{ | ||
public string CustomerCode { get; set; } | ||
|
||
public string IP { get; set; } | ||
|
||
public OTPCodeByEmailCommand(string customerCode, string ip) | ||
{ | ||
CustomerCode = customerCode; | ||
IP = ip; | ||
} | ||
} | ||
|
||
public class OTPCodeByEmailCommandHandler : IRequestHandler<OTPCodeByEmailCommand> | ||
{ | ||
private readonly ICustomerRepository _customerRepository; | ||
private readonly ICustomerDeviceRepository _customerDeviceRepository; | ||
private readonly ICustomerOTPGenerator _otpGenerator; | ||
private readonly ISendGridMailService _sendGridMailService; | ||
private readonly IUnitOfWork _unitOfWork; | ||
|
||
public OTPCodeByEmailCommandHandler( | ||
ICustomerRepository customerRepository, | ||
ICustomerDeviceRepository customerDeviceRepository, | ||
ICustomerOTPGenerator otpGenerator, | ||
ISendGridMailService sendGridMailService, | ||
IUnitOfWork unitOfWork) | ||
{ | ||
_customerRepository = customerRepository; | ||
_customerDeviceRepository = customerDeviceRepository; | ||
_otpGenerator = otpGenerator; | ||
_sendGridMailService = sendGridMailService; | ||
_unitOfWork = unitOfWork; | ||
} | ||
|
||
public async Task Handle(OTPCodeByEmailCommand request, CancellationToken cancellationToken) | ||
{ | ||
var customer = await _customerRepository.GetAsync(request.CustomerCode, cancellationToken); | ||
|
||
if (customer == null) | ||
{ | ||
throw new CustomErrorsException(DomainErrorCode.CustomerNotFoundError.ToString(), request.CustomerCode, "Customer not found."); | ||
} | ||
|
||
if (customer.Status != CustomerStatus.ACTIVE.ToString()) | ||
{ | ||
throw new CustomErrorsException(DomainErrorCode.CustomerNotActiveError.ToString(), request.CustomerCode, "Customer is not ACTIVE."); | ||
} | ||
|
||
var customerDevice = await _customerDeviceRepository.GetAsync(request.CustomerCode, cancellationToken); | ||
|
||
// rare case of exception | ||
if (customerDevice == null || string.IsNullOrEmpty(customerDevice.OTPKey)) | ||
{ | ||
throw new CustomErrorsException(DomainErrorCode.CustomerNotFoundError.ToString(), request.CustomerCode, "Customer device key not found."); | ||
} | ||
|
||
// Generate OTPCode | ||
var otpCode = _otpGenerator.GenerateOTPCode(customerDevice.OTPKey); | ||
|
||
// Send OTPCode to customer email | ||
await _sendGridMailService.SendOTPCodeMailAsync(customer, otpCode); | ||
|
||
await _unitOfWork.SaveChangesAsync(cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.