2023-02-19 21:39:03 -08:00
|
|
|
using System.Data;
|
|
|
|
using Dapper;
|
|
|
|
using Newsbot.Collector.Domain.Interfaces;
|
|
|
|
using Newsbot.Collector.Domain.Models;
|
|
|
|
using Npgsql;
|
|
|
|
|
|
|
|
namespace Newsbot.Collector.Database.Repositories;
|
|
|
|
|
|
|
|
public class DiscordQueueTable : IDiscordQueueRepository
|
|
|
|
{
|
|
|
|
private string _connectionString;
|
|
|
|
|
|
|
|
public DiscordQueueTable(string connectionString)
|
|
|
|
{
|
|
|
|
_connectionString = connectionString;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IDbConnection OpenConnection(string connectionString)
|
|
|
|
{
|
|
|
|
var conn = new NpgsqlConnection(_connectionString);
|
|
|
|
conn.Open();
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void New(DiscordQueueModel model)
|
|
|
|
{
|
|
|
|
using var conn = OpenConnection(_connectionString);
|
|
|
|
var query = "Insert into DiscordQueue(ID, ArticleId) Values (@id, @articleid);";
|
|
|
|
conn.Execute(query, new
|
|
|
|
{
|
|
|
|
id = Guid.NewGuid(),
|
|
|
|
articleid = model.ArticleID
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Delete(Guid id)
|
|
|
|
{
|
|
|
|
using var conn = OpenConnection(_connectionString);
|
|
|
|
var query = "Delete From DiscordQueue Where ID = @id;";
|
|
|
|
conn.Execute(query, new
|
|
|
|
{
|
|
|
|
id = id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<DiscordQueueModel> List(int limit = 25)
|
|
|
|
{
|
|
|
|
using var conn = OpenConnection(_connectionString);
|
2023-03-05 22:33:41 -08:00
|
|
|
var query = "Select * from DiscordQueue LIMIT @limit;";
|
2023-02-19 21:39:03 -08:00
|
|
|
return conn.Query<DiscordQueueModel>(query, new {
|
|
|
|
limit = limit
|
|
|
|
}).ToList();
|
|
|
|
}
|
|
|
|
}
|