first commit
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.Auth;
|
||||
using Fitness_core_BE.DTOs.Auth;
|
||||
using Fitness_core_BE.Exceptions;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class AuthFuncHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<AuthResponse>>> _functionHandler;
|
||||
|
||||
public AuthFuncHandler(IAuthService authService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{"SendOtp", authService.SendOtp },
|
||||
{"VerifyOTP", authService.VerifyOTP },
|
||||
{"IsAvailable", authService.IsAvailable },
|
||||
{"RegisterUser", authService.RegisterUser },
|
||||
{"UpdateUser", authService.UpdateUser },
|
||||
{"GetUserDetails", authService.GetUserDetails },
|
||||
{"LoginUser", authService.LoginUser },
|
||||
{"RefreshToken", authService.RefreshToken },
|
||||
{"VerifyOtpForLogin", authService.VerifyOtpForLogin },
|
||||
{"forgotPassword", authService.ForgotPassword },
|
||||
{"resetPassword", authService.ResetPassword },
|
||||
{"resetPasswordWithToken", authService.ResetPasswordWithToken },
|
||||
{"LogOut", authService.LogOut }
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<object>> Execute(ApiRequest request, HttpContext httpContext)
|
||||
{
|
||||
if (!_functionHandler.TryGetValue(request.FunctionName, out var handler))
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = $"Function '{request.FunctionName}' not found.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
try
|
||||
{
|
||||
var authResponse = await handler(request.Payload, httpContext);
|
||||
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = authResponse.StatusCode,
|
||||
Message = authResponse.Message,
|
||||
Data = authResponse.Data
|
||||
};
|
||||
}
|
||||
catch (UnauthorizedException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 401,
|
||||
Message = ex.Message,
|
||||
};
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
};
|
||||
}
|
||||
catch (BadRequestException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = ex.Message,
|
||||
};
|
||||
}
|
||||
catch (ForbiddenException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 403,
|
||||
Message = ex.Message,
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user