merchant onboarding process completed
This commit is contained in:
71
Singer_Hexdive/Services/FunctionHandlers/MerchantManager.cs
Normal file
71
Singer_Hexdive/Services/FunctionHandlers/MerchantManager.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Singer_Hexdive.Exceptions;
|
||||
using Singer_Hexdive.Interfaces.ServiceInterfaces;
|
||||
using Singer_Hexdive.Models.IOs;
|
||||
|
||||
namespace Singer_Hexdive.Services.FunctionHandlers
|
||||
{
|
||||
public class MerchantManager
|
||||
{
|
||||
private readonly Dictionary<string, Func<object, Task<object>>> _functionHandler;
|
||||
|
||||
public MerchantManager(BaseMerchantService merchantService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{"PostM_PersonalDetails", merchantService.PostM_PersonalDetails }
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<object>> Execute(ApiRequest request)
|
||||
{
|
||||
|
||||
|
||||
if (!_functionHandler.TryGetValue(request.FunctionName, out var handler))
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = $"Function '{request.FunctionName}' not found.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
try
|
||||
{
|
||||
var results = await handler(request.Payload);
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 200,
|
||||
Message = "success",
|
||||
Data = results
|
||||
};
|
||||
}
|
||||
catch (NotfoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user