Update project 7 FRONT UI -> API -> DB -> RabbitMQ -> Worker -> MinIO

This commit is contained in:
2026-03-06 13:18:32 +00:00
parent a418c53664
commit 8de0a1e7db
7 changed files with 408 additions and 19 deletions

View File

@@ -2,7 +2,7 @@ import axios from "axios";
import { useAuthStore } from "@/store/authStore";
const apiClient = axios.create({
baseURL: "http://192.168.149.101:8000/api",
baseURL: process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8081/api",
headers: { "Content-Type": "application/json" },
});
@@ -14,13 +14,47 @@ apiClient.interceptors.request.use((config) => {
return config;
});
// ─── Seat locking ─────────────────────────────────────────────────────────────
interface LockSeatResponse {
message: string;
seat_id: number;
status: string;
/** Returned by backend when the Ticket row is created. Falls back to seat_id. */
ticket_id?: number;
}
/**
* POST /api/seats/{seat_id}/lock?user_id={user_id}
* Бросает AxiosError со status 409, если место захвачено конкурентом.
* Returns the ticketId for the locked seat (falls back to seatId if backend
* does not yet expose ticket_id in the response body).
* Throws AxiosError with status 409 if the seat is already locked.
*/
export async function lockSeatApi(seatId: number, userId: number): Promise<void> {
await apiClient.post(`/seats/${seatId}/lock`, null, {
params: { user_id: userId },
export async function lockSeatApi(
seatId: number,
userId: number
): Promise<{ ticketId: number }> {
const response = await apiClient.post<LockSeatResponse>(
`/seats/${seatId}/lock`,
null,
{ params: { user_id: userId } }
);
return { ticketId: response.data.ticket_id ?? seatId };
}
// ─── Payment webhook ──────────────────────────────────────────────────────────
/**
* POST /api/webhooks/payment
* Simulates a payment gateway callback for the given ticket.
* Uses a random idempotency key to satisfy the backend's idempotency check.
*/
export async function processPaymentWebhook(ticketId: number): Promise<void> {
const idempotencyKey = "req-" + Math.random().toString(36).substring(2, 9);
await apiClient.post("/webhooks/payment", {
ticket_id: ticketId,
idempotency_key: idempotencyKey,
status: "success",
});
}