Add new gettallfeed api
This commit is contained in:
@@ -3,8 +3,8 @@ import { toast } from 'sonner';
|
|||||||
import { getToken, clearToken } from './auth';
|
import { getToken, clearToken } from './auth';
|
||||||
|
|
||||||
// Set up API base URLs
|
// Set up API base URLs
|
||||||
const USER_DATA_API_URL = 'https://io-userdata.monasefloadbalancer.ir';
|
const USER_DATA_API_URL = 'http://127.0.0.1:5001';
|
||||||
const DATA_API_URL = 'https://io-data.monasefloadbalancer.ir/api';
|
const DATA_API_URL = 'http://127.0.0.1:5002/api';
|
||||||
|
|
||||||
// Create axios instances
|
// Create axios instances
|
||||||
const userDataApi = axios.create({
|
const userDataApi = axios.create({
|
||||||
@@ -87,43 +87,32 @@ export const getAllFeeds = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateFeed = async (feedId: string, name: string, isPublic: boolean) => {
|
export const addNewFeed = async (name: string, isPublic: boolean) => {
|
||||||
|
try {
|
||||||
const token = getToken();
|
const token = getToken();
|
||||||
if (!token) throw new Error('Authentication required');
|
if (!token) {
|
||||||
|
throw new Error('Authentication required');
|
||||||
|
}
|
||||||
|
|
||||||
const response = await userDataApi.patch('/api/updatefeed', {
|
const response = await userDataApi.post(
|
||||||
feedId,
|
'/api/addnewfeed',
|
||||||
|
{
|
||||||
Name: name,
|
Name: name,
|
||||||
IsPublic: isPublic,
|
IsPublic: isPublic,
|
||||||
}, {
|
},
|
||||||
headers: {
|
{
|
||||||
Authorization: `Bearer ${token}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return response.data;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const addNewFeed = async (name: string, isPublic: boolean) => {
|
|
||||||
const token = getToken();
|
|
||||||
if (!token) throw new Error('Authentication required');
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await userDataApi.post('/api/addnewfeed', {
|
|
||||||
Name: name,
|
|
||||||
IsPublic: isPublic
|
|
||||||
}, {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
'Content-Type': 'application/json'
|
},
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw error.response?.data || { success: false, message: 'Network error' };
|
throw error.response?.data || { success: false, message: 'Network error' };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deleteFeed = async (feedId: string) => {
|
export const deleteFeed = async (feedId: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await userDataApi.delete('/api/deletefeed', {
|
const response = await userDataApi.delete('/api/deletefeed', {
|
||||||
|
@@ -25,7 +25,7 @@ export interface ApiKeyResponse {
|
|||||||
apiKey: string;
|
apiKey: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// New ApiKey Typez
|
// New ApiKey Type
|
||||||
export interface ApiKey {
|
export interface ApiKey {
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
key: string;
|
key: string;
|
||||||
@@ -37,11 +37,17 @@ export interface Feed {
|
|||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AddFeedRequest {
|
||||||
|
Name: string;
|
||||||
|
IsPublic: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AddFeedResponse {
|
export interface AddFeedResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
feedId: string;
|
feedId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface FeedDataPoint {
|
export interface FeedDataPoint {
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
data: string;
|
data: string;
|
||||||
|
@@ -61,7 +61,9 @@ export function DashboardPage() {
|
|||||||
// Handle add new feed
|
// Handle add new feed
|
||||||
const handleAddNewFeed = async () => {
|
const handleAddNewFeed = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await addNewFeed();
|
const defaultName = `Untitled Feed ${new Date().toLocaleString()}`;
|
||||||
|
const response = await addNewFeed(defaultName);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
toast.success("New feed created successfully");
|
toast.success("New feed created successfully");
|
||||||
fetchFeeds();
|
fetchFeeds();
|
||||||
@@ -166,8 +168,9 @@ export function DashboardPage() {
|
|||||||
>
|
>
|
||||||
<div className="flex flex-col items-start w-full overflow-hidden">
|
<div className="flex flex-col items-start w-full overflow-hidden">
|
||||||
<div className="font-medium truncate w-full">
|
<div className="font-medium truncate w-full">
|
||||||
Feed {feed.id.substring(0, 8)}...
|
{feed.name || `Feed ${feed.id.substring(0, 8)}...`}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="text-xs text-muted-foreground truncate w-full">
|
<div className="text-xs text-muted-foreground truncate w-full">
|
||||||
Created: {formatDateTime(feed.createdAt)}
|
Created: {formatDateTime(feed.createdAt)}
|
||||||
</div>
|
</div>
|
||||||
@@ -184,13 +187,36 @@ export function DashboardPage() {
|
|||||||
<Card className="md:col-span-3 relative">
|
<Card className="md:col-span-3 relative">
|
||||||
<CardHeader className="flex flex-col md:flex-row md:items-center md:justify-between space-y-2 md:space-y-0">
|
<CardHeader className="flex flex-col md:flex-row md:items-center md:justify-between space-y-2 md:space-y-0">
|
||||||
<div>
|
<div>
|
||||||
<CardTitle>Feed Data</CardTitle>
|
<CardHeader>
|
||||||
<CardDescription>
|
<CardTitle>
|
||||||
{selectedFeed
|
{selectedFeed ? `Feed Data: ${selectedFeed.name}` : "Feed Data"}
|
||||||
? `Showing data for Feed ${selectedFeed.id.substring(0, 8)}...`
|
</CardTitle>
|
||||||
: "Select a feed to view data"
|
<CardDescription className="flex flex-col">
|
||||||
}
|
{selectedFeed ? (
|
||||||
|
<>
|
||||||
|
<span className="text-sm text-muted-foreground flex items-center gap-2">
|
||||||
|
Feed ID:
|
||||||
|
<code className="bg-muted px-1 py-0.5 rounded text-xs">{selectedFeed.id}</code>
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className="h-5 w-5 p-1"
|
||||||
|
onClick={() => {
|
||||||
|
navigator.clipboard.writeText(selectedFeed.id);
|
||||||
|
toast.success("Feed ID copied to clipboard");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 16h8M8 12h8m-6 8h6a2 2 0 002-2v-5m0-4V6a2 2 0 00-2-2h-6l-2 2H6a2 2 0 00-2 2v12a2 2 0 002 2h2" />
|
||||||
|
</svg>
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"Select a feed to view data"
|
||||||
|
)}
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Flex container for the select box and button */}
|
{/* Flex container for the select box and button */}
|
||||||
@@ -250,7 +276,7 @@ export function DashboardPage() {
|
|||||||
<FeedChart data={feedData} />
|
<FeedChart data={feedData} />
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user