first commit
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
using Fitness_core_BE.Exceptions;
|
||||
using Fitness_core_BE.Helpers;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class AccessDeviceFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public AccessDeviceFunctionHandler(IAccessDeviceService accessDeviceService)
|
||||
{
|
||||
// Admin-auth actions only. The cloud no longer talks to devices directly:
|
||||
// - AddDevice / RemoveDevice / GeneratePairingCode are pure DB operations.
|
||||
// - AddUser / WhiteListMember / BlackListMember do their local DB work and
|
||||
// ENQUEUE a DeviceCommand for the on-prem agent to execute.
|
||||
// Device communication (attendance pull, command execution, enrollment)
|
||||
// is handled by the agent against the AgentApiKey-protected endpoints in AgentController.
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "AddDevice", (payload, _) => accessDeviceService.AddDevice(payload) },
|
||||
{ "RemoveDevice", (payload, _) => accessDeviceService.RemoveDevice(payload) },
|
||||
{ "GeneratePairingCode", (payload, _) => accessDeviceService.GeneratePairingCode(payload) },
|
||||
{ "AddUser", AddUser },
|
||||
{ "WhiteListMember", WhiteListMember },
|
||||
{ "BlackListMember", BlackListMember }
|
||||
};
|
||||
|
||||
Task<object> AddUser(object payload, HttpContext _)
|
||||
{
|
||||
var data = DeserializePayload.Deserialize(payload);
|
||||
var customerAccess = new CustomerAccess
|
||||
{
|
||||
Name = DataExtractor.GetRequiredString(data, "Name"),
|
||||
FKDeviceId = DataExtractor.GetRequiredGuid(data, "FKDeviceId"),
|
||||
FKCustomerId = DataExtractor.GetRequiredGuid(data, "FKCustomerId")
|
||||
};
|
||||
|
||||
return accessDeviceService.AddUser(customerAccess);
|
||||
}
|
||||
|
||||
Task<object> WhiteListMember(object payload, HttpContext _)
|
||||
{
|
||||
var data = DeserializePayload.Deserialize(payload);
|
||||
var customerId = DataExtractor.GetRequiredGuid(data, "customerId");
|
||||
return accessDeviceService.WhiteListMember(customerId).ContinueWith(t => (object)t.Result);
|
||||
}
|
||||
|
||||
Task<object> BlackListMember(object payload, HttpContext _)
|
||||
{
|
||||
var data = DeserializePayload.Deserialize(payload);
|
||||
var customerId = DataExtractor.GetRequiredGuid(data, "customerId");
|
||||
return accessDeviceService.BlackListMember(customerId).ContinueWith(t => (object)t.Result);
|
||||
}
|
||||
}
|
||||
|
||||
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 (UnauthorizedException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 401,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (BadRequestException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (ForbiddenException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 403,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Fitness_core_BE.Services.ActivityLog;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class ActivityLogFuncHandler
|
||||
{
|
||||
private readonly IActivityLogService _activityLogService;
|
||||
|
||||
public ActivityLogFuncHandler(IActivityLogService activityLogService)
|
||||
{
|
||||
_activityLogService = activityLogService;
|
||||
}
|
||||
|
||||
public async Task<object> ExecuteAsync(string functionName, object payload, HttpContext httpContext)
|
||||
{
|
||||
return functionName switch
|
||||
{
|
||||
"LogActivity" => await _activityLogService.LogActivity(payload, httpContext),
|
||||
"GetActivityLogs" => await _activityLogService.GetActivityLogs(payload, httpContext),
|
||||
_ => throw new NotImplementedException($"Function '{functionName}' is not implemented.")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using Fitness_core_BE.Exceptions;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class AttendanceFunctionHandler
|
||||
{
|
||||
private readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public AttendanceFunctionHandler(IAttendanceService attendanceService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetAllAttendanceRecords", attendanceService.GetAllAttendanceRecords },
|
||||
{ "GetAttendanceCounts", attendanceService.GetAttendanceCounts },
|
||||
{ "GetTodayAttendance", attendanceService.GetTodayAttendance }
|
||||
};
|
||||
}
|
||||
|
||||
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 (UnauthorizedException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 401,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (BadRequestException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (ForbiddenException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 403,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class ChatFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, Task<object>>> _functionHandler;
|
||||
|
||||
public ChatFunctionHandler(IChatService chatService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetOrCreateChatAsync", chatService.GetOrCreateChatAsync },
|
||||
{ "GetClientById", chatService.SendMessageAsync },
|
||||
{ "RegisterClient", chatService.GetMessagesAsync }
|
||||
};
|
||||
}
|
||||
|
||||
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 (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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services;
|
||||
using Fitness_core_BE.Exceptions;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class ClientFuncHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public ClientFuncHandler(IClientService clientService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetClientList", clientService.GetClientList },
|
||||
{ "GetClientById", clientService.GetClientById },
|
||||
{ "GetCustomerDetailsById", clientService.GetCustomerDetailsById },
|
||||
{ "CreateCustomerWithPlans", clientService.CreateCustomerWithPlans },
|
||||
{ "UpdateCustomerByClient", clientService.UpdateCustomerByClient },
|
||||
{"GetCustomersByClientId", clientService.GetCustomersByClientId},
|
||||
{"GetCustomerPlansByClientId", clientService.GetCustomerPlansByClientId},
|
||||
{"RegisterClient", clientService.RegisterClient},
|
||||
{ "GetPackageList", clientService.GetPackageList },
|
||||
{"GetAllCustomers", clientService.GetAllCustomers },
|
||||
{"DeleteCustomerByClient", clientService.DeleteCustomerByClient },
|
||||
{"ClientLogOut", clientService.ClientLogOut },
|
||||
{"GetAllCustomerPlans", clientService.GetAllCustomerPlans },
|
||||
{"GetMealPlansByClientId", clientService.GetMealPlansByClientId },
|
||||
{"GetWorkoutPlansByClientId", clientService.GetWorkoutPlansByClientId },
|
||||
{"GetMealPlanById", clientService.GetMealPlanById },
|
||||
{"GetWorkoutPlanById", clientService.GetWorkoutPlanById },
|
||||
{"GetCustomerPlanById", clientService.GetCustomerPlanById },
|
||||
{"GetOwnCards", clientService.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 (UnauthorizedException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 401,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (BadRequestException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (ForbiddenException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 403,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.ClientInvoice;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class ClientInvoiceFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public ClientInvoiceFunctionHandler(IClientInvoiceService clientInvoiceService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "CreateClientInvoiceFromSubscription", clientInvoiceService.CreateClientInvoiceFromSubscription },
|
||||
{ "GetClientInvoiceById", clientInvoiceService.GetClientInvoiceById },
|
||||
{ "GetClientInvoicesByClientId", clientInvoiceService.GetClientInvoicesByClientId },
|
||||
{ "GetClientInvoicesByUserId", clientInvoiceService.GetClientInvoicesByUserId },
|
||||
{ "UpdateClientInvoiceStatus", clientInvoiceService.UpdateClientInvoiceStatus },
|
||||
{ "CalculateClientInvoiceTotal", clientInvoiceService.CalculateClientInvoiceTotal }
|
||||
};
|
||||
}
|
||||
|
||||
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!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Exceptions;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class ClientStatFuncHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public ClientStatFuncHandler(IClientStatService clientStatService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetTotalCustomerCount", clientStatService.GetTotalCustomerCount },
|
||||
{ "GetMonthlyCustomerCount", clientStatService.GetMonthlyCustomerCount },
|
||||
{ "GetTotalWorkoutPlanCount", clientStatService.GetTotalWorkoutPlanCount },
|
||||
{ "GetTotalMealPlanCount", clientStatService.GetTotalMealPlanCount },
|
||||
{ "GetLastMonthCustomerCount", clientStatService.GetLastMonthCustomerCount },
|
||||
{ "GetLastFiveAttendances", clientStatService.GetLastFiveAttendances },
|
||||
{ "GetLastFivePayments", clientStatService.GetLastFivePayments },
|
||||
{ "GetLastMonthRevenue", clientStatService.GetLastMonthRevenue },
|
||||
{ "GetMonthlyRevenueVariation", (payload, ctx) => clientStatService.GetMonthlyRevenueVariation(payload, ctx) },
|
||||
{ "GetTotalRevenue", clientStatService.GetTotalRevenue },
|
||||
{ "GetClientStatSummary", (payload, ctx) => clientStatService.GetClientStatSummary(payload, ctx) }
|
||||
};
|
||||
}
|
||||
|
||||
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 (UnauthorizedException ex)
|
||||
{
|
||||
return new ApiResponse<object> { StatusCode = 401, Message = ex.Message, Data = null };
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object> { StatusCode = 404, Message = ex.Message, Data = null };
|
||||
}
|
||||
catch (BadRequestException ex)
|
||||
{
|
||||
return new ApiResponse<object> { StatusCode = 400, Message = ex.Message, Data = null };
|
||||
}
|
||||
catch (ForbiddenException ex)
|
||||
{
|
||||
return new ApiResponse<object> { StatusCode = 403, Message = ex.Message, Data = null };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.CustomerInvoice;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class CustomerInvoiceFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public CustomerInvoiceFunctionHandler(ICustomerInvoiceService customerInvoiceService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "CreateCustomerInvoiceFromSubscription", customerInvoiceService.CreateCustomerInvoiceFromSubscription },
|
||||
{ "GetCustomerInvoiceById", customerInvoiceService.GetCustomerInvoiceById },
|
||||
{ "GetCustomerInvoicesByCustomerId", customerInvoiceService.GetCustomerInvoicesByCustomerId },
|
||||
{ "GetCustomerInvoicesByClientId", customerInvoiceService.GetCustomerInvoicesByClientId },
|
||||
{ "UpdateCustomerInvoiceStatus", customerInvoiceService.UpdateCustomerInvoiceStatus },
|
||||
{ "CalculateCustomerInvoiceTotal", customerInvoiceService.CalculateCustomerInvoiceTotal }
|
||||
};
|
||||
}
|
||||
|
||||
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!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.CustomerPlanService;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class CustomerPlanFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public CustomerPlanFunctionHandler(ICustomerPlanService customerPlanService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetAllCustomerPlans", customerPlanService.GetAllCustomerPlans },
|
||||
{ "GetCustomerPlanById", customerPlanService.GetCustomerPlanById },
|
||||
{ "CreateCustomerPlan", customerPlanService.CreateCustomerPlan },
|
||||
{ "UpdateCustomerPlan", customerPlanService.UpdateCustomerPlan },
|
||||
{ "SetCustomerPlanStatus", customerPlanService.SetCustomerPlanStatus },
|
||||
{ "DeleteCustomerPlan", customerPlanService.DeleteCustomerPlan }
|
||||
};
|
||||
}
|
||||
|
||||
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!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.CustomerSubscription;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class CustomerSubscriptionFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public CustomerSubscriptionFunctionHandler(ICustomerSubscriptionService customerSubscriptionService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "CreateCustomerSubscription", customerSubscriptionService.CreateCustomerSubscription },
|
||||
{ "GetCustomerSubscriptionById", customerSubscriptionService.GetCustomerSubscriptionById },
|
||||
{ "GetCustomerSubscriptionsByCustomerId", customerSubscriptionService.GetCustomerSubscriptionsByCustomerId },
|
||||
{ "GetActiveSubscriptionByCustomerId", customerSubscriptionService.GetActiveSubscriptionByCustomerId }
|
||||
};
|
||||
}
|
||||
|
||||
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!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.Document;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class DocumentFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public DocumentFunctionHandler(IDocumentService documentService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "UploadDocument", documentService.UploadDocument },
|
||||
{ "GetDocumentsByUserId", documentService.GetDocumentsByUserId },
|
||||
{ "GetDocumentById", documentService.GetDocumentById },
|
||||
{ "RemoveDocument", documentService.RemoveDocument }
|
||||
};
|
||||
}
|
||||
|
||||
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 (FileNotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.Feed;
|
||||
using Fitness_core_BE.Exceptions;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class FeedFuncHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public FeedFuncHandler(IFeedService feedService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetFeedPostById", feedService.GetFeedPostById },
|
||||
{ "GetFeedList", feedService.GetFeedForCustomer },
|
||||
{ "Like", feedService.LikeAsync },
|
||||
{ "Unlike", feedService.UnlikeAsync },
|
||||
{ "IsLiked", feedService.IsLikedAsync },
|
||||
{ "CreateFeed", feedService.CreateFeed },
|
||||
{ "ShowFeedByClientId", feedService.ShowFeedByClient },
|
||||
{ "DeleteFeedByPostId", feedService.DeleteFeedByPostId }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
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 (UnauthorizedException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 401,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (BadRequestException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (ForbiddenException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 403,
|
||||
Message = ex.Message,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.Meal;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class MealFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public MealFunctionHandler(IMealService mealService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetMealCategoryList", mealService.GetMealCategoryList },
|
||||
{ "CreateMealCategory", mealService.CreateMealCategory },
|
||||
{ "GetMealPlanList", mealService.GetMealPlanList },
|
||||
{ "GetMealPlanById", mealService.GetMealPlanById },
|
||||
{ "GetMealPlanByCustomerId", mealService.GetMealPlanByCustomerId },
|
||||
{ "CreateMealPlan", mealService.CreateMealPlan },
|
||||
{ "CreateCustomerMealPlan", mealService.CreateCustomerMealPlan },
|
||||
{ "UpdateMealPlan", mealService.UpdateMealPlan },
|
||||
{ "GetMealItemsByMealPlanId", mealService.GetMealItemsByMealPlanId },
|
||||
{ "CreateMealItem", mealService.CreateMealItem },
|
||||
{ "DeleteMealPlan", mealService.DeleteMealPlan }
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Fitness_core_BE.Exceptions;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class PaymentFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public PaymentFunctionHandler(IPaymentService paymentService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "CreateCustomerPayment", paymentService.CreateCustomerPayment },
|
||||
{ "CreateClientPayment", paymentService.CreateClientPayment },
|
||||
{ "GetPaymentById", paymentService.GetPaymentById },
|
||||
{ "GetPaymentsByCustomerInvoice", paymentService.GetPaymentsByCustomerInvoice },
|
||||
{ "GetPaymentsByClientInvoice", paymentService.GetPaymentsByClientInvoice },
|
||||
{ "ApprovePayment", paymentService.ApprovePayment },
|
||||
};
|
||||
}
|
||||
|
||||
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 (NotFoundException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 404,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (BadRequestException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (UnauthorizedException ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 401,
|
||||
Message = ex.Message,
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ApiResponse<object>
|
||||
{
|
||||
StatusCode = 500,
|
||||
Message = $"An error occurred: {ex.Message}",
|
||||
Data = null!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.Staff;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class StaffFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public StaffFunctionHandler(IStaffService staffService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetAllStaff", staffService.GetAllStaff },
|
||||
{ "GetStaffById", staffService.GetStaffById },
|
||||
{ "GetStaffByClientId", staffService.GetStaffByClientId },
|
||||
{ "CreateStaff", staffService.CreateStaff },
|
||||
{ "UpdateStaff", staffService.UpdateStaff },
|
||||
{ "DeleteStaff", staffService.DeleteStaff }
|
||||
};
|
||||
}
|
||||
|
||||
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!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.Ticket;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class TicketFuncHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public TicketFuncHandler(ITicketService ticketService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetTicketList", ticketService.GetTicketList },
|
||||
{ "GetTicketById", ticketService.GetTicketById },
|
||||
{ "GetTicketByUserId", ticketService.GetTicketByUserId },
|
||||
{ "GetTicketCategoryList", ticketService.GetTicketCategoryList },
|
||||
{ "CreateTicket", ticketService.CreateTicket },
|
||||
{ "UpdateTicket", ticketService.UpdateTicket },
|
||||
{ "SendMessage", ticketService.SendMessage },
|
||||
{ "SubmitTicketFeedback", ticketService.SubmitTicketFeedback },
|
||||
{ "CloseTicket", ticketService.CloseTicket },
|
||||
{ "DeleteTicket", ticketService.DeleteTicket }
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class UserRegisterHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public UserRegisterHandler(ICustomerService customerService, IClientService clientService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "CreateCustomer", customerService.CreateCustomer },
|
||||
{"RegisterClient", clientService.RegisterClient }
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Fitness_core_BE.Services.Workout;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
|
||||
namespace Fitness_core_BE.Services.FunctionHandler
|
||||
{
|
||||
public class WorkoutFunctionHandler
|
||||
{
|
||||
public readonly Dictionary<string, Func<object, HttpContext, Task<object>>> _functionHandler;
|
||||
|
||||
public WorkoutFunctionHandler(IWorkoutService workoutService)
|
||||
{
|
||||
_functionHandler = new()
|
||||
{
|
||||
{ "GetWorkoutCategoryList", workoutService.GetWorkoutCategoryList },
|
||||
{ "CreateWorkoutCategory", workoutService.CreateWorkoutCategory },
|
||||
{ "GetWorkoutPlanList", workoutService.GetWorkoutPlanList },
|
||||
{ "GetWorkoutPlanById", workoutService.GetWorkoutPlanById },
|
||||
{ "GetWorkoutPlanByCustomerId", workoutService.GetWorkoutPlanByCustomerId },
|
||||
{ "CreateWorkoutPlan", workoutService.CreateWorkoutPlan },
|
||||
{ "CreateCustomerWorkout", workoutService.CreateCustomerWorkout },
|
||||
{ "UpdateWorkoutPlan", workoutService.UpdateWorkoutPlan },
|
||||
{ "DeleteWorkoutPlan", workoutService.DeleteWorkoutPlan },
|
||||
{ "GetWorkoutItemsByWorkoutPlanId", workoutService.GetWorkoutItemsByWorkoutPlanId },
|
||||
{ "CreateWorkoutItem", workoutService.CreateWorkoutItem }
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user