feat: 添加 GitHub 相关的 API 操作,包括获取、创建、更新和删除 starred 项目
This commit is contained in:
2
convex/_generated/api.d.ts
vendored
2
convex/_generated/api.d.ts
vendored
@@ -8,6 +8,7 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import type * as github_action from "../github/action.js";
|
||||
import type * as github_starrred from "../github/starrred.js";
|
||||
import type * as http from "../http.js";
|
||||
|
||||
@@ -18,6 +19,7 @@ import type {
|
||||
} from "convex/server";
|
||||
|
||||
declare const fullApi: ApiFromModules<{
|
||||
"github/action": typeof github_action;
|
||||
"github/starrred": typeof github_starrred;
|
||||
http: typeof http;
|
||||
}>;
|
||||
|
||||
67
convex/github/action.ts
Normal file
67
convex/github/action.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { query, mutation, action } from "../_generated/server.js";
|
||||
import { v } from "convex/values";
|
||||
|
||||
export const getList = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const results = await ctx.db.query("github_starred").collect();
|
||||
return results;
|
||||
},
|
||||
});
|
||||
|
||||
export const createStarred = mutation({
|
||||
args: {
|
||||
repo_id: v.number(),
|
||||
title: v.string(),
|
||||
description: v.string(),
|
||||
author: v.string(),
|
||||
stars: v.number(),
|
||||
last_updated: v.string(),
|
||||
link: v.string(),
|
||||
auto: v.optional(v.string()),
|
||||
summary: v.optional(v.string()),
|
||||
tags: v.optional(v.array(v.string())),
|
||||
},
|
||||
handler: async (ctx, values) => {
|
||||
const repo_id = values.repo_id;
|
||||
const existing = await ctx.db.query("github_starred").withIndex("by_repo_id", (q) =>
|
||||
q.eq("repo_id", repo_id)
|
||||
).first();
|
||||
if (existing) {
|
||||
// 更新已有记录
|
||||
const updated = await ctx.db.patch("github_starred", existing._id, values);
|
||||
return updated;
|
||||
}
|
||||
// 创建新记录
|
||||
const result = await ctx.db.insert("github_starred", values);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
export const updateById = mutation({
|
||||
args: {
|
||||
id: v.id("github_starred"),
|
||||
repo_id: v.number(),
|
||||
title: v.string(),
|
||||
description: v.string(),
|
||||
author: v.string(),
|
||||
stars: v.number(),
|
||||
last_updated: v.string(),
|
||||
link: v.string(),
|
||||
auto: v.optional(v.string()),
|
||||
summary: v.optional(v.string()),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const { id, ...rest } = args;
|
||||
await ctx.db.patch(id, rest);
|
||||
},
|
||||
});
|
||||
|
||||
export const deleteById = mutation({
|
||||
args: {
|
||||
id: v.id("github_starred"),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
await ctx.db.delete(args.id);
|
||||
},
|
||||
});
|
||||
@@ -4,16 +4,17 @@ import { v } from "convex/values";
|
||||
export default defineSchema({
|
||||
// Other tables here...
|
||||
github_starred: defineTable({
|
||||
author: v.string(),
|
||||
auto: v.string(),
|
||||
repo_id: v.number(),
|
||||
title: v.string(),
|
||||
description: v.string(),
|
||||
author: v.string(),
|
||||
stars: v.number(),
|
||||
last_updated: v.string(),
|
||||
link: v.string(),
|
||||
repo_id: v.float64(),
|
||||
stars: v.float64(),
|
||||
summary: v.string(),
|
||||
title: v.string(),
|
||||
}),
|
||||
auto: v.optional(v.string()),
|
||||
summary: v.optional(v.string()),
|
||||
}).index("by_repo_id", ["repo_id"])
|
||||
.index("by_title", ["title"]),
|
||||
users: defineTable({
|
||||
userId: v.string(), // 外部系统的用户 ID
|
||||
name: v.string(),
|
||||
|
||||
Reference in New Issue
Block a user