You've already forked CC-Framework.BriskGameServer
163 lines
5.2 KiB
C#
163 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
/// <summary>
|
|
/// 玩家空间模块。
|
|
/// </summary>
|
|
public sealed class BriskSpaceModule
|
|
: BriskModuleBase
|
|
{
|
|
/// <summary>
|
|
/// 按玩家 ID 获取空间数据。
|
|
/// </summary>
|
|
public async Task<BriskSpaceView> GetByPlayerIdAsync(string playerId)
|
|
{
|
|
ValidatePlayerId(playerId);
|
|
|
|
return await ExecuteAsync(async context =>
|
|
{
|
|
var data = await context.HttpClient.GetDataAsync($"/spaces/{playerId}", null, true);
|
|
return BriskModelMapper.ToSpaceView(data);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按登录身份获取空间数据。
|
|
/// </summary>
|
|
public async Task<BriskSpaceView> GetByLoginIdentityAsync(string loginProvider, string loginUserId)
|
|
{
|
|
ValidateLoginIdentity(loginProvider, loginUserId);
|
|
|
|
return await ExecuteAsync(async context =>
|
|
{
|
|
var data = await context.HttpClient.GetDataAsync("/spaces/by-login", CreateLoginIdentityQuery(loginProvider, loginUserId), true);
|
|
return BriskModelMapper.ToSpaceView(data);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按玩家 ID 获取空间统计。
|
|
/// </summary>
|
|
public async Task<BriskSpaceStats> GetStatsByPlayerIdAsync(string playerId)
|
|
{
|
|
ValidatePlayerId(playerId);
|
|
|
|
return await ExecuteAsync(async context =>
|
|
{
|
|
var data = await context.HttpClient.GetDataAsync($"/spaces/{playerId}/stats", null, true);
|
|
return BriskModelMapper.ToSpaceStats(data);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按登录身份获取空间统计。
|
|
/// </summary>
|
|
public async Task<BriskSpaceStats> GetStatsByLoginIdentityAsync(string loginProvider, string loginUserId)
|
|
{
|
|
ValidateLoginIdentity(loginProvider, loginUserId);
|
|
|
|
return await ExecuteAsync(async context =>
|
|
{
|
|
var data = await context.HttpClient.GetDataAsync("/spaces/by-login/stats", CreateLoginIdentityQuery(loginProvider, loginUserId), true);
|
|
return BriskModelMapper.ToSpaceStats(data);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按玩家 ID 点赞空间。
|
|
/// </summary>
|
|
public async Task LikeByPlayerIdAsync(string playerId)
|
|
{
|
|
ValidatePlayerId(playerId);
|
|
await ExecuteAsync(async context =>
|
|
{
|
|
await context.HttpClient.PostJsonRawAsync($"/spaces/{playerId}/like", new Dictionary<string, object>(), true);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按玩家 ID 取消点赞空间。
|
|
/// </summary>
|
|
public async Task UnlikeByPlayerIdAsync(string playerId)
|
|
{
|
|
ValidatePlayerId(playerId);
|
|
await ExecuteAsync(async context =>
|
|
{
|
|
await context.HttpClient.SendDeleteJsonRawAsync($"/spaces/{playerId}/like", null, true);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按登录身份点赞空间。
|
|
/// </summary>
|
|
public async Task LikeByLoginIdentityAsync(string loginProvider, string loginUserId)
|
|
{
|
|
ValidateLoginIdentity(loginProvider, loginUserId);
|
|
await ExecuteAsync(async context =>
|
|
{
|
|
await context.HttpClient.PostJsonRawAsync("/spaces/by-login/like", new Dictionary<string, object>(), true, CreateLoginIdentityQuery(loginProvider, loginUserId));
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按登录身份取消点赞空间。
|
|
/// </summary>
|
|
public async Task UnlikeByLoginIdentityAsync(string loginProvider, string loginUserId)
|
|
{
|
|
ValidateLoginIdentity(loginProvider, loginUserId);
|
|
await ExecuteAsync(async context =>
|
|
{
|
|
await context.HttpClient.SendDeleteJsonRawAsync("/spaces/by-login/like", CreateLoginIdentityQuery(loginProvider, loginUserId), true);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新当前玩家自己的空间内容。
|
|
/// </summary>
|
|
public async Task UpdateMyAsync(object payload)
|
|
{
|
|
RequireNotNull(payload, nameof(payload));
|
|
|
|
await ExecuteAsync(async context =>
|
|
{
|
|
await context.HttpClient.SendPutJsonRawAsync(
|
|
"/spaces/me",
|
|
new Dictionary<string, object> { { "payload_json", payload } },
|
|
true);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取我的访客列表。
|
|
/// </summary>
|
|
public async Task<IReadOnlyList<BriskSpaceVisit>> GetMyVisitsAsync()
|
|
{
|
|
return await ExecuteAsync(async context =>
|
|
{
|
|
var data = await context.HttpClient.GetRawDataAsync("/spaces/me/visits", null, true);
|
|
return (IReadOnlyList<BriskSpaceVisit>)BriskModelMapper.ToSpaceVisits(data);
|
|
});
|
|
}
|
|
|
|
private static Dictionary<string, string> CreateLoginIdentityQuery(string loginProvider, string loginUserId)
|
|
{
|
|
return new Dictionary<string, string>
|
|
{
|
|
{ "login_provider", loginProvider },
|
|
{ "login_user_id", loginUserId }
|
|
};
|
|
}
|
|
|
|
private static void ValidatePlayerId(string playerId)
|
|
{
|
|
RequireNotEmpty(playerId, nameof(playerId));
|
|
}
|
|
|
|
private static void ValidateLoginIdentity(string loginProvider, string loginUserId)
|
|
{
|
|
RequireNotEmpty(loginProvider, nameof(loginProvider));
|
|
RequireNotEmpty(loginUserId, nameof(loginUserId));
|
|
}
|
|
}
|