Merge remote-tracking branch 'origin/authentication' into integrateWithAuth
This commit is contained in:
@@ -4,23 +4,19 @@ import { useAuthStore } from "@/store/authStore";
|
||||
|
||||
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||
|
||||
//const API_URL = "http://10.0.2.2:8080/api/v1";
|
||||
|
||||
export async function listNotices() {
|
||||
const { token } = useAuthStore.getState();
|
||||
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
||||
|
||||
console.log(token);
|
||||
|
||||
const response = await fetch(`${API_URL}/notices/get/all`, {
|
||||
headers: headers,
|
||||
});
|
||||
// console.log(response);r
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(response.toString());
|
||||
}
|
||||
return data;
|
||||
const response = await fetch(`${API_URL}/notices/get/all`, {
|
||||
headers: headers
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(response.toString());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getNoticeById(noticeId) {
|
||||
@@ -62,27 +58,32 @@ export async function getImageByNoticeId(noticeId) {
|
||||
const imageName = listResponse.data[0];
|
||||
imageUrl = `${API_URL}/images/get/${imageName}`;
|
||||
|
||||
console.log(`Pobrano zdjęcie o nazwie: ${imageName}`);
|
||||
|
||||
return imageUrl;
|
||||
} catch (err) {
|
||||
console.log(`Zdjęcie nie istnieje dla notice o id: ${noticeId}`);
|
||||
imageUrl = "https://http.cat/404.jpg";
|
||||
return imageUrl;
|
||||
}
|
||||
return imageUrl;
|
||||
} catch (err) {
|
||||
console.log(`Zdjęcie nie istnieje dla notice o id: ${noticeId}`);
|
||||
imageUrl = "https://http.cat/404.jpg";
|
||||
return imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllImagesByNoticeId(noticeId) {
|
||||
try {
|
||||
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`);
|
||||
|
||||
if (listResponse.data && listResponse.data.length > 0) {
|
||||
const imageUrls = listResponse.data.map(
|
||||
(imageName) => `${API_URL}/images/get/${imageName}`
|
||||
);
|
||||
if (listResponse.data && listResponse.data.length > 0) {
|
||||
return listResponse.data.map(imageName =>
|
||||
`${API_URL}/images/get/${imageName}`
|
||||
);
|
||||
}
|
||||
|
||||
// console.log(`Pobrano ${imageUrls.length} zdjęć dla ogłoszenia o id: ${noticeId}`);
|
||||
return imageUrls;
|
||||
return ["https://http.cat/404.jpg"];
|
||||
} catch (err) {
|
||||
if(err.response.status === 404) {
|
||||
console.info(`Ogłoszenie o id: ${noticeId} nie posiada zdjęć.`);
|
||||
return ["https://http.cat/404.jpg"];
|
||||
}
|
||||
console.warn(`Nie udało się pobrać listy zdjęć dla ogłoszenia o id: ${noticeId}`, err);
|
||||
return ["https://http.cat/404.jpg"];
|
||||
}
|
||||
|
||||
// console.log(`Brak zdjęć dla ogłoszenia o id: ${noticeId}`);
|
||||
@@ -94,9 +95,7 @@ export async function getAllImagesByNoticeId(noticeId) {
|
||||
}
|
||||
|
||||
export const uploadImage = async (noticeId, imageUri) => {
|
||||
console.log(imageUri);
|
||||
|
||||
const formData = new FormData();
|
||||
const formData = new FormData();
|
||||
|
||||
const filename = imageUri.split("/").pop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user