using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Newtonsoft.Json; using PartnerDAL.DTO.PartnerWebhook; using PartnerDAL.Interfaces; using PartnerDAL.Query.PartnerWebhook; namespace PartnerDAL.CustomCode.PartnerWebhook { public class PartnerWebhookDAL : IPartnerWebhookDAL { private readonly IQueryExecutor _queryExecutor; private readonly IValidation _validation; public PartnerWebhookDAL(IQueryExecutor queryExecutor, IValidation validation) { _queryExecutor = queryExecutor; _validation = validation; } public async Task GetPartnerWebhookList(int partnerProductId, LoginDTO loginDTO) { try { var rows = await _queryExecutor.QueryAsync( loginDTO, PartnerWebhookQB.GET_PARTNER_WEBHOOK_LIST, new { PartnerProductId = partnerProductId }).ConfigureAwait(false); return JsonConvert.SerializeObject(rows); } catch (Exception) { throw; } } public async Task> GetWebhooksByEvent(int eventTypeId, LoginDTO loginDTO) { try { return await _queryExecutor.QueryAsync( loginDTO, PartnerWebhookQB.GET_WEBHOOKS_BY_EVENT, new { EventTypeId = eventTypeId }).ConfigureAwait(false); } catch (Exception) { throw; } } public async Task CheckEventTypeExists(int eventTypeId, LoginDTO loginDTO) { try { return await _queryExecutor.ExecuteScalarAsync( loginDTO, PartnerWebhookQB.CHECK_EVENT_TYPE_EXISTS, new { EventTypeId = eventTypeId }).ConfigureAwait(false); } catch (Exception) { throw; } } public async Task SavePartnerWebhook(PartnerWebhookDTO dto, LoginDTO loginDTO) { try { return await _queryExecutor.ExecuteIdentityAsync( loginDTO, PartnerWebhookQB.SAVE_PARTNER_WEBHOOK, dto).ConfigureAwait(false); } catch (Exception ex) { string error = await _validation.HandleException(ex, ErrorResponse.SaveErrorMessage).ConfigureAwait(false); throw new Exception(error); } } public async Task DeletePartnerWebhook(int webhookId, int modifiedById, LoginDTO loginDTO) { try { return await _queryExecutor.ExecuteAsync( loginDTO, PartnerWebhookQB.DELETE_PARTNER_WEBHOOK, new { WebhookId = webhookId, ModifiedById = modifiedById, ModifiedOn = DateTime.UtcNow }).ConfigureAwait(false); } catch (Exception ex) { string error = await _validation.HandleException(ex, ErrorResponse.DeleteErrorMessage).ConfigureAwait(false); throw new Exception(error); } } public async Task UpdateWebhookDeliveryStatus(int webhookId, string status, LoginDTO loginDTO) { try { await _queryExecutor.ExecuteAsync( loginDTO, PartnerWebhookQB.UPDATE_WEBHOOK_DELIVERY_STATUS, new { WebhookId = webhookId, Status = status }).ConfigureAwait(false); } catch (Exception) { throw; } } } }