116 lines
3.1 KiB
C#
116 lines
3.1 KiB
C#
using Newtonsoft.Json;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
|
|
|
|
namespace ServerCommon;
|
|
|
|
public class BlockUserAttrib : AttribBase
|
|
{
|
|
[JsonProperty("guid")]
|
|
public string BlockGuid { get; set; } = string.Empty;
|
|
|
|
[JsonProperty("is_new")]
|
|
public Int32 IsNew { get; set; } = 0;
|
|
|
|
public void cloneAttrib(ref BlockUserAttrib attrib)
|
|
{
|
|
attrib.BlockGuid = BlockGuid;
|
|
attrib.IsNew = IsNew;
|
|
}
|
|
|
|
public BlockUserAttrib()
|
|
: base(typeof(BlockUserAttrib).Name)
|
|
{ }
|
|
}
|
|
|
|
|
|
//=============================================================================================
|
|
// PK(Partition Key) : "block#owner_guid"
|
|
// SK(Sort Key) : "block_user_guid"
|
|
// DocType : BlockUserDoc
|
|
// BlockUserAttrib : {}
|
|
// ...
|
|
//=============================================================================================
|
|
public class BlockUserDoc : DynamoDbDocBase
|
|
{
|
|
public BlockUserDoc()
|
|
: base(typeof(BlockUserDoc).Name)
|
|
{
|
|
appendAttribWrapper(new AttribWrapper<BlockUserAttrib>());
|
|
}
|
|
|
|
public BlockUserDoc(string userGuid, string blockGuid)
|
|
: base(typeof(BlockUserDoc).Name)
|
|
{
|
|
setCombinationKeyForPK(userGuid);
|
|
setCombinationKeyForSK(blockGuid);
|
|
|
|
fillUpPrimaryKey(onMakePK(), onMakeSK());
|
|
appendAttribWrapper(new AttribWrapper<BlockUserAttrib>());
|
|
}
|
|
|
|
|
|
protected override string onGetPrefixOfPK()
|
|
{
|
|
return "block#";
|
|
}
|
|
|
|
protected override string onGetPrefixOfSK()
|
|
{
|
|
return "";
|
|
}
|
|
|
|
protected override string onMakePK()
|
|
{
|
|
return $"{onGetPrefixOfPK()}{getCombinationKeyForPK()}";
|
|
}
|
|
|
|
protected override string onMakeSK()
|
|
{
|
|
return $"{onGetPrefixOfSK()}{getCombinationKeyForSK()}";
|
|
|
|
}
|
|
|
|
protected override ServerErrorCode onCheckAndSetPK(string pk)
|
|
{
|
|
getPrimaryKey().fillUpPK(pk);
|
|
return ServerErrorCode.Success;
|
|
}
|
|
|
|
protected override ServerErrorCode onCheckAndSetSK(string sortKey)
|
|
{
|
|
getPrimaryKey().fillUpSK(sortKey);
|
|
return ServerErrorCode.Success;
|
|
}
|
|
|
|
|
|
public static async Task<(Result, List<BlockUserDoc>)> findBlockUserFromGuid(string ownerGuid, string otherGuid)
|
|
{
|
|
var result = new Result();
|
|
var block_docs = new List<BlockUserDoc>();
|
|
|
|
var server_logic = ServerLogicApp.getServerLogicApp();
|
|
var dynamo_db_client = server_logic.getDynamoDbClient();
|
|
|
|
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<BlockUserDoc>(ownerGuid, otherGuid);
|
|
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!!");
|
|
if (result.isFail())
|
|
{
|
|
return (result, block_docs);
|
|
}
|
|
|
|
var query_config = dynamo_db_client.makeQueryConfigForReadByPKSK(make_primary_key.PK, make_primary_key.SK);
|
|
|
|
(result, block_docs) = await dynamo_db_client.simpleQueryDocTypesWithQueryOperationConfig<BlockUserDoc>(query_config);
|
|
if (result.isFail())
|
|
{
|
|
return (result, block_docs);
|
|
}
|
|
|
|
return (result, block_docs);
|
|
}
|
|
}
|