105 lines
4.3 KiB
C#
105 lines
4.3 KiB
C#
using Fitness_core_BE.Models.IOs;
|
|
using Fitness_core_BE.Services.CustomerService;
|
|
using Fitness_core_BE.Interfaces.Services;
|
|
|
|
namespace Fitness_core_BE.Services.FunctionHandler
|
|
{
|
|
public class CustomerFunctionHandler
|
|
{
|
|
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
|
|
|
public CustomerFunctionHandler(ICustomerService customerService)
|
|
{
|
|
_functionHandler = new()
|
|
{
|
|
{ "CreateCustomer", customerService.CreateCustomer },
|
|
{ "DeleteCustomer", customerService.DeleteCustomer },
|
|
{ "UpdateCustomer", customerService.UpdateCustomer },
|
|
{ "GetCustomerMealPlan", customerService.GetCustomerMealPlan },
|
|
{ "GetCustomerMealPlanById", customerService.GetCustomerMealPlanById },
|
|
{ "GetCustomerWorkOutPlan", customerService.GetCustomerWorkOutPlan },
|
|
{ "GetCustomerWorkoutPlanById", customerService.GetCustomerWorkoutPlanById },
|
|
{ "FollowMealPlan", customerService.FollowMealPlan },
|
|
{ "GetFollowedMealPlans", customerService.GetFollowedMealPlans },
|
|
{ "GetFollowedWorkoutPlans", customerService.GetFollowedWorkoutPlans },
|
|
{ "FollowWorkOutPlan", customerService.FollowWorkOutPlan },
|
|
{ "GetClientDataById", customerService.GetClientDataById },
|
|
{ "CreateCusHealthRec", customerService.CreateCusHealthRec },
|
|
{ "CreateCusProgressRec", customerService.CreateCusProgressRec },
|
|
{ "UpdateCusHealthRec", customerService.UpdateCusHealthRec },
|
|
{ "UpdateCusProgressRec", customerService.UpdateCusProgressRec },
|
|
{ "UpdateCustomerTargetNutritions", customerService.UpdateCustomerTargetNutritions },
|
|
{ "GetClientGyms", customerService.GetClientGyms },
|
|
{ "GetCustomerProgress", customerService.GetCustomerProgress },
|
|
{ "UpdateWeeklyProgress", customerService.UpdateWeeklyProgress },
|
|
{ "GetWeeklyProgressForCustomer", customerService.GetWeeklyProgressForCustomer },
|
|
{ "GetCusBasicDetails", customerService.GetCusBasicDetails },
|
|
{ "GetCusHealthDetails", customerService.GetCusHealthDetails },
|
|
{ "GetCusProgressDetails", customerService.GetCusProgressDetails },
|
|
{"CreateFeed", customerService.CreateFeed },
|
|
{"GetOwnCards", customerService.GetCardDetails }
|
|
|
|
};
|
|
}
|
|
|
|
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 results = await handler(request.Payload, httpContext);
|
|
return new ApiResponse<object>
|
|
{
|
|
StatusCode = 200,
|
|
Message = "success",
|
|
Data = results
|
|
};
|
|
}
|
|
catch (UnauthorizedAccessException ex)
|
|
{
|
|
return new ApiResponse<object>
|
|
{
|
|
StatusCode = 401,
|
|
Message = ex.Message,
|
|
Data = null!
|
|
};
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return new ApiResponse<object>
|
|
{
|
|
StatusCode = 400,
|
|
Message = ex.Message,
|
|
Data = null!
|
|
};
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
return new ApiResponse<object>
|
|
{
|
|
StatusCode = 400,
|
|
Message = ex.Message,
|
|
Data = null!
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ApiResponse<object>
|
|
{
|
|
StatusCode = 500,
|
|
Message = $"An error occurred: {ex.Message}",
|
|
Data = null!
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|