40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using adas_core.Application.Repositories.Interfaces;
|
|
using adas_core.Domain.Models.AppSettings;
|
|
using adas_core.Domain.Models.MongoModels;
|
|
using Microsoft.Extensions.Options;
|
|
using MongoDB.Bson;
|
|
using MongoDB.Driver;
|
|
|
|
namespace adas_core.Infrastructure.Repositories;
|
|
|
|
public class ServiceConfigRepository : MongoRepository<ServiceConfig>, IServiceConfigRepository
|
|
{
|
|
private readonly ApiSettings _apiSettings;
|
|
|
|
public ServiceConfigRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database) : base(database)
|
|
{
|
|
if (apiSettings == null) throw new ArgumentNullException(nameof(apiSettings));
|
|
_apiSettings = apiSettings.Value;
|
|
} //For testing
|
|
|
|
|
|
|
|
public override string GetCollectionName()
|
|
{
|
|
return _apiSettings.ServiceConfig ?? "service_config";
|
|
}
|
|
|
|
public async Task<ServiceConfig?> FindById(string id)
|
|
{
|
|
var result = await Collection.FindAsync(Builders<ServiceConfig>.Filter.Eq(x => x.StrId, id));
|
|
|
|
return await result.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<ServiceConfig?> FindById(ObjectId oid)
|
|
{
|
|
var result = await Collection.FindAsync(Builders<ServiceConfig>.Filter.Eq(x => x.Id, oid));
|
|
|
|
return await result.FirstOrDefaultAsync();
|
|
}
|
|
} |