1- using RandomAPI . Models ;
1+ using Dapper ;
2+ using RandomAPI . Models ;
3+ using System . Data ;
24
35namespace RandomAPI . Repository
46{
57
68 /// <summary>
79 /// Implements CRUD operations for Webhook URLs using Dapper and the provided DatabaseService.
810 /// </summary>
9- public class WebhookRepository : IWebhookRepository
11+ public class WebhookRepository : IWebhookRepository , IInitializer
1012 {
11- private readonly DatabaseService _dbService ;
13+ private readonly IDbConnection _db ;
1214
13- public WebhookRepository ( DatabaseService dbService )
15+ public WebhookRepository ( IDbConnection dbService )
1416 {
15- _dbService = dbService ;
17+ _db = dbService ;
1618 }
1719
1820 /// <summary>
@@ -27,7 +29,7 @@ CREATE TABLE IF NOT EXISTS WebhookUrls (
2729 Url TEXT NOT NULL UNIQUE
2830 );" ;
2931
30- await _dbService . ExecuteAsync ( sql ) ;
32+ await _db . ExecuteAsync ( sql ) ;
3133 }
3234
3335 /// <summary>
@@ -38,7 +40,7 @@ public async Task<IEnumerable<WebhookUrl>> GetAllUrlsAsync()
3840 {
3941 const string sql = "SELECT Id, Url FROM WebhookUrls ORDER BY Id;" ;
4042 // Dapper maps the columns to the WebhookUrl model properties
41- return await _dbService . QueryAsync < WebhookUrl > ( sql ) ;
43+ return await _db . QueryAsync < WebhookUrl > ( sql ) ;
4244 }
4345
4446 /// <summary>
@@ -49,7 +51,7 @@ public async Task AddUrlAsync(string url)
4951 {
5052 // SQLITE specific command to ignore unique constraint errors if URL already exists
5153 const string sql = "INSERT OR IGNORE INTO WebhookUrls (Url) VALUES (@Url);" ;
52- await _dbService . ExecuteAsync ( sql , new { Url = url } ) ;
54+ await _db . ExecuteAsync ( sql , new { Url = url } ) ;
5355 }
5456
5557 /// <summary>
@@ -60,7 +62,7 @@ public async Task AddUrlAsync(string url)
6062 public async Task < int > DeleteUrlAsync ( string url )
6163 {
6264 const string sql = "DELETE FROM WebhookUrls WHERE Url = @Url;" ;
63- return await _dbService . ExecuteAsync ( sql , new { Url = url } ) ;
65+ return await _db . ExecuteAsync ( sql , new { Url = url } ) ;
6466 }
6567 }
6668}
0 commit comments