155 lines
3.6 KiB
C#
155 lines
3.6 KiB
C#
using ServerBase;
|
|
|
|
|
|
namespace BrokerApiCore;
|
|
|
|
using ServerCommon;
|
|
|
|
//==========================================
|
|
// 유저의 인증 처리 Action 정의
|
|
//==========================================
|
|
public class UserAuthAction : EntityActionBase
|
|
{
|
|
private readonly DynamoDbClient m_dynamo_db_client;
|
|
|
|
public UserAuthAction(EntityBase owner, DynamoDbClient dynamoDbClient) : base(owner)
|
|
{
|
|
this.m_dynamo_db_client = dynamoDbClient;
|
|
}
|
|
|
|
public override Task<Result> onInit()
|
|
{
|
|
return Task.FromResult(new Result());
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<(Result, AccountBaseDoc?)> findAccountDoc(string accountId)
|
|
{
|
|
return await EntityHelper.findDocByPk<AccountBaseDoc>(accountId, getOwner(), m_dynamo_db_client);
|
|
}
|
|
|
|
public async Task<(Result, UserBaseDoc?)> findUserDoc(string userGuid)
|
|
{
|
|
return await EntityHelper.findDocByPk<UserBaseDoc>(userGuid, getOwner(), m_dynamo_db_client);
|
|
}
|
|
|
|
public async Task<(Result, NicknameDoc?)> findNicknameDoc(string nickname)
|
|
{
|
|
return await EntityHelper.findDocByPk<NicknameDoc>(nickname, getOwner(), m_dynamo_db_client);
|
|
}
|
|
|
|
public async Task<Result> findAndSetAllAttributeByAccountId(string accountId)
|
|
{
|
|
|
|
var result = await findAndSetAccount(accountId);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
var user_guid = getOwner().getEntityAttributeNotNull<AccountAttribute>().UserGuid;
|
|
result = await findAndSetUser(user_guid);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
result = await findAndSetNickName(user_guid);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<Result> findAndSetAllAttributeByUserGuid(string userGuid)
|
|
{
|
|
var result = await findAndSetUser(userGuid);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
result = await findAndSetNickName(userGuid);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
var account_id = getOwner().getEntityAttributeNotNull<UserAttribute>().AccountId;
|
|
result = await findAndSetAccount(account_id);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// account로 AccountDoc을 읽고, AccountAttribute에 저장한다.
|
|
public async Task<Result> findAndSetAccount(string accountId)
|
|
{
|
|
var (result, doc) = await findAccountDoc(accountId);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
if (doc is null)
|
|
{
|
|
result.setFail(ServerErrorCode.AccountIdInvalid, accountId);
|
|
return result;
|
|
}
|
|
|
|
var attribute = getOwner().getEntityAttributeNotNull<AccountAttribute>();
|
|
attribute.copyEntityAttributeFromDoc(doc);
|
|
return result;
|
|
}
|
|
|
|
// UserBaseDoc을 읽고 UserAttribute에 저장
|
|
public async Task<Result> findAndSetUser(string userGuid)
|
|
{
|
|
var (result, doc) = await findUserDoc(userGuid);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
if (doc is null)
|
|
{
|
|
result.setFail(ServerErrorCode.UserGuidInvalid,
|
|
$"userGuid:{userGuid} not found - {getOwner().toBasicString()}");
|
|
return result;
|
|
}
|
|
|
|
var attribute = getOwner().getEntityAttributeNotNull<UserAttribute>();
|
|
attribute.copyEntityAttributeFromDoc(doc);
|
|
return result;
|
|
}
|
|
|
|
// NicknameDoc을 읽고, NicknameAttribute에 저장
|
|
public async Task<Result> findAndSetNickName(string userGuid)
|
|
{
|
|
var (result, doc) = await findNicknameDoc(userGuid);
|
|
if (result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
if (doc is null)
|
|
{
|
|
result.setFail(ServerErrorCode.NotFoundNickName,
|
|
$"nickname not found by userGuid:{userGuid} - {getOwner().toBasicString()}");
|
|
return result;
|
|
}
|
|
|
|
var attribute = getOwner().getEntityAttributeNotNull<NicknameAttribute>();
|
|
attribute.copyEntityAttributeFromDoc(doc);
|
|
return result;
|
|
}
|
|
}
|