diff --git a/Program.cs b/Program.cs index 2b69b6f..a35dfbe 100644 --- a/Program.cs +++ b/Program.cs @@ -90,7 +90,7 @@ builder.Services.AddAuthentication(options => builder.Services.Configure(builder.Configuration.GetSection("PushFileSetting")); // HttpClientFactory를 이용한 ApnsPushService 등록 (핸들러에 인증서 추가) -builder.Services.AddHttpClient(client => +builder.Services.AddHttpClient(client => { var settings = builder.Configuration.GetSection("PushFileSetting").Get(); client.BaseAddress = new Uri(settings.uri); diff --git a/Program/Repositories/V1/Interfaces/ILogRepository.cs b/Program/Repositories/V1/Interfaces/ILogRepository.cs index 7b526af..413a6fd 100644 --- a/Program/Repositories/V1/Interfaces/ILogRepository.cs +++ b/Program/Repositories/V1/Interfaces/ILogRepository.cs @@ -5,5 +5,8 @@ namespace Back.Program.Repositories.V1.Interfaces; public interface ILogRepository { Task SaveLogUser(LogUser log); - Task SaveLogProjrct(LogProject log); + Task SaveLogProject(LogProject log); + Task SaveLogPush(LogPush log); + + } \ No newline at end of file diff --git a/Program/Repositories/V1/Interfaces/IPushRepository.cs b/Program/Repositories/V1/Interfaces/IPushRepository.cs new file mode 100644 index 0000000..1d3037e --- /dev/null +++ b/Program/Repositories/V1/Interfaces/IPushRepository.cs @@ -0,0 +1,14 @@ +using Back.Program.Models.Entities; + +namespace Back.Program.Repositories.V1.Interfaces; + +public interface IPushRepository +{ + Task FindAcademy(string bid); + Task FindPushPayload(string bid, string? pid, string? category); + Task FindUserAcademy(string uid, string bid); + Task FindPushCabinet(string uid); + Task FindUser(string uid); + + +} \ No newline at end of file diff --git a/Program/Repositories/V1/LogRepository.cs b/Program/Repositories/V1/LogRepository.cs index 396e968..4dead60 100644 --- a/Program/Repositories/V1/LogRepository.cs +++ b/Program/Repositories/V1/LogRepository.cs @@ -22,9 +22,15 @@ public class LogRepository: ILogRepository return await _context.SaveChangesAsync() > 0; } - public async Task SaveLogProjrct(LogProject log) + public async Task SaveLogProject(LogProject log) { _context.LogProject.Add(log); return await _context.SaveChangesAsync() > 0; } + + public async Task SaveLogPush(LogPush log) + { + _context.LogPush.Add(log); + return await _context.SaveChangesAsync() > 0; + } } \ No newline at end of file diff --git a/Program/Repositories/V1/PushRepository.cs b/Program/Repositories/V1/PushRepository.cs new file mode 100644 index 0000000..799cf61 --- /dev/null +++ b/Program/Repositories/V1/PushRepository.cs @@ -0,0 +1,42 @@ +using Back.Program.Common.Data; +using Back.Program.Models.Entities; +using Back.Program.Repositories.V1.Interfaces; +using Microsoft.EntityFrameworkCore; + +namespace Back.Program.Repositories.V1; + +public class PushRepository: IPushRepository +{ + private readonly AppDbContext _context; + + public PushRepository(AppDbContext context) + { + _context = context; + } + + + public async Task FindAcademy(string bid, string? pid, string? category) + { + return await _context.Academy.FirstOrDefaultAsync(a => a.bid == bid); + } + + public async Task FindPushPayload(string bid, string pid, string? category) + { + throw new NotImplementedException(); + } + + public async Task FindUserAcademy(string uid, string bid) + { + throw new NotImplementedException(); + } + + public async Task FindPushCabinet(string uid) + { + throw new NotImplementedException(); + } + + public async Task FindUser(string uid) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/Program/Services/V1/AppService.cs b/Program/Services/V1/AppService.cs index ae6922b..6bc33fb 100644 --- a/Program/Services/V1/AppService.cs +++ b/Program/Services/V1/AppService.cs @@ -61,7 +61,7 @@ public class AppService: IAppService if (await _repositoryService.SaveData(apiHeader)) { // 새로 업뎃해서 저장 - if(await _logRepository.SaveLogProjrct( new LogProject { create_date = DateTime.Now , log = $"[{summary}] : 해당 키 유효시간 만료로 인한 새 키 부여"})) + if(await _logRepository.SaveLogProject( new LogProject { create_date = DateTime.Now , log = $"[{summary}] : 해당 키 유효시간 만료로 인한 새 키 부여"})) { _logger.LogInformation($"[{summary}] : 성공"); } @@ -99,7 +99,7 @@ public class AppService: IAppService if (await _repositoryService.SaveData(newHeader)) { // 새로 업뎃해서 저장 - if(await _logRepository.SaveLogProjrct( new LogProject { create_date = DateTime.Now , log = $"[{summary}] : 새 기기 등록으로 인한 새 키 부여"})) + if(await _logRepository.SaveLogProject( new LogProject { create_date = DateTime.Now , log = $"[{summary}] : 새 기기 등록으로 인한 새 키 부여"})) { _logger.LogInformation($"[{summary}] : 성공"); } diff --git a/Program/Services/V1/InMemoryPushQueue.cs b/Program/Services/V1/InMemoryPushQueue.cs index 6e6f351..fc04058 100644 --- a/Program/Services/V1/InMemoryPushQueue.cs +++ b/Program/Services/V1/InMemoryPushQueue.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using Back.Program.Models.Entities; +using Back.Program.Services.V1.Interfaces; namespace Back.Program.Services.V1 { @@ -33,9 +34,9 @@ namespace Back.Program.Services.V1 public class PushBackgroundService : BackgroundService { private readonly IPushQueue _queue; - private readonly IApnsPushService _pushService; + private readonly IPushService _pushService; - public PushBackgroundService(IPushQueue queue, IApnsPushService pushService) + public PushBackgroundService(IPushQueue queue, IPushService pushService) { _queue = queue; _pushService = pushService; diff --git a/Program/Services/V1/Interfaces/IPushService.cs b/Program/Services/V1/Interfaces/IPushService.cs new file mode 100644 index 0000000..32546d5 --- /dev/null +++ b/Program/Services/V1/Interfaces/IPushService.cs @@ -0,0 +1,8 @@ +using Back.Program.Models.Entities; + +namespace Back.Program.Services.V1.Interfaces; + +public interface IPushService +{ + Task SendPushNotificationAsync(string deviceToken, Payload payload); +} \ No newline at end of file diff --git a/Program/Services/V1/PushService.cs b/Program/Services/V1/PushService.cs index d90d12d..bc578da 100644 --- a/Program/Services/V1/PushService.cs +++ b/Program/Services/V1/PushService.cs @@ -2,22 +2,19 @@ using System.Text; using System.Text.Json; using Back.Program.Common.Model; using Back.Program.Models.Entities; +using Back.Program.Services.V1.Interfaces; using Microsoft.Extensions.Options; using Polly; using Version = System.Version; namespace Back.Program.Services.V1 { - public interface IApnsPushService - { - Task SendPushNotificationAsync(string deviceToken, Payload payload); - } - public class ApnsPushService: IApnsPushService + public class PushService: IPushService { private readonly HttpClient _httpClient; private readonly PushFileSetting _setting; - public ApnsPushService(HttpClient httpClient, IOptions options) + public PushService(HttpClient httpClient, IOptions options) { _httpClient = httpClient; _setting = options.Value; @@ -31,23 +28,6 @@ namespace Back.Program.Services.V1 throw new FileNotFoundException("[푸시] : p12 관련 파일 확인 필요"); var jsonPayload = JsonSerializer.Serialize(payload); - // var keys = - // JsonSerializer.Deserialize>(await File.ReadAllTextAsync(_setting.p12PWPath)) - // ?? throw new FileContentNotFoundException("[푸시] : 파일 내부의 값을 읽어오지 못함"); - // - // try - // { - // var handler = new HttpClientHandler(); - // handler.ClientCertificates - // .Add(new X509Certificate2(_setting.p12Path, keys["Password"])); - // handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12; - // - // - // using var client = new HttpClient(handler) - // { - // BaseAddress = new Uri(_setting.uri), - // Timeout = TimeSpan.FromSeconds(60) - // }; var request = new HttpRequestMessage(HttpMethod.Post, $"/3/device/{deviceToken}") { @@ -73,20 +53,7 @@ namespace Back.Program.Services.V1 } }); - // var response = await client.SendAsync(request); - // - // if (response.IsSuccessStatusCode) return true; - // else - // { - // var errorContent = await response.Content.ReadAsStringAsync(); - // throw new ServiceConnectionFailedException($"[푸시] : APNS 통신 실패 - {errorContent}"); - // } - // } - // catch (HttpRequestException httpEx) - // { - // Console.WriteLine($"HttpRequestException: {httpEx.Message}"); - // throw new ServiceConnectionFailedException($"[푸시] : APNS 통신 실패 - {httpEx.Message}"); - // } } + } } \ No newline at end of file