-
-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from pengqian089/support-mongodb-repository
系统初始化优化
- Loading branch information
Showing
16 changed files
with
166 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace AgileConfig.Server.Common; | ||
|
||
public static class SystemSettings | ||
{ | ||
public const string SuperAdminId = "super_admin"; | ||
public const string SuperAdminUserName = "admin"; | ||
|
||
public const string DefaultEnvironment = "DEV,TEST,STAGING,PROD"; | ||
public const string DefaultEnvironmentKey = "environment"; | ||
public const string DefaultJwtSecretKey = "jwtsecret"; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/AgileConfig.Server.Data.Abstraction/ISysInitRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using AgileConfig.Server.Data.Entity; | ||
|
||
namespace AgileConfig.Server.Data.Abstraction; | ||
|
||
public interface ISysInitRepository | ||
{ | ||
/// <summary> | ||
/// get jwt token secret from db | ||
/// </summary> | ||
/// <returns></returns> | ||
string? GetJwtTokenSecret(); | ||
|
||
/// <summary> | ||
/// save initialization setting | ||
/// </summary> | ||
/// <param name="setting"></param> | ||
void SaveInitSetting(Setting setting); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/AgileConfig.Server.Data.Repository.Freesql/SysInitRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using AgileConfig.Server.Common; | ||
using AgileConfig.Server.Data.Abstraction; | ||
using AgileConfig.Server.Data.Entity; | ||
using AgileConfig.Server.Data.Freesql; | ||
|
||
namespace AgileConfig.Server.Data.Repository.Freesql; | ||
|
||
public class SysInitRepository : ISysInitRepository | ||
{ | ||
public string? GetJwtTokenSecret() | ||
{ | ||
var setting = FreeSQL.Instance.Select<Setting>().Where(x => x.Id == SystemSettings.DefaultJwtSecretKey) | ||
.ToOne(); | ||
return setting?.Value; | ||
} | ||
|
||
public void SaveInitSetting(Setting setting) | ||
{ | ||
FreeSQL.Instance.Insert(setting); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/AgileConfig.Server.Data.Repository.Mongodb/SysInitRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using AgileConfig.Server.Common; | ||
|
||
namespace AgileConfig.Server.Data.Repository.Mongodb; | ||
|
||
public class SysInitRepository : ISysInitRepository | ||
{ | ||
private readonly MongodbAccess<Setting> _access = new(Global.Config["db:conn"]); | ||
|
||
public string? GetJwtTokenSecret() | ||
{ | ||
var setting = _access.MongoQueryable.FirstOrDefault(x => x.Id == SystemSettings.DefaultJwtSecretKey); | ||
return setting?.Value; | ||
} | ||
|
||
public void SaveInitSetting(Setting setting) | ||
{ | ||
_access.Collection.InsertOne(setting); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/AgileConfig.Server.IService/ISystemInitializationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace AgileConfig.Server.IService; | ||
|
||
public interface ISystemInitializationService | ||
{ | ||
bool TryInitJwtSecret(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.