초기커밋
This commit is contained in:
177
BrokerApiTest/DocQuery/DataExample.cs
Normal file
177
BrokerApiTest/DocQuery/DataExample.cs
Normal file
@@ -0,0 +1,177 @@
|
||||
using PlatformTest.DbQuery;
|
||||
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
using USER_GUID = System.String;
|
||||
|
||||
|
||||
// public class DBQUserTest : QueryExecutorBase
|
||||
// {
|
||||
// private string m_combination_key_for_pk = string.Empty;
|
||||
// private string m_combination_key_for_sk = string.Empty;
|
||||
// private UserTestEntity? m_user_test;
|
||||
// private DynamoDbClient m_dynamoDbClient;
|
||||
//
|
||||
// public DBQUserTest(string combinationKeyForPK, string combinationKeyForSK, DynamoDbClient dynamoDbClient)
|
||||
// : base(nameof(DBQUserTest))
|
||||
// {
|
||||
// m_combination_key_for_pk = combinationKeyForPK;
|
||||
// m_combination_key_for_sk = combinationKeyForSK;
|
||||
// m_dynamoDbClient = dynamoDbClient;
|
||||
// }
|
||||
//
|
||||
// //===================================================================================================
|
||||
// // DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
// //===================================================================================================
|
||||
// public override async Task<Result> onPrepareQuery()
|
||||
// {
|
||||
// var result = new Result();
|
||||
//
|
||||
// var user_test = getOwner();
|
||||
// NullReferenceCheckHelper.throwIfNull(user_test, () => "user is null !!!");
|
||||
//
|
||||
// var query_batch = getQueryBatch();
|
||||
// NullReferenceCheckHelper.throwIfNull(query_batch,
|
||||
// () => $"query_batch is null !!! - {user_test.toBasicString()}");
|
||||
//
|
||||
// var db_connector = query_batch.getDynamoDbConnector();
|
||||
// NullReferenceCheckHelper.throwIfNull(db_connector,
|
||||
// () => $"db_connector is null !!! - {user_test.toBasicString()}");
|
||||
//
|
||||
// await DynamoDBDocBaseHelper.makePrimaryKey<UserTestDoc>(m_combination_key_for_pk, m_combination_key_for_sk);
|
||||
//
|
||||
// // var ctxs = new List<DynamoDbDocumentQueryContext>();
|
||||
// //
|
||||
// // (result, var user_doc) = await m_user_test.onCopyToDocument();
|
||||
//
|
||||
//
|
||||
// return Task.FromResult(result);
|
||||
// }
|
||||
//
|
||||
// //===================================================================================================
|
||||
// // onPrepareQuery()를 성공할 경우 호출된다.
|
||||
// //===================================================================================================
|
||||
// public override async Task<Result> onQuery()
|
||||
// {
|
||||
// var result = new Result();
|
||||
// var err_msg = string.Empty;
|
||||
//
|
||||
// var user = getOwner();
|
||||
// NullReferenceCheckHelper.throwIfNull(user, () => "user is null !!!");
|
||||
//
|
||||
// var query_batch = getQueryBatch();
|
||||
// NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {user.toBasicString()}");
|
||||
//
|
||||
// var db_connector = query_batch.getDynamoDbConnector();
|
||||
//
|
||||
// var user_doc = new UserTestDoc(m_combination_key_for_pk, m_combination_key_for_sk);
|
||||
// var user_test_base = new UserTestEntity(EntityType.None);
|
||||
// var user_test_base_attrib = user_test_base.getEntityAttribute<UserTestEntityAttribute>();
|
||||
// NullReferenceCheckHelper.throwIfNull(user_test_base_attrib, () => $"user_test_base_attrib is null !!!");
|
||||
//
|
||||
// user_test_base_attrib.UserId = m_combination_key_for_pk;
|
||||
// user_test_base_attrib.Name = m_combination_key_for_sk;
|
||||
//
|
||||
// var user_test_base_action = user_test_base.getEntityAction<UserTestInsertAction>();
|
||||
// NullReferenceCheckHelper.throwIfNull(user_test_base_action, () => $"user_test_base_action is null !!!");
|
||||
//
|
||||
// result = await user_test_base_action.tryInsertUser(m_combination_key_for_pk, m_combination_key_for_sk);
|
||||
// if (result.isFail())
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// var query_context = new DynamoDbDocumentQueryContext(user_doc, QueryType.Insert);
|
||||
// await query_batch.addQuery(new QueryExecutorBase("InsertUser")
|
||||
// {
|
||||
// onPrepareQuery = () => Task.FromResult(new Result()),
|
||||
// onQuery = () => Task.FromResult(new Result()),
|
||||
// onQueryResponseCommit = () => Task.CompletedTask,
|
||||
// onQueryResponseRollback = (errorResult) => Task.CompletedTask
|
||||
// });
|
||||
//
|
||||
// var result = await QueryHelper.sendQueryAndBusinessLog(query_batch);
|
||||
// if (result.isFail())
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// //===================================================================================================
|
||||
// // DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
// //===================================================================================================
|
||||
// public override Task onQueryResponseCommit()
|
||||
// {
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
//
|
||||
// //===================================================================================================
|
||||
// // DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
// //===================================================================================================
|
||||
// public override Task onQueryResponseRollback(Result errorResult)
|
||||
// {
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
// }
|
||||
|
||||
public class UserTestActorLog : ILogActor
|
||||
{
|
||||
}
|
||||
|
||||
// EntityBase를 상속 받은 Entity는 EntityAttributeBase와 EntityActionBase를 상속받아 자동으로 만들어진 Attribute들과 Action들을 가지고 있습니다.
|
||||
// 위 내용은 onInit()에서 직접 생성해서 초기화 한다.
|
||||
|
||||
|
||||
public class DynamoDbExample
|
||||
{
|
||||
private readonly DynamoDbClient m_dynamo_db_client;
|
||||
private readonly UserTestEntity m_user_entity;
|
||||
|
||||
public DynamoDbExample(DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
m_dynamo_db_client = dynamoDbClient;
|
||||
m_user_entity = new UserTestEntity();
|
||||
}
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> insertUser(string userId, string name)
|
||||
{
|
||||
await m_user_entity.onInit();
|
||||
var action = m_user_entity.getEntityAction<UserTestInsertAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(action,
|
||||
() => $"UserTestInsertAction is null !!! - {m_user_entity.toBasicString()}");
|
||||
var (result, user_test_doc) = await action.tryInsertUser(userId, name, m_dynamo_db_client);
|
||||
return (result, user_test_doc);
|
||||
}
|
||||
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> findUserOne(string userId)
|
||||
{
|
||||
await m_user_entity.onInit();
|
||||
var action = m_user_entity.getEntityAction<UserTestFindOneAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(action,
|
||||
() => $"UserTestInsertAction is null !!! - {m_user_entity.toBasicString()}");
|
||||
return await action.findUserOne(userId, m_dynamo_db_client);
|
||||
}
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> updateUser(string userId, string newName)
|
||||
{
|
||||
await m_user_entity.onInit();
|
||||
var action = m_user_entity.getEntityAction<UserTestUpdateOneAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(action,
|
||||
() => $"UserTestUpdateOneAction is null !!! - {m_user_entity.toBasicString()}");
|
||||
return await action.updateOne(userId, newName, m_dynamo_db_client);
|
||||
}
|
||||
|
||||
public async Task<Result> DeleteUserOne(string userId)
|
||||
{
|
||||
await m_user_entity.onInit();
|
||||
var action = m_user_entity.getEntityAction<UserTestDeleteOneAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(action,
|
||||
() => $"UserTestDeleteOneAction is null !!! - {m_user_entity.toBasicString()}");
|
||||
return await action.deleteOne(userId, m_dynamo_db_client);
|
||||
}
|
||||
}
|
||||
92
BrokerApiTest/DocQuery/DynamoDbClientTests.cs
Normal file
92
BrokerApiTest/DocQuery/DynamoDbClientTests.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
namespace PlatformTest.DbQuery;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Xunit;
|
||||
using Amazon.DynamoDBv2;
|
||||
using Amazon.DynamoDBv2.Model;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
public class DynamoDbClientTests
|
||||
{
|
||||
private ServerConfig? m_config;
|
||||
private string m_config_path = "../Config/Config.json";
|
||||
private string m_nlog_config_path = "../Config/nlog.config";
|
||||
|
||||
public DynamoDbClientTests()
|
||||
{
|
||||
Log.NLogFileName = m_nlog_config_path;
|
||||
m_config = new ServerConfig();
|
||||
m_config_path = Path.GetFullPath(m_config_path);
|
||||
m_config.setConfigFilePath(m_config_path);
|
||||
m_config.tryLoadConfig().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task connectToDb_ShouldConnectSuccessfully()
|
||||
{
|
||||
NullReferenceCheckHelper.throwIfNull(m_config);
|
||||
var dynamo_db_client = new DynamoDbClient();
|
||||
|
||||
// Act
|
||||
(var error_code, var to_load_table_names) = ServerConfigHelper.getDynamoDbTableNamesWithServiceType(m_config.ServiceType);
|
||||
if (error_code.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to DynamoDbClient.getDynamoDbTableNameWithServiceType() !!!";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var result = dynamo_db_client.connectToDb( to_load_table_names
|
||||
, m_config.AWS.LocalDynamoDB, m_config.Dynamodb
|
||||
, m_config.AWS.AccessKey, m_config.AWS.SecretKey, m_config.AWS.Region);
|
||||
if (result.isFail())
|
||||
{
|
||||
Log.getLogger().error($"Failed to connectToDb !!! ");
|
||||
return;
|
||||
}
|
||||
|
||||
// Assert
|
||||
await Task.CompletedTask;
|
||||
Assert.True(result.isSuccess());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateDBIfNotExists_ShouldCreateTable()
|
||||
{
|
||||
NullReferenceCheckHelper.throwIfNull(m_config);
|
||||
|
||||
var dynamo_db_client = new DynamoDbClient();
|
||||
|
||||
(var error_code, var to_load_table_names) = ServerConfigHelper.getDynamoDbTableNamesWithServiceType(m_config.ServiceType);
|
||||
if (error_code.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to DynamoDbClient.getDynamoDbTableNameWithServiceType() !!!";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var result = dynamo_db_client.connectToDb(to_load_table_names
|
||||
, m_config.AWS.LocalDynamoDB, m_config.Dynamodb
|
||||
, m_config.AWS.AccessKey, m_config.AWS.SecretKey, m_config.AWS.Region);
|
||||
if (result.isFail())
|
||||
{
|
||||
Log.getLogger().error($"Failed to connectToDb !!! ");
|
||||
return;
|
||||
}
|
||||
|
||||
// Act
|
||||
var is_success = await dynamo_db_client.createDBIfNotExists(false);
|
||||
|
||||
// Assert
|
||||
Assert.True(is_success);
|
||||
}
|
||||
}
|
||||
111
BrokerApiTest/DocQuery/EntityBaseTests.cs
Normal file
111
BrokerApiTest/DocQuery/EntityBaseTests.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
namespace PlatformTest.DbQuery;
|
||||
|
||||
using Amazon;
|
||||
using Amazon.DynamoDBv2;
|
||||
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
public class EntityBaseTests
|
||||
{
|
||||
private readonly DynamoDbClient m_dynamo_db_client;
|
||||
|
||||
public EntityBaseTests()
|
||||
{
|
||||
m_dynamo_db_client = new DynamoDbClient();
|
||||
|
||||
(var error_code, var table_names) = ServerConfigHelper.getDynamoDbTableNamesWithServiceType("Dev");
|
||||
ConditionValidCheckHelper.throwIfFalseWithCondition(() => ServerErrorCode.Success == error_code
|
||||
, () => $"Failed to ServerConfigHelper.getDynamoDbTableNamesWithServiceType() !!! : errorCode:{error_code}");
|
||||
|
||||
var result = m_dynamo_db_client.connectToDb(table_names, true, "http://localhost:8000", "local", "local");
|
||||
if (result.isFail())
|
||||
{
|
||||
Log.getLogger().error($"Failed to connectToDb !!! ");
|
||||
return;
|
||||
}
|
||||
Log.getLogger().info($"Success connectToDb !!!");
|
||||
}
|
||||
|
||||
internal async Task initDynamoDbClient()
|
||||
{
|
||||
if (false == await m_dynamo_db_client.createDBIfNotExists(false))
|
||||
{
|
||||
// err_msg = $"Failed to create DB Table !!! - {toBasicString()}";
|
||||
// result.setFail(ServerErrorCode.DynamoDbTableCreateFailed, err_msg);
|
||||
Log.getLogger().fatal("Failed to create DB Table !!!");
|
||||
// return result;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task entityInsertActionTest()
|
||||
{
|
||||
await initDynamoDbClient();
|
||||
var user_entity = new UserTestEntity();
|
||||
await user_entity.onInit();
|
||||
|
||||
user_entity.getEntityAction<UserTestInsertAction>();
|
||||
var user_id = Guid.NewGuid().ToString();
|
||||
var name = $"name_{user_id}";
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EntityFindOneActionTest()
|
||||
{
|
||||
await initDynamoDbClient();
|
||||
var user_entity = new UserTestEntity();
|
||||
await user_entity.onInit();
|
||||
|
||||
user_entity.getEntityAction<UserTestFindOneAction>();
|
||||
|
||||
|
||||
// var example = new DynamoDbExample(m_dynamo_db_client);
|
||||
var user_id = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task entityBaseTest()
|
||||
{
|
||||
await initDynamoDbClient();
|
||||
var example = new DynamoDbExample(m_dynamo_db_client);
|
||||
var user_id = Guid.NewGuid().ToString();
|
||||
var name = $"name_{user_id}";
|
||||
|
||||
//=====================================================================================
|
||||
// Insert
|
||||
//=====================================================================================
|
||||
var (result, user_test_doc) = await example.insertUser(user_id, name);
|
||||
Assert.True(result.isSuccess());
|
||||
var user_test_attrib = user_test_doc?.getAttrib<UserTestAttrib>();
|
||||
Assert.NotNull(user_test_attrib);
|
||||
Assert.True(user_test_attrib.UserId == user_id);
|
||||
Assert.True(user_test_attrib.Name == name);
|
||||
|
||||
|
||||
var (find_result, user_test_find_doc) = await example.findUserOne(user_id);
|
||||
Assert.True(find_result.isSuccess());
|
||||
Assert.NotNull(find_result);
|
||||
Assert.NotNull(user_test_find_doc);
|
||||
Assert.True(user_test_find_doc.getAttrib<UserTestAttrib>()?.UserId == user_id);
|
||||
Assert.True(user_test_find_doc.getAttrib<UserTestAttrib>()?.Name == name);
|
||||
|
||||
var new_name = $"name_{user_id}_2";
|
||||
var (update_result, user_test_update_doc) = await example.updateUser(user_id, new_name);
|
||||
Assert.True(update_result.isSuccess());
|
||||
|
||||
var (find_result2, user_test_update_doc2) = await example.findUserOne(user_id);
|
||||
Assert.True(find_result2.isSuccess());
|
||||
Assert.NotNull(user_test_update_doc2);
|
||||
Assert.True(user_test_update_doc2.getAttrib<UserTestAttrib>()?.UserId == user_id);
|
||||
Assert.True(user_test_update_doc2.getAttrib<UserTestAttrib>()?.Name == new_name);
|
||||
|
||||
var delete_result = await example.DeleteUserOne(user_id);
|
||||
Assert.True(delete_result.isSuccess());
|
||||
|
||||
var (find_result3, user_test_delete_doc) = await example.findUserOne(user_id);
|
||||
Assert.Null(user_test_delete_doc);
|
||||
Assert.True(find_result3.isFail());
|
||||
}
|
||||
}
|
||||
34
BrokerApiTest/DocQuery/UserTestAttrib.cs
Normal file
34
BrokerApiTest/DocQuery/UserTestAttrib.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
public class UserTestAttrib : AttribBase
|
||||
{
|
||||
[JsonProperty("user_id")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public UserTestAttrib(UserTestEntity owner) : base(nameof(UserTestAttrib))
|
||||
{
|
||||
}
|
||||
|
||||
public UserTestAttrib()
|
||||
: base(nameof(UserTestAttrib))
|
||||
{
|
||||
}
|
||||
|
||||
public UserTestAttrib(string userId, string name) : base(nameof(UserTestAttrib))
|
||||
{
|
||||
UserId = userId;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public void set(UserTestAttrib attrib)
|
||||
{
|
||||
UserId = attrib.UserId;
|
||||
Name = attrib.Name;
|
||||
}
|
||||
}
|
||||
31
BrokerApiTest/DocQuery/UserTestDeleteOneAction.cs
Normal file
31
BrokerApiTest/DocQuery/UserTestDeleteOneAction.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace PlatformTest.DbQuery;
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
public class UserTestDeleteOneAction : EntityActionBase
|
||||
{
|
||||
public UserTestDeleteOneAction(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Task<Result> onInit()
|
||||
{
|
||||
return Task.FromResult(new Result());
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<Result> deleteOne(string userId, DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
var user_test_doc = new UserTestDoc(userId);
|
||||
user_test_doc.setQueryType(QueryType.Delete);
|
||||
var result = await dynamoDbClient.simpleDeleteDocumentWithDocType(user_test_doc);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
92
BrokerApiTest/DocQuery/UserTestDoc.cs
Normal file
92
BrokerApiTest/DocQuery/UserTestDoc.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
// DynamoDbDocBase는 리파지토리로 이해하면 편할 듯
|
||||
// AttribBase: db에 저장될 데이터
|
||||
public sealed class UserTestDoc : DynamoDbDocBase
|
||||
{
|
||||
private const string m_prefix_of_pk = "user_test#";
|
||||
private const string m_prefix_of_sk = "";
|
||||
public UserTestDoc() : base(nameof(UserTestDoc))
|
||||
{
|
||||
// doc에 저장되는 attrib을 생성한다.
|
||||
appendAttribWrapper(new AttribWrapper<UserTestAttrib>());
|
||||
}
|
||||
|
||||
public UserTestDoc(string userId, string name = "") : base(nameof(UserTestDoc))
|
||||
{
|
||||
// doc에 저장되는 attrib을 생성한다.
|
||||
appendAttribWrapper(new AttribWrapper<UserTestAttrib>());
|
||||
|
||||
// prefix를 제외한 key를 설정정한다.
|
||||
setCombinationKeyForPK(userId);
|
||||
|
||||
// 파티션 키와 소트 키를 안전하게 설정한다.
|
||||
// 이 과정에서 onCheckAndSetPK, onCheckAndSetSK 메소드가 호출된다.
|
||||
fillUpPrimaryKey(onMakePK(), onMakeSK());
|
||||
|
||||
// 기본 값 설정
|
||||
var attrib = getAttrib<UserTestAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(attrib, () => $"attrib is null !!! - {toBasicString()}");
|
||||
attrib.UserId = userId;
|
||||
attrib.Name = name;
|
||||
}
|
||||
|
||||
public async Task<Result> insertUser(DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
var result = await dynamoDbClient.simpleInsertDocumentWithDocType(this);
|
||||
if (result.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to insertUser() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.getLogger().info($"Insert User Test !!! - {this.toBasicString()}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> findOne(DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
var config = dynamoDbClient.makeQueryConfigForReadByPKOnly(getPK());
|
||||
var (result, result_doc) = await dynamoDbClient.simpleQueryDocTypeWithQueryOperationConfig<UserTestDoc>(config);
|
||||
if (result.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to simpleQueryDocTypesWithQueryOperationConfig() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
return (result, result_doc);
|
||||
}
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> updateOne(DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
setQueryType(QueryType.Update);
|
||||
var result = await dynamoDbClient.simpleUpdateDocumentWithDocType(this);
|
||||
if (result.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to simpleUpdateDocumentWithDocType() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
Log.getLogger().info($"Insert User Test !!! - {this.toBasicString()}");
|
||||
return (result, this);
|
||||
}
|
||||
|
||||
protected override string onGetPrefixOfPK() => m_prefix_of_pk;
|
||||
protected override string onGetPrefixOfSK() => m_prefix_of_sk;
|
||||
|
||||
protected override ServerErrorCode onCheckAndSetPK(string partitionKey)
|
||||
{
|
||||
getPrimaryKey().fillUpPK(partitionKey);
|
||||
return ServerErrorCode.Success;
|
||||
}
|
||||
|
||||
protected override ServerErrorCode onCheckAndSetSK(string sortKey)
|
||||
{
|
||||
return ServerErrorCode.Success;
|
||||
}
|
||||
}
|
||||
53
BrokerApiTest/DocQuery/UserTestEntity.cs
Normal file
53
BrokerApiTest/DocQuery/UserTestEntity.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using PlatformTest.DbQuery;
|
||||
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
// EntityBase: EntityAttribute와 EntityAction을 관리하는 컨테이너
|
||||
public class UserTestEntity : EntityBase, IWithLogActor
|
||||
{
|
||||
// EntityType은 어디에 쓰는 걸까? 아마도 로그?
|
||||
|
||||
public UserTestEntity() : base(EntityType.Golbal)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
base.onCearAll();
|
||||
// EntityAttribute, EntityAction 생성
|
||||
addEntityAttribute(new UserTestEntityAttribute(this));
|
||||
addEntityAction(new UserTestInsertAction(this));
|
||||
addEntityAction(new UserTestFindOneAction(this));
|
||||
addEntityAction(new UserTestUpdateOneAction(this));
|
||||
addEntityAction(new UserTestDeleteOneAction(this));
|
||||
var result = await base.onInit();
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void onCearAll()
|
||||
{
|
||||
base.onCearAll();
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"{this.getTypeName()}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
return $"{this.getTypeName()}";
|
||||
}
|
||||
|
||||
public ILogActor toLogActor()
|
||||
{
|
||||
// 그냥 나중에 로거를 꺼내서 처리하는 듯 하다.
|
||||
return new UserTestActorLog();
|
||||
}
|
||||
}
|
||||
118
BrokerApiTest/DocQuery/UserTestEntityAttribute.cs
Normal file
118
BrokerApiTest/DocQuery/UserTestEntityAttribute.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
using ThirdParty.Json.LitJson;
|
||||
|
||||
// EntityAttributeBase를 상속 받은 개체는 메모리에 사용될 내용임
|
||||
// 스토리지에 저장은 UsrTestDoc:DynamoDbDocBase에서 처리함
|
||||
public class UserTestEntityAttribute : EntityAttributeBase
|
||||
{
|
||||
[JsonProperty] public string UserId { get; set; } = string.Empty;
|
||||
[JsonProperty] public string Name { get; set; } = string.Empty;
|
||||
|
||||
public UserTestEntityAttribute(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override UserTestDoc onCreateDocBase()
|
||||
{
|
||||
return new UserTestDoc(UserId, Name);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
UserId = string.Empty;
|
||||
Name = string.Empty;
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
//=====================================================================================
|
||||
// try_pending_doc은 없으면 새로 생성하고 초기화 한다.
|
||||
//=====================================================================================
|
||||
if (getTryPendingDocBase() is not UserTestDoc try_pending_doc)
|
||||
{
|
||||
var new_pending_doc = new UserTestDoc();
|
||||
var origin_doc = getOriginDocBase<UserTestEntityAttribute>();
|
||||
if (origin_doc is not null)
|
||||
{
|
||||
new_pending_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
setTryPendingDocBase(new_pending_doc);
|
||||
try_pending_doc = (getTryPendingDocBase() as UserTestDoc)!;
|
||||
NullReferenceCheckHelper.throwIfNull(try_pending_doc, () => $"try_pending_doc is null !!!");
|
||||
}
|
||||
|
||||
var to_copy_user_test_attrib = try_pending_doc.getAttrib<UserTestAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_user_test_attrib, () => $"to_copy_user_test_attrib is null !!!");
|
||||
to_copy_user_test_attrib.UserId = UserId;
|
||||
to_copy_user_test_attrib.Name = Name;
|
||||
|
||||
|
||||
// 읽기 용도가 아닌 경우
|
||||
if (false == isForQuery)
|
||||
{
|
||||
return (result, try_pending_doc);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// Doc QueryType 반영
|
||||
//=====================================================================================
|
||||
(result, var to_query_doc) = await applyDoc4Query(try_pending_doc);
|
||||
return result.isFail() ? (result, null) : (result, to_query_doc);
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new UserTestEntityAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var owner = getOwner() as UserTestEntity;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
return new UserTestEntityAttribute(owner) { UserId = UserId, Name = Name };
|
||||
}
|
||||
|
||||
private class UserTestEntityAttributeTransactor : EntityAttributeTransactorBase<UserTestEntityAttribute>,
|
||||
ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public UserTestEntityAttributeTransactor(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttribute)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = nameof(UserTestEntityAttribute);
|
||||
|
||||
if (entityAttribute is not UserTestEntityAttribute copy_from_user_test_attribute)
|
||||
{
|
||||
err_msg =
|
||||
$"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_user_test_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 롤백을 위해 객체를 복사한다.
|
||||
if (getClonedEntityAttribute() is not UserTestEntityAttribute copy_to_user_test_attribute)
|
||||
{
|
||||
err_msg =
|
||||
$"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_user_test_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_user_test_attribute.UserId = copy_from_user_test_attribute.UserId;
|
||||
copy_to_user_test_attribute.Name = copy_from_user_test_attribute.Name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
BrokerApiTest/DocQuery/UserTestFindOneAction.cs
Normal file
38
BrokerApiTest/DocQuery/UserTestFindOneAction.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
public class UserTestFindOneAction : EntityActionBase
|
||||
{
|
||||
public UserTestFindOneAction(UserTestEntity owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> findUserOne(string userId, DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(dynamoDbClient,
|
||||
() => $"dynamoDbClient is null !!! - {getOwner().toBasicString()}");
|
||||
var doc = new UserTestDoc(userId);
|
||||
var (result, result_doc) = await doc.findOne(dynamoDbClient);
|
||||
return (result, result_doc);
|
||||
}
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> findUserOne2(string userId, DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(dynamoDbClient,
|
||||
() => $"dynamoDbClient is null !!! - {getOwner().toBasicString()}");
|
||||
var config = dynamoDbClient.makeQueryConfigForReadByPKOnly(userId);
|
||||
var (result, doc) = await dynamoDbClient.simpleQueryDocTypeWithQueryOperationConfig<UserTestDoc>(config);
|
||||
return (result, doc);
|
||||
}
|
||||
}
|
||||
29
BrokerApiTest/DocQuery/UserTestInsertAction.cs
Normal file
29
BrokerApiTest/DocQuery/UserTestInsertAction.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
public class UserTestInsertAction : EntityActionBase
|
||||
{
|
||||
public UserTestInsertAction(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
}
|
||||
|
||||
// 실제 할 일을 정의한다.
|
||||
public async Task<(Result, UserTestDoc)> tryInsertUser(string userId, string name, DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
ArgumentNullReferenceCheckHelper.throwIfNull(dynamoDbClient, () => $"dynamoDbClient is null !!! - {getOwner().toBasicString()}");
|
||||
var doc = new UserTestDoc(userId, name);
|
||||
var result = await doc.insertUser(dynamoDbClient);
|
||||
return (result, doc);
|
||||
}
|
||||
}
|
||||
26
BrokerApiTest/DocQuery/UserTestUpdateOneAction.cs
Normal file
26
BrokerApiTest/DocQuery/UserTestUpdateOneAction.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
public class UserTestUpdateOneAction : EntityActionBase
|
||||
{
|
||||
public UserTestUpdateOneAction(UserTestEntity owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<(Result, UserTestDoc?)> updateOne(string userId, string userName, DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
var doc = new UserTestDoc(userId, userName);
|
||||
return await doc.updateOne(dynamoDbClient);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user