Skip to content

Commit

Permalink
feat: get feed api
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 30, 2024
1 parent b21170b commit cc2f92f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/renderer/src/biz/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ export class UnprocessableEntityError extends RequestError {
super(message)
}
}

export class UnprocessableFeedError extends RequestError {
name = "UnprocessableEntityError"

constructor(message?: string) {
super(message)
}
}
33 changes: 33 additions & 0 deletions src/renderer/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,39 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
};
};
} & {
"/feeds": {
$get: {
input: {
query: {
id: string;
};
};
output: {
code: 0;
data: {
feed: {
description: string | null;
title: string | null;
id: string;
image: string | null;
url: string;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
etagHeader: string | null;
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
};
subscriptionCount: number;
readCount: number;
};
};
outputFormat: "json";
status: 200;
};
};
"/feeds/refresh": {
$get: {
input: {
Expand Down
38 changes: 38 additions & 0 deletions src/renderer/src/queries/feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
UnprocessableFeedError,
} from "@renderer/biz/error"
import { useBizQuery } from "@renderer/hooks/useBizQuery"
import { defineQuery } from "@renderer/lib/defineQuery"
import { apiClient } from "@renderer/queries/api-fetch"

export const feed = {
byId: (id?: string | null) =>
defineQuery(
["feed", id],
async () => {
if (!id) {
throw new UnprocessableFeedError("id is required")
}
const res = await apiClient.feeds.$get({
query: {
id,
},
})
const json = await res.json()

return json.data
},
{
rootKey: ["feed"],
},
),
}

export const useFeed = ({
id,
}: {
id?: string | null
}) =>
useBizQuery(feed.byId(id), {
enabled: !!id,
})

0 comments on commit cc2f92f

Please sign in to comment.