| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Threading; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using OzonDomains.Models; |
| | | 6 | | using OzonRepositories.Data; |
| | | 7 | | |
| | | 8 | | namespace Services.DataServices |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Сервис доступа к данным push-уведомлений Ozon. |
| | | 12 | | /// Обёртка над <see cref="OzonPushNotificationRepository"/> в соответствии |
| | | 13 | | /// с паттерном DataService, принятым в проекте (тонкий слой делегирования). |
| | | 14 | | /// </summary> |
| | | 15 | | public class OzonPushNotificationDataService |
| | | 16 | | { |
| | | 17 | | private readonly OzonPushNotificationRepository _repository; |
| | | 18 | | |
| | 0 | 19 | | public OzonPushNotificationDataService(OzonPushNotificationRepository repository) |
| | | 20 | | { |
| | 0 | 21 | | _repository = repository; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Добавляет новую запись о push-уведомлении в базу данных. |
| | | 26 | | /// </summary> |
| | | 27 | | public async Task<int> AddAsync(OzonPushNotification notification, CancellationToken ct = default) |
| | 0 | 28 | | => await _repository.AddAsync(notification, ct); |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Возвращает запись по первичному ключу. |
| | | 32 | | /// </summary> |
| | | 33 | | public async Task<OzonPushNotification?> GetByIdAsync(long id, CancellationToken ct = default) |
| | 0 | 34 | | => await _repository.GetByIdAsync(id, ct); |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Возвращает все уведомления по номеру отправления. |
| | | 38 | | /// </summary> |
| | | 39 | | public async Task<List<OzonPushNotification>> GetByPostingNumberAsync( |
| | | 40 | | string postingNumber, |
| | | 41 | | CancellationToken ct = default) |
| | 0 | 42 | | => await _repository.GetByPostingNumberAsync(postingNumber, ct); |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Возвращает уведомления заданного типа в указанном диапазоне дат. |
| | | 46 | | /// </summary> |
| | | 47 | | public async Task<List<OzonPushNotification>> GetByMessageTypeAsync( |
| | | 48 | | string messageType, |
| | | 49 | | DateTime? from = null, |
| | | 50 | | DateTime? to = null, |
| | | 51 | | CancellationToken ct = default) |
| | 0 | 52 | | => await _repository.GetByMessageTypeAsync(messageType, from, to, ct); |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Обновляет запись о push-уведомлении. |
| | | 56 | | /// Вызывается фоновым заданием Hangfire после завершения бизнес-логики обработчика. |
| | | 57 | | /// </summary> |
| | | 58 | | public async Task<int> UpdateAsync(OzonPushNotification notification, CancellationToken ct = default) |
| | 0 | 59 | | => await _repository.UpdateAsync(notification, ct); |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Возвращает последние N уведомлений. |
| | | 63 | | /// </summary> |
| | | 64 | | public async Task<List<OzonPushNotification>> GetRecentAsync( |
| | | 65 | | int count = 100, |
| | | 66 | | CancellationToken ct = default) |
| | 0 | 67 | | => await _repository.GetRecentAsync(count, ct); |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Возвращает уведомления по идентификатору продавца в указанном диапазоне дат. |
| | | 71 | | /// </summary> |
| | | 72 | | public async Task<List<OzonPushNotification>> GetBySellerIdAsync( |
| | | 73 | | long sellerId, |
| | | 74 | | DateTime? from = null, |
| | | 75 | | DateTime? to = null, |
| | | 76 | | CancellationToken ct = default) |
| | 0 | 77 | | => await _repository.GetBySellerIdAsync(sellerId, from, to, ct); |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Возвращает уведомления с комбинированной фильтрацией. |
| | | 81 | | /// </summary> |
| | | 82 | | public async Task<List<OzonPushNotification>> GetFilteredAsync( |
| | | 83 | | string? messageType = null, |
| | | 84 | | long? sellerId = null, |
| | | 85 | | string? processingStatus = null, |
| | | 86 | | string? postingNumber = null, |
| | | 87 | | DateTime? from = null, |
| | | 88 | | DateTime? to = null, |
| | | 89 | | int take = 500, |
| | | 90 | | CancellationToken ct = default) |
| | 0 | 91 | | => await _repository.GetFilteredAsync(messageType, sellerId, processingStatus, postingNumber, from, to, take |
| | | 92 | | |
| | | 93 | | /// <summary> |
| | | 94 | | /// Возвращает все уникальные типы уведомлений, присутствующие в базе. |
| | | 95 | | /// </summary> |
| | | 96 | | public async Task<List<string>> GetDistinctMessageTypesAsync(CancellationToken ct = default) |
| | 0 | 97 | | => await _repository.GetDistinctMessageTypesAsync(ct); |
| | | 98 | | } |
| | | 99 | | } |
| | | 100 | | |