Files
caliverse_server/BrokerApiCore/Entity/Helpers/EntityHelper.cs
2025-05-01 07:23:28 +09:00

33 lines
879 B
C#

using ServerBase;
namespace BrokerApiCore;
public static class EntityHelper
{
public static async Task<(Result, TDoc?)> findDocByPk<TDoc>(string pk, EntityBase owner, DynamoDbClient dynamoDbClient)
where TDoc : DynamoDbDocBase, new()
{
ArgumentNullException.ThrowIfNull(owner, $"owner is null !!!");
var (result, user_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<TDoc>(pk);
if (result.isFail())
{
return (result, null);
}
ArgumentNullException.ThrowIfNull(user_primary_key, $"user_primary_key is null !!! - {owner.toBasicString()}");
var query_config = dynamoDbClient.makeQueryConfigForReadByPKSK(user_primary_key.PK);
(result, var found_doc) =
await dynamoDbClient.simpleQueryDocTypeWithQueryOperationConfig<TDoc>(query_config, false);
if (result.isFail())
{
return (result, null);
}
return (result, found_doc);
}
}