add image upload, fix styles

This commit is contained in:
smanylov
2025-12-09 16:35:47 +07:00
parent 7e485ee524
commit c8e8be8935
28 changed files with 547 additions and 83 deletions
+54
View File
@@ -0,0 +1,54 @@
'use server'
import { getSessionData } from '@/app/actions/session';
import { localDevelopmentUrl } from '@/app/actions/definitions';
const API_BASE_URL = process.env.NODE_ENV === 'development'
? localDevelopmentUrl
: 'http://app:8080';
const FRUITS_URL = 'https://www.fruityvice.com/api/fruit/';
const ALL = 'all';
export async function fetchFruits() {
try {
const response = await fetch(FRUITS_URL + ALL, { 'method': 'GET' });
let parsed = await response.json();
return parsed;
} catch (error) {
console.error('Error:', error);
throw new Error('Failed to fetch fruits data.');
}
}
export async function fetchFruit(id: number) {
try {
const response = await fetch(FRUITS_URL + id, { 'method': 'GET' });
let parsed = await response.json();
return parsed;
} catch (error) {
console.error('Error:', error);
throw new Error('Failed to fetch fruits data.');
}
}
export async function getUserData() {
const userEmail = await getSessionData('email');
const token = await getSessionData('token');
try {
const response = await fetch(`${API_BASE_URL}/v1/api/user?email=${userEmail}`, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${token}`,
}
});
if (response.ok) {
return await response.json();
}
} catch (error) {
console.error('error');
}
}