Skip to content

Commit

Permalink
Remove unecessary Route Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Kawtar Choubari committed Nov 1, 2023
1 parent 98e3320 commit eacacb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 43 deletions.
34 changes: 0 additions & 34 deletions app/api/views/[slug]/route.ts

This file was deleted.

24 changes: 15 additions & 9 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FooterSocials } from "@/config/navigation";
import { Repo, SocialPlatform } from "@/types";
import { SupabaseAdmin } from "./supabase";

export const fetchGithubRepos = async () => {
const response = await fetch("https://api.github.com/users/choubari/repos");
Expand Down Expand Up @@ -98,15 +99,20 @@ export const validateCaptcha = (response_key) => {
};

export async function getPostViews(slug: string) {
const response = await fetch(
`${process.env.NEXT_PUBLIC_APP_URL}/api/views/${slug}`
);
const data = await response.json();
return data;
const { data } = await SupabaseAdmin.from("posts")
.select("view_count")
.filter("slug", "eq", slug);
return {
total: data[0]?.view_count || null,
};
}
export async function incrementPostViews(slug: string) {
await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/views/${slug}`, {
method: "POST",
next: { revalidate: 10 },
});
try {
await SupabaseAdmin.rpc("increment_post_view", { post_slug: slug });
return {
message: `Successfully incremented post: ${slug}`,
};
} catch (error) {
return { error };
}
}

0 comments on commit eacacb6

Please sign in to comment.