feat: Add more pages
This commit is contained in:
76
src/shared/store/StationsStore/index.ts
Normal file
76
src/shared/store/StationsStore/index.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
type Station = {
|
||||
id: number;
|
||||
address: string;
|
||||
city: string;
|
||||
city_id: number;
|
||||
description: string;
|
||||
direction: boolean;
|
||||
icon: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
name: string;
|
||||
offset_x: number;
|
||||
offset_y: number;
|
||||
system_name: string;
|
||||
transfers: {
|
||||
bus: string;
|
||||
metro_blue: string;
|
||||
metro_green: string;
|
||||
metro_orange: string;
|
||||
metro_purple: string;
|
||||
metro_red: string;
|
||||
train: string;
|
||||
tram: string;
|
||||
trolleybus: string;
|
||||
};
|
||||
};
|
||||
|
||||
class StationsStore {
|
||||
stations: Station[] = [];
|
||||
station: Station | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getStations = async () => {
|
||||
const response = await authInstance.get("/station");
|
||||
|
||||
runInAction(() => {
|
||||
this.stations = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteStation = async (id: number) => {
|
||||
await authInstance.delete(`/station/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.stations = this.stations.filter((station) => station.id !== id);
|
||||
});
|
||||
};
|
||||
|
||||
getStation = async (id: number) => {
|
||||
const response = await authInstance.get(`/station/${id}`);
|
||||
this.station = response.data;
|
||||
};
|
||||
|
||||
createStation = async (
|
||||
name: string,
|
||||
systemName: string,
|
||||
direction: string
|
||||
) => {
|
||||
const response = await authInstance.post("/station", {
|
||||
station_name: name,
|
||||
system_name: systemName,
|
||||
direction,
|
||||
});
|
||||
runInAction(() => {
|
||||
this.stations.push(response.data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const stationsStore = new StationsStore();
|
Reference in New Issue
Block a user