Add delete link functionality in frontend

This commit is contained in:
2025-12-24 14:02:36 +00:00
parent c56ea8b90f
commit 52d1984478
6 changed files with 171 additions and 44 deletions

View File

@@ -1,6 +1,7 @@
import axios from "axios";
const API_BASE_URL = "http://localhost:8080";
const FRONTEND_BASE_URL = "http://localhost:3000";
export async function shortenLink(longUrl: string): Promise<{
shortUrl: string;
@@ -18,10 +19,41 @@ export async function shortenLink(longUrl: string): Promise<{
title: string;
createdAt: string;
clicks: number;
} = res.data
} = res.data;
return {
shortUrl: API_BASE_URL + "/l/" + sl.code,
manageUrl: API_BASE_URL + "/l/" + sl.code + "/manage",
manageUrl: FRONTEND_BASE_URL + "/manage/" + sl.id,
}
}
export async function getLinkInfo(id: string): Promise<{
shortUrl: string;
manageUrl: string;
title: string;
createdAt: string;
clicks: number;
}> {
let res = await axios.get(API_BASE_URL + "/l/info/" + id);
let sl: {
id: string;
url: string;
code: string;
title: string;
createdAt: string;
clicks: number;
} = res.data;
return {
title: sl.title,
shortUrl: API_BASE_URL + "/l/" + sl.code,
manageUrl: FRONTEND_BASE_URL + "/manage/" + sl.id,
createdAt: sl.createdAt,
clicks: sl.clicks,
}
}
export async function deleteLink(id: string): Promise<void> {
await axios.delete(API_BASE_URL + "/l/" + id);
}