Update project 6 FRONT SVG SEAT LOCK

This commit is contained in:
2026-03-06 12:39:26 +00:00
parent 02b70f4369
commit a418c53664
4 changed files with 158 additions and 35 deletions

View File

@@ -2,12 +2,11 @@ import axios from "axios";
import { useAuthStore } from "@/store/authStore";
const apiClient = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8081/api",
baseURL: "http://192.168.149.101:8000/api",
headers: { "Content-Type": "application/json" },
});
apiClient.interceptors.request.use((config) => {
// getState() — безопасен вне React-дерева (server actions, route handlers тоже работают)
const token = useAuthStore.getState().token;
if (token) {
config.headers.Authorization = `Bearer ${token}`;
@@ -15,4 +14,14 @@ apiClient.interceptors.request.use((config) => {
return config;
});
/**
* POST /api/seats/{seat_id}/lock?user_id={user_id}
* Бросает AxiosError со status 409, если место захвачено конкурентом.
*/
export async function lockSeatApi(seatId: number, userId: number): Promise<void> {
await apiClient.post(`/seats/${seatId}/lock`, null, {
params: { user_id: userId },
});
}
export default apiClient;