Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongodb 支持 #152

Merged
merged 51 commits into from
Jan 21, 2024
Merged
Changes from 6 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
fb33250
mongodb support init.
pengqian089 Dec 12, 2023
34929c6
适配mongodb
pengqian089 Dec 13, 2023
34f47ec
修复bug,
pengqian089 Dec 15, 2023
a93d2ad
mongodb存储的是UTC时间,目前改为取出时为 本地时间
pengqian089 Dec 15, 2023
4da4341
添加单元测试
pengqian089 Dec 15, 2023
143a9ce
修复当 主键 属性名不为Id时产生错误的问题
pengqian089 Dec 15, 2023
797c3df
优化过滤器,IRepository Find FindAsync 参数签名改为object,适配SysLog实体int类型的id
pengqian089 Dec 15, 2023
3c4b6fd
补完单元测试
pengqian089 Dec 15, 2023
a1349b8
重构数据访问模块,定义 Repository 层。
Dec 23, 2023
f24e20c
重新实现 Mongodb IRepository
pengqian089 Dec 23, 2023
238a80d
Mongodb Repository Implement
pengqian089 Dec 23, 2023
17bda7d
重构 ConfigService; 重构 FreesqlRepository;
Dec 23, 2023
01ab14a
修复 EnvAccessor 读取 env 的 bug;
Dec 23, 2023
cce74d0
Merge branch 'support-mongodb' into support-mongodb-repository
pengqian089 Dec 25, 2023
c6f6982
移除 Mongodb Service,使用 Mongodb Repository
pengqian089 Dec 25, 2023
5f193ce
修复错误依赖
pengqian089 Dec 25, 2023
8ca3baf
Merge pull request #1 from pengqian089/support-mongodb-repository
pengqian089 Dec 25, 2023
cacf8f4
EventRegister 注入抽象
pengqian089 Dec 25, 2023
b50d583
对 IFreeSqlFactory 接口添加 DeaultFreesqlFactory
Dec 25, 2023
3d67e5b
Merge branch 'support-mongodb' of https://github.com/pengqian089/Agil…
Dec 25, 2023
bcbbd25
Merge pull request #2 from pengqian089/support-mongodb-repository
pengqian089 Dec 26, 2023
a016c48
Service 实现层移除 FreeSql 的依赖,同时适配新的 Repository 层
pengqian089 Dec 26, 2023
e2f8137
Merge pull request #3 from pengqian089/support-mongodb-repository
pengqian089 Dec 26, 2023
85884cf
系统初始化优化
pengqian089 Dec 27, 2023
5428e92
Merge pull request #4 from pengqian089/support-mongodb-repository
pengqian089 Dec 27, 2023
e37858c
修复在 freesql 下的一些问题。配置的该删除基本能用。
Jan 2, 2024
4a6d8ee
Refactor ConfigService;
kklldog Jan 3, 2024
cb3529c
Refactor Freesql repositories;
kklldog Jan 3, 2024
ecc0064
adapt to different environment configurations of mongodb
pengqian089 Jan 5, 2024
625b7d4
修复相关bug,重构 EventRegister 相关内容。
Jan 6, 2024
7b453e5
重构 EventRegisterService
Jan 6, 2024
7057e50
实现 Unitofwork 模式来适配事务
Jan 6, 2024
304c906
Refactor FreesqlUow
Jan 6, 2024
abedae3
Refactor freesql respository;
Jan 6, 2024
5e77ba9
mongodb 事务适配;
pengqian089 Jan 6, 2024
462654d
Add more unit test cases;
Jan 7, 2024
7bbc27b
Update master ci file
Jan 7, 2024
0f9c6a1
重构 SystemInitializationService 把环境初始化跟Jwt secret初始化整合到一起;
Jan 7, 2024
eb9a34d
When standalone cluster run action without transaction.
Jan 13, 2024
51805e2
Update AppServiceTests for mysql
Jan 13, 2024
0643deb
Update AppServiceTests for pg
Jan 14, 2024
7932587
update AppServiceTests for oracle
Jan 14, 2024
f72f3ca
Update testcases;
Jan 14, 2024
be8b099
Fix ConfigServer test cases on sqlite
Jan 21, 2024
43b1a7d
Update ConfigService test cases for sqlserver
Jan 21, 2024
bf894db
update configservice test cases for mysql
Jan 21, 2024
c3f27df
Update ApiController test cases
Jan 21, 2024
42f546f
Update testcases;
Jan 21, 2024
d5a7dc8
Fix mongodb syslog sorted issue
Jan 21, 2024
a7b96fe
重构 test cases, 统一了 freesql 跟 mongodb 的测试用例;
Jan 21, 2024
6da6f61
测试用例适配 mongodb;
Jan 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions AgileConfig.sln
Original file line number Diff line number Diff line change
@@ -40,14 +40,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AgileConfig.Server.OIDC", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Data.Mongodb", "src\AgileConfig.Server.Data.Mongodb\AgileConfig.Server.Data.Mongodb.csproj", "{4803646E-8327-4F69-8BA5-2244CB58BBA2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Mongodb.Service", "src\AgileConfig.Server.Mongodb.Service\AgileConfig.Server.Mongodb.Service.csproj", "{375B1F54-11CA-415D-ADCC-3B14684AE1DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Mongodb.ServiceTest", "test\AgileConfig.Server.Mongodb.ServiceTest\AgileConfig.Server.Mongodb.ServiceTest.csproj", "{E35504A4-E032-4EEA-A53A-12C99B56680B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Data.Abstraction", "src\AgileConfig.Server.Data.Abstraction\AgileConfig.Server.Data.Abstraction.csproj", "{E8101403-72C9-40FB-BCEE-16ED5C23A495}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Data.Repository.Freesql", "src\AgileConfig.Server.Data.Repository.Freesql\AgileConfig.Server.Data.Repository.Freesql.csproj", "{955F64CC-9EAC-4563-804D-6E2CF9547357}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Data.Repository.Mongodb", "src\AgileConfig.Server.Data.Repository.Mongodb\AgileConfig.Server.Data.Repository.Mongodb.csproj", "{C6B7A5A6-7287-4A20-9336-EBE82A5256F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -102,14 +100,6 @@ Global
{4803646E-8327-4F69-8BA5-2244CB58BBA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4803646E-8327-4F69-8BA5-2244CB58BBA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4803646E-8327-4F69-8BA5-2244CB58BBA2}.Release|Any CPU.Build.0 = Release|Any CPU
{375B1F54-11CA-415D-ADCC-3B14684AE1DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{375B1F54-11CA-415D-ADCC-3B14684AE1DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{375B1F54-11CA-415D-ADCC-3B14684AE1DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{375B1F54-11CA-415D-ADCC-3B14684AE1DB}.Release|Any CPU.Build.0 = Release|Any CPU
{E35504A4-E032-4EEA-A53A-12C99B56680B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E35504A4-E032-4EEA-A53A-12C99B56680B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E35504A4-E032-4EEA-A53A-12C99B56680B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E35504A4-E032-4EEA-A53A-12C99B56680B}.Release|Any CPU.Build.0 = Release|Any CPU
{E8101403-72C9-40FB-BCEE-16ED5C23A495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8101403-72C9-40FB-BCEE-16ED5C23A495}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8101403-72C9-40FB-BCEE-16ED5C23A495}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -118,6 +108,10 @@ Global
{955F64CC-9EAC-4563-804D-6E2CF9547357}.Debug|Any CPU.Build.0 = Debug|Any CPU
{955F64CC-9EAC-4563-804D-6E2CF9547357}.Release|Any CPU.ActiveCfg = Release|Any CPU
{955F64CC-9EAC-4563-804D-6E2CF9547357}.Release|Any CPU.Build.0 = Release|Any CPU
{C6B7A5A6-7287-4A20-9336-EBE82A5256F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6B7A5A6-7287-4A20-9336-EBE82A5256F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6B7A5A6-7287-4A20-9336-EBE82A5256F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6B7A5A6-7287-4A20-9336-EBE82A5256F1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -135,10 +129,9 @@ Global
{70724B0E-7D81-412C-BDA7-747F4845E990} = {F277EC27-8C0E-4490-9645-F5F3244F9246}
{E49A2006-6D07-4434-AEC1-27E356A767AE} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{4803646E-8327-4F69-8BA5-2244CB58BBA2} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{375B1F54-11CA-415D-ADCC-3B14684AE1DB} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{E35504A4-E032-4EEA-A53A-12C99B56680B} = {F277EC27-8C0E-4490-9645-F5F3244F9246}
{E8101403-72C9-40FB-BCEE-16ED5C23A495} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{955F64CC-9EAC-4563-804D-6E2CF9547357} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{C6B7A5A6-7287-4A20-9336-EBE82A5256F1} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7F10DB58-5B6F-4EAC-994F-14E8046B306F}
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
<ItemGroup>
<ProjectReference Include="..\AgileConfig.Server.Data.Abstraction\AgileConfig.Server.Data.Abstraction.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Repository.Freesql\AgileConfig.Server.Data.Repository.Freesql.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Mongodb.Service\AgileConfig.Server.Mongodb.Service.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Repository.Mongodb\AgileConfig.Server.Data.Repository.Mongodb.csproj" />
<ProjectReference Include="..\Agile.Config.Protocol\Agile.Config.Protocol.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Entity\AgileConfig.Server.Data.Entity.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Freesql\AgileConfig.Server.Data.Freesql.csproj" />
9 changes: 2 additions & 7 deletions src/AgileConfig.Server.Apisite/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using AgileConfig.Server.Apisite.UIExtension;
using AgileConfig.Server.Apisite.Websocket;
using AgileConfig.Server.Common;
using AgileConfig.Server.Common.RestClient;
using AgileConfig.Server.Data.Freesql;
using AgileConfig.Server.Mongodb.Service;
using AgileConfig.Server.OIDC;
using AgileConfig.Server.Service;
using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -18,9 +15,9 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using AgileConfig.Server.Data.Repository.Freesql;
using AgileConfig.Server.Data.Repository.Mongodb;

namespace AgileConfig.Server.Apisite
{
@@ -161,9 +158,7 @@ private void AddDataRepositories(IServiceCollection services)
{
if (string.Equals(Configuration["db:provider"], "mongodb", StringComparison.OrdinalIgnoreCase))
{
// todo

// services.AddMongoRepository();
services.AddMongodbRepository();
}
else
{
Original file line number Diff line number Diff line change
@@ -13,4 +13,8 @@
<PackageReference Include="MongoDB.Driver" Version="2.22.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AgileConfig.Server.Data.Abstraction\AgileConfig.Server.Data.Abstraction.csproj" />
</ItemGroup>

</Project>
91 changes: 91 additions & 0 deletions src/AgileConfig.Server.Data.Mongodb/MongodbRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Linq.Expressions;
using AgileConfig.Server.Common;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
using MongoDB.Driver.Linq;

namespace AgileConfig.Server.Data.Mongodb;

public class MongodbRepository<TEntity, TId> : Abstraction.IRepository<TEntity, TId>
where TEntity : IEntity<TId>, new()
{
private readonly MongodbAccess<TEntity> _access;

public MongodbRepository(string? connectionString)
{
_access = new MongodbAccess<TEntity>(connectionString);
}

[ActivatorUtilitiesConstructor]
public MongodbRepository(IConfiguration configuration)
{
var connectionString = configuration["db:conn"];
_access = new MongodbAccess<TEntity>(connectionString);
}

public void Dispose()
{
GC.SuppressFinalize(this);
}

public async Task<List<TEntity>> AllAsync()
{
return await _access.MongoQueryable.ToListAsync();
}

private Expression<Func<TEntity,bool>> GetIdPropertyFilter(TId id)
{
var expression = _access.MongoQueryable.Where(x => Equals(x.Id, id)).Expression;
return Expression.Lambda<Func<TEntity, bool>>(expression);
}

public async Task<TEntity> GetAsync(TId id)
{
var filter = GetIdPropertyFilter(id);
return await (await _access.Collection.FindAsync(filter)).SingleOrDefaultAsync();
}

public async Task UpdateAsync(TEntity entity)
{
var filter = GetIdPropertyFilter(entity.Id);
await _access.Collection.ReplaceOneAsync(filter, entity);
}

public async Task UpdateAsync(IList<TEntity> entities)
{
var writes = entities
.Select(x => new ReplaceOneModel<TEntity>(GetIdPropertyFilter(x.Id), x))
.ToList();
await _access.Collection.BulkWriteAsync(writes);
}

public async Task DeleteAsync(TEntity entity)
{
var filter = GetIdPropertyFilter(entity.Id);
await _access.Collection.DeleteOneAsync(filter);
}

public async Task DeleteAsync(IList<TEntity> entities)
{
var filter = Builders<TEntity>.Filter.In(x => x.Id, entities.Select(y => y.Id));
await _access.Collection.DeleteManyAsync(filter);
}

public async Task<TEntity> InsertAsync(TEntity entity)
{
await _access.Collection.InsertOneAsync(entity);
return entity;
}

public async Task InsertAsync(IList<TEntity> entities)
{
if(entities.Count > 0)
await _access.Collection.InsertManyAsync(entities);
}

public async Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> exp)
{
return await _access.MongoQueryable.Where(exp).ToListAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AgileConfig.Server.Data.Abstraction\AgileConfig.Server.Data.Abstraction.csproj" />
<ProjectReference Include="..\AgileConfig.Server.Data.Mongodb\AgileConfig.Server.Data.Mongodb.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class AppInheritancedRepository : MongodbRepository<AppInheritanced, string>, IAppInheritancedRepository
{
public AppInheritancedRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public AppInheritancedRepository(IConfiguration configuration) : base(configuration)
{
}
}
13 changes: 13 additions & 0 deletions src/AgileConfig.Server.Data.Repository.Mongodb/AppRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class AppRepository: MongodbRepository<App, string>, IAppRepository
{
public AppRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public AppRepository(IConfiguration configuration) : base(configuration)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class ConfigPublishedRepository : MongodbRepository<ConfigPublished, string>, IConfigPublishedRepository
{
public ConfigPublishedRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public ConfigPublishedRepository(IConfiguration configuration) : base(configuration)
{
}
}
13 changes: 13 additions & 0 deletions src/AgileConfig.Server.Data.Repository.Mongodb/ConfigRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class ConfigRepository: MongodbRepository<Config, string>, IConfigRepository
{
public ConfigRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public ConfigRepository(IConfiguration configuration) : base(configuration)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public static class MongodbRepositoryExt
{
public static void AddMongodbRepository(this IServiceCollection services)
{
services.AddScoped<IAppInheritancedRepository, AppInheritancedRepository>();
services.AddScoped<IAppRepository, AppRepository>();
services.AddScoped<IConfigPublishedRepository, ConfigPublishedRepository>();
services.AddScoped<IConfigRepository, ConfigRepository>();
services.AddScoped<IPublishDetailRepository, PublishDetailRepository>();
services.AddScoped<IPublishTimelineRepository, PublishTimelineRepository>();
services.AddScoped<IServerNodeRepository, ServerNodeRepository>();
services.AddScoped<IServiceInfoRepository, ServiceInfoRepository>();
services.AddScoped<ISettingRepository, SettingRepository>();
services.AddScoped<ISysLogRepository, SysLogRepository>();
services.AddScoped<IUserAppAuthRepository, UserAppAuthRepository>();
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IUserRoleRepository, UserRoleRepository>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class PublishDetailRepository: MongodbRepository<PublishDetail, string>, IPublishDetailRepository
{
public PublishDetailRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public PublishDetailRepository(IConfiguration configuration) : base(configuration)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class PublishTimelineRepository: MongodbRepository<PublishTimeline, string>, IPublishTimelineRepository
{
public PublishTimelineRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public PublishTimelineRepository(IConfiguration configuration) : base(configuration)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class ServerNodeRepository: MongodbRepository<ServerNode, string>, IServerNodeRepository
{
public ServerNodeRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public ServerNodeRepository(IConfiguration configuration) : base(configuration)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class ServiceInfoRepository: MongodbRepository<ServiceInfo, string>, IServiceInfoRepository
{
public ServiceInfoRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public ServiceInfoRepository(IConfiguration configuration) : base(configuration)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class SettingRepository: MongodbRepository<Setting, string>, ISettingRepository
{
public SettingRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public SettingRepository(IConfiguration configuration) : base(configuration)
{
}
}
13 changes: 13 additions & 0 deletions src/AgileConfig.Server.Data.Repository.Mongodb/SysLogRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AgileConfig.Server.Data.Repository.Mongodb;

public class SysLogRepository: MongodbRepository<SysLog, int>, ISysLogRepository
{
public SysLogRepository(string? connectionString) : base(connectionString)
{
}

[ActivatorUtilitiesConstructor]
public SysLogRepository(IConfiguration configuration) : base(configuration)
{
}
}
Loading