refactor(frontend): migrate entities/bond to FSD
This commit is contained in:
parent
dd727f9fb2
commit
9c115f0e16
@ -5,8 +5,4 @@ export {
|
|||||||
setOnUnauthorized,
|
setOnUnauthorized,
|
||||||
getHealth,
|
getHealth,
|
||||||
searchSecurities,
|
searchSecurities,
|
||||||
getBond,
|
|
||||||
getBondMarketData,
|
|
||||||
getBondHistory,
|
|
||||||
getBondCandles,
|
|
||||||
} from '../shared/api/client';
|
} from '../shared/api/client';
|
||||||
|
|||||||
44
apps/frontend/src/entities/bond/api/bondApi.ts
Normal file
44
apps/frontend/src/entities/bond/api/bondApi.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { request } from '@/shared/api/client';
|
||||||
|
import type {
|
||||||
|
ApiResponseMeta,
|
||||||
|
BondResponse,
|
||||||
|
BondMarketData,
|
||||||
|
BondHistoryItem,
|
||||||
|
CandleItem,
|
||||||
|
} from '@/shared/api/responses';
|
||||||
|
|
||||||
|
export function getBond(secid: string): Promise<{ data: BondResponse; meta: ApiResponseMeta }> {
|
||||||
|
return request<BondResponse>(`/api/v1/securities/bonds/${encodeURIComponent(secid)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBondMarketData(
|
||||||
|
secid: string,
|
||||||
|
): Promise<{ data: BondMarketData; meta: ApiResponseMeta }> {
|
||||||
|
return request<BondMarketData>(
|
||||||
|
`/api/v1/securities/bonds/${encodeURIComponent(secid)}/marketdata`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBondHistory(
|
||||||
|
secid: string,
|
||||||
|
from: string,
|
||||||
|
till: string,
|
||||||
|
): Promise<{ data: BondHistoryItem[]; meta: ApiResponseMeta }> {
|
||||||
|
return request<BondHistoryItem[]>(
|
||||||
|
`/api/v1/securities/bonds/${encodeURIComponent(secid)}/history`,
|
||||||
|
{ from, till },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBondCandles(
|
||||||
|
secid: string,
|
||||||
|
interval: '1h' | '24h',
|
||||||
|
from: string,
|
||||||
|
till: string,
|
||||||
|
): Promise<{ data: CandleItem[]; meta: ApiResponseMeta }> {
|
||||||
|
return request<CandleItem[]>(`/api/v1/securities/bonds/${encodeURIComponent(secid)}/candles`, {
|
||||||
|
interval,
|
||||||
|
from,
|
||||||
|
till,
|
||||||
|
});
|
||||||
|
}
|
||||||
3
apps/frontend/src/entities/bond/index.ts
Normal file
3
apps/frontend/src/entities/bond/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export { useBond } from './model/useBond';
|
||||||
|
export { useBondCandles } from './model/useBondCandles';
|
||||||
|
export { getBond, getBondMarketData, getBondHistory, getBondCandles } from './api/bondApi';
|
||||||
14
apps/frontend/src/entities/bond/model/useBond.ts
Normal file
14
apps/frontend/src/entities/bond/model/useBond.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { getBond } from '../api/bondApi';
|
||||||
|
import type { BondResponse } from '@/shared/api/responses';
|
||||||
|
|
||||||
|
export function useBond(secid: string) {
|
||||||
|
return useQuery<BondResponse>({
|
||||||
|
queryKey: ['bond', secid],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await getBond(secid);
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
|
staleTime: 900_000,
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
|
|||||||
import { renderHook, waitFor } from '@testing-library/react';
|
import { renderHook, waitFor } from '@testing-library/react';
|
||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
import { http, HttpResponse } from 'msw';
|
import { http, HttpResponse } from 'msw';
|
||||||
import { server } from '../test/server';
|
import { server } from '../../../test/server';
|
||||||
import { useBondCandles } from './useBondCandles';
|
import { useBondCandles } from './useBondCandles';
|
||||||
import { type ReactNode } from 'react';
|
import { type ReactNode } from 'react';
|
||||||
|
|
||||||
14
apps/frontend/src/entities/bond/model/useBondCandles.ts
Normal file
14
apps/frontend/src/entities/bond/model/useBondCandles.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { getBondCandles } from '../api/bondApi';
|
||||||
|
import type { CandleItem } from '@/shared/api/responses';
|
||||||
|
|
||||||
|
export function useBondCandles(secid: string, interval: '1h' | '24h', from: string, till: string) {
|
||||||
|
return useQuery<CandleItem[]>({
|
||||||
|
queryKey: ['bondCandles', secid, interval, from, till],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await getBondCandles(secid, interval, from, till);
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
|
staleTime: 3600_000,
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -1,14 +1 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
export { useBond } from '../entities/bond/model/useBond';
|
||||||
import { getBond } from '@/shared/api/client';
|
|
||||||
import type { BondResponse } from '@/shared/api/responses';
|
|
||||||
|
|
||||||
export function useBond(secid: string) {
|
|
||||||
return useQuery<BondResponse>({
|
|
||||||
queryKey: ['bond', secid],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await getBond(secid);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
staleTime: 900_000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,14 +1 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
export { useBondCandles } from '../entities/bond/model/useBondCandles';
|
||||||
import { getBondCandles } from '@/shared/api/client';
|
|
||||||
import type { CandleItem } from '@/shared/api/responses';
|
|
||||||
|
|
||||||
export function useBondCandles(secid: string, interval: '1h' | '24h', from: string, till: string) {
|
|
||||||
return useQuery<CandleItem[]>({
|
|
||||||
queryKey: ['bondCandles', secid, interval, from, till],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await getBondCandles(secid, interval, from, till);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
staleTime: 3600_000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { useBond } from '../hooks/useBond';
|
import { useBond, useBondCandles } from '../entities/bond';
|
||||||
import { useBondCandles } from '../hooks/useBondCandles';
|
|
||||||
import { BondDetails } from '../components/BondDetails';
|
import { BondDetails } from '../components/BondDetails';
|
||||||
import { PriceChart } from '../components/PriceChart';
|
import { PriceChart } from '../components/PriceChart';
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,6 @@ import type {
|
|||||||
ApiEnvelope,
|
ApiEnvelope,
|
||||||
ApiResponseMeta,
|
ApiResponseMeta,
|
||||||
AuthResponse,
|
AuthResponse,
|
||||||
BondResponse,
|
|
||||||
BondMarketData,
|
|
||||||
BondHistoryItem,
|
|
||||||
CandleItem,
|
|
||||||
SearchResultItem,
|
SearchResultItem,
|
||||||
HealthResponse,
|
HealthResponse,
|
||||||
} from './responses';
|
} from './responses';
|
||||||
@ -146,39 +142,3 @@ export function searchSecurities(
|
|||||||
limit: String(limit),
|
limit: String(limit),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBond(secid: string): Promise<{ data: BondResponse; meta: ApiResponseMeta }> {
|
|
||||||
return request<BondResponse>(`/api/v1/securities/bonds/${encodeURIComponent(secid)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getBondMarketData(
|
|
||||||
secid: string,
|
|
||||||
): Promise<{ data: BondMarketData; meta: ApiResponseMeta }> {
|
|
||||||
return request<BondMarketData>(
|
|
||||||
`/api/v1/securities/bonds/${encodeURIComponent(secid)}/marketdata`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getBondHistory(
|
|
||||||
secid: string,
|
|
||||||
from: string,
|
|
||||||
till: string,
|
|
||||||
): Promise<{ data: BondHistoryItem[]; meta: ApiResponseMeta }> {
|
|
||||||
return request<BondHistoryItem[]>(
|
|
||||||
`/api/v1/securities/bonds/${encodeURIComponent(secid)}/history`,
|
|
||||||
{ from, till },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getBondCandles(
|
|
||||||
secid: string,
|
|
||||||
interval: '1h' | '24h',
|
|
||||||
from: string,
|
|
||||||
till: string,
|
|
||||||
): Promise<{ data: CandleItem[]; meta: ApiResponseMeta }> {
|
|
||||||
return request<CandleItem[]>(`/api/v1/securities/bonds/${encodeURIComponent(secid)}/candles`, {
|
|
||||||
interval,
|
|
||||||
from,
|
|
||||||
till,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@ -5,10 +5,6 @@ export {
|
|||||||
setOnUnauthorized,
|
setOnUnauthorized,
|
||||||
getHealth,
|
getHealth,
|
||||||
searchSecurities,
|
searchSecurities,
|
||||||
getBond,
|
|
||||||
getBondMarketData,
|
|
||||||
getBondHistory,
|
|
||||||
getBondCandles,
|
|
||||||
} from './client';
|
} from './client';
|
||||||
export type {
|
export type {
|
||||||
ApiResponseMeta,
|
ApiResponseMeta,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user