Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tasks]: 有关【新版 NMS.Github.SDK】相关功能的规划与任务细化 (意见搜集与讨论) #298

Open
6 of 7 tasks
NMSAzulX opened this issue May 24, 2024 · 4 comments
Labels
pause 暂停开发及其相关工作 tasks This is a tasklist.

Comments

@NMSAzulX
Copy link
Collaborator

NMSAzulX commented May 24, 2024

📃 计划清单 (Tasklist).

基于 .NET 版可靠的 GithubSDK

@NMSAzulX NMSAzulX added the tasks This is a tasklist. label May 24, 2024
@NMSAzulX
Copy link
Collaborator Author

NMSAzulX commented May 24, 2024

低级 API 案例

Query

//创建查询实例
 GithubQueryData query = new()
{
    repository = new GithubRepository("DotNetCore","Natasha")
    {
        issue = new(297)
        {
            title = "",
            url = "",
            id=""
        }
    }
};
//获取查询结果
var (data, msg) = await query.GetExecuteResultAsync();
var issue = data!.repository!.issue!;

Mutation 不获取实体结果

//创建方法实例
GithubMutationData add = new()
{
    addReaction = new(issue.id!, GithubReactionContent.HOORAY)
};

//获取方法结果
(var result, msg) = await add.GetExecuteStateAsync();
if (result)
{
    Console.WriteLine("succeed");
}
else
{
    Console.WriteLine(msg);
}

Mutation 获取实体结果

GithubMutationData remove = new()
{
    removeReaction = new(issue.id!, GithubReactionContent.HOORAY)
    {
        //创建返回体实例
        reaction = new()
        {
            id = "",
            content = 0,
            createdAt = DateTime.Now
        }
    }
};


//获取方法结果
(var reData, msg) = await remove.GetExecuteResultAsync();
if (reData != null)
{
    var reaction = reData!.removeReaction!.reaction!;
    Console.WriteLine("succeed");
    Console.WriteLine(reaction.id);
    Console.WriteLine(reaction.content);
    Console.WriteLine(reaction.createdAt);
}
else
{
    Console.WriteLine(msg);
}

@NMSAzulX
Copy link
Collaborator Author

NMSAzulX commented May 26, 2024

集合查询

GithubQueryData query = new()
{
    repository = new GithubRepository("DotNetCore", "Natasha")
    {
        //需要查询的集合
        labels = new GithubConnection<GithubLabel>()
        {
            nodes =
            [
                //创建一个元素:为了定义要查询返回的结构
                new GithubLabel()
                {
                    id = "",
                    name = "",
                }
            ]
        }
    }
};

//获取所有数据
var labels = await query.GetCollectionResultAsync(repository => repository!.labels!);

//获取最先的 5 个
var labels = await query.GetCollectionResultAsync(repository => repository!.labels!, 5);

//获取最后的 5 个
var labels = await query.GetCollectionResultAsync(repository => repository!.labels!, -5);

获取某集合总数

var count = await query.GetTotalAsync(repository => repository!.labels!);
Console.WriteLine(count);

@NMSAzulX
Copy link
Collaborator Author

NMSAzulX commented May 26, 2024

分页查询

GithubQueryData query = new()
{
    repository = new GithubRepository("DotNetCore", "Natasha")
    {
        //需要查询的集合
        labels = new GithubConnection<GithubLabel>()
        {
            nodes =
            [
                //创建一个元素:为了定义要查询返回的结构
                new GithubLabel()
                {
                    id = "",
                    name = "",
                }
            ]
        }
    }
};

//从第一页取 5 条数据
var labels = await query.GetCollectionResultAsync(repository => repository!.labels!, 5);

//自动设置下一页游标
query.repository!.labels.SetNextPage();

//从下一页取 5 条数据
labels = await query.GetCollectionResultAsync(repository => repository!.labels!, 5);

//查询重置
query.repository.labels.Reset();

//从排尾取 5 条数据
labels = await query.GetCollectionResultAsync(repository => repository!.labels!, -5);

//自动设置排尾的前一页
query.repository!.labels.SetNextPage();

//从前一页取 5 条数据
labels = await query.GetCollectionResultAsync(repository => repository!.labels!, -5);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pause 暂停开发及其相关工作 tasks This is a tasklist.
Projects
None yet
Development

No branches or pull requests

1 participant