using JiDangJia.Contracts;
using System.Text.Json;
namespace JiDangJia.Services;
public sealed class LegalConsentRequiredException(string message="请分别勾选同意三项条款后继续") : InvalidOperationException(message);
public sealed partial class AuthClient
{
private static void RequireLegalConsent(LegalConsent? consent)
{if(!LegalPolicyRules.AllAccepted(consent))throw new LegalConsentRequiredException();}
public async Task<LegalPolicies> LegalPolicies()
{
using var response=await Request("/legal",auth:false);
return response.RootElement.Deserialize<LegalPolicies>(communityJson)??throw new InvalidOperationException("协议加载失败,请重试");
}
public async Task<LegalDocument> PublishLegal(string key,PublishLegalRequest request)
{
using var response=await AdminRequest("/legal/"+Uri.EscapeDataString(key),request);
return response.RootElement.Deserialize<LegalDocument>(communityJson)??throw new InvalidOperationException("发布响应无效");
}
public async Task<List<LegalVersionInfo>> LegalHistory(string key,long before=0)
{
using var response=await AdminRequest("/legal/"+Uri.EscapeDataString(key)+"/versions?before="+before);
return response.RootElement.Deserialize<List<LegalVersionInfo>>(communityJson)??[];
}
public async Task<LegalDocument> LegalVersion(string key,long version)
{
using var response=await AdminRequest("/legal/"+Uri.EscapeDataString(key)+"/versions/"+version);
return response.RootElement.Deserialize<LegalDocument>(communityJson)??throw new InvalidOperationException("协议版本响应无效");
}
public async Task<LegalAcceptanceStatus> LegalStatus()
{
using var response=await Request("/user/legal");
return response.RootElement.Deserialize<LegalAcceptanceStatus>(communityJson)??throw new InvalidOperationException("同意记录响应无效");
}
}
using JiDangJia.Contracts;
using System.Text.Json;
namespace JiDangJia.Services;
public sealed class LegalConsentRequiredException(string message="请分别勾选同意三项条款后继续") : InvalidOperationException(message);
public sealed partial class AuthClient
{
private static void RequireLegalConsent(LegalConsent? consent)
{if(!LegalPolicyRules.AllAccepted(consent))throw new LegalConsentRequiredException();}
public async Task<LegalPolicies> LegalPolicies()
{
using var response=await Request("/legal",auth:false);
return response.RootElement.Deserialize<LegalPolicies>(communityJson)??throw new InvalidOperationException("协议加载失败,请重试");
}
public async Task<LegalDocument> PublishLegal(string key,PublishLegalRequest request)
{
using var response=await AdminRequest("/legal/"+Uri.EscapeDataString(key),request);
return response.RootElement.Deserialize<LegalDocument>(communityJson)??throw new InvalidOperationException("发布响应无效");
}
public async Task<List<LegalVersionInfo>> LegalHistory(string key,long before=0)
{
using var response=await AdminRequest("/legal/"+Uri.EscapeDataString(key)+"/versions?before="+before);
return response.RootElement.Deserialize<List<LegalVersionInfo>>(communityJson)??[];
}
public async Task<LegalDocument> LegalVersion(string key,long version)
{
using var response=await AdminRequest("/legal/"+Uri.EscapeDataString(key)+"/versions/"+version);
return response.RootElement.Deserialize<LegalDocument>(communityJson)??throw new InvalidOperationException("协议版本响应无效");
}
public async Task<LegalAcceptanceStatus> LegalStatus()
{
using var response=await Request("/user/legal");
return response.RootElement.Deserialize<LegalAcceptanceStatus>(communityJson)??throw new InvalidOperationException("同意记录响应无效");
}
}