fixes to app

This commit is contained in:
Patryk
2025-06-08 20:18:38 +02:00
parent dbf07cea0a
commit bcce392c9b
13 changed files with 1450 additions and 375 deletions

View File

@@ -1,10 +1,16 @@
import axios from "axios";
import { useAuthStore } from "@/store/authStore";
const API_URL = "https://hopp.zikor.pl/api/v1";
export async function getUserById(userId) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.get(`${API_URL}/clients/get/${userId}`);
const response = await axios.get(
`${API_URL}/clients/get/${userId}`,
headers
);
return response.data;
} catch (err) {
console.error(

View File

@@ -14,9 +14,11 @@ export async function listNotices() {
headers: headers,
});
const data = await response.json();
if (!response.ok) {
throw new Error(response.toString());
}
// console.info("Notices fetched successfully:", data);
return data;
}
@@ -68,8 +70,12 @@ export async function getImageByNoticeId(noticeId) {
}
export async function getAllImagesByNoticeId(noticeId) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`);
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`, {
headers,
});
if (listResponse.data && listResponse.data.length > 0) {
return listResponse.data.map(
@@ -127,3 +133,23 @@ export const uploadImage = async (noticeId, imageUri) => {
throw error;
}
};
export const deleteNotice = async (noticeId) => {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.delete(
`${API_URL}/notices/delete/${noticeId}`,
{ headers }
);
return response.data;
} catch (error) {
console.error(
"Error deleting notice:",
error.response?.data,
error.response?.status
);
throw error;
}
};

View File

@@ -1,12 +1,67 @@
import axios from "axios";
import FormData from "form-data";
const API_URL = "https://hopp.zikor.pl/api/v1";
export async function listOrders() {
const response = await fetch(`${API_URL}/orders/get/all`);
const data = await response.json();
if (!response.ok) {
throw new Error(response.toString());
import { useAuthStore } from "@/store/authStore";
const API_URL = "https://hopp.zikor.pl/api/v1/orders";
export async function createOrder(noticeId, orderType) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
const clientId = 1;
try {
const response = await axios.post(
`${API_URL}/add`,
{ clientId, noticeId, orderType },
{
headers: {
"Content-Type": "application/json",
...headers,
},
}
);
return response.data;
} catch (error) {
console.log("Error", error.response?.data, error.response?.status);
return null;
}
}
export async function createPayment(orderId) {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
const clientId = 1;
try {
const response = await axios.post(
`${API_URL}/token`,
{},
{
headers: {
"Content-Type": "application/json",
...headers,
},
}
);
return response.data;
} catch (error) {
console.log("Error", error.response?.data, error.response?.status);
return null;
}
}
export async function listOrders() {
const { token } = useAuthStore.getState();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try {
const response = await axios.get(`${API_URL}/get/all`, { headers });
return response.data; // to będzie tablica OrderWithPaymentsDTO
} catch (error) {
console.error(
"Error fetching orders:",
error.response?.data,
error.response?.status
);
throw error;
}
return data;
}