From 4264d8135c066081dbabb412db17bf537ceab86e Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 20 Dec 2022 19:25:02 +0800 Subject: Develop secret api. v50 --- .../CrupestApi.Commons/Secrets/SecretService.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets') diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs index 47e9583..69acad3 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs @@ -1,5 +1,5 @@ +using System.Data; using CrupestApi.Commons.Crud; -using Dapper; namespace CrupestApi.Commons.Secrets; @@ -11,23 +11,26 @@ public class SecretService : CrudService, ISecretService } - protected override void DoInitializeDatabase(System.Data.IDbConnection connection) + protected override void DoInitializeDatabase(IDbConnection connection) { base.DoInitializeDatabase(connection); using var transaction = connection.BeginTransaction(); - _table.Insert(connection, new SecretInfo - { - Key = SecretsConstants.SecretManagementKey, - Secret = "crupest", - Description = "This is the init key. Please revoke it immediately after creating a new one." - }); + var insertClause = InsertClause.Create() + .Add(nameof(SecretInfo.Key), SecretsConstants.SecretManagementKey) + .Add(nameof(SecretInfo.Secret), "crupest") + .Add(nameof(SecretInfo.Description), "This is the init key. Please revoke it immediately after creating a new one."); + _table.Insert(connection, insertClause); transaction.Commit(); } public void CreateTestSecret(string key, string secret) { var connection = _dbConnection; - connection.Execute("INSERT INTO secrets (key, secret, description) VALUES (@key, @secret, @desc)", new { key, secret, desc = "Test key." }); + var insertClause = InsertClause.Create() + .Add(nameof(SecretInfo.Key), key) + .Add(nameof(SecretInfo.Secret), secret) + .Add(nameof(SecretInfo.Description), "Test secret."); + _table.Insert(connection, insertClause); } public List GetPermissions(string secret) -- cgit v1.2.3