add image upload, fix styles
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user