mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
feat(places): read every place of the trips and lists in one view
A read-only overview of every place a user can reach: the saved places of
their lists and the places of their trips, viewer trips included, with tours,
tracks and the stops of a drive left out. A saved place and a trip place are
one entry only when the saved place came from that trip place, the trip is
still open to the user, and both agree (a provider id, or the same name at the
same spot); anything else stays apart. Every entry names where it comes from
and whether it may be changed there.
- GET /api/addons/collections/library/places: paged by cursor, search,
category, kind, list, trip and status filters, counts per kind.
- GET /api/addons/collections/library/places/{trip|list}/🆔 one entry with
what each origin keeps on its own (notes after the existing rights, labels,
ratings, a trip's planned days, whether a stay or booking uses it).
- MCP tools list_all_places and get_library_place.
Nothing is written and nothing migrates; the rights are the existing list and
trip checks, read on every call.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// FE-API-PLACES-LIBRARY-001 to FE-API-PLACES-LIBRARY-002
|
||||
//
|
||||
// PLC-07/PLC-08: each method pins its verb, its path and its query, and hands
|
||||
// back what the server answered.
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { server } from '../../tests/helpers/msw/server';
|
||||
import { placesLibraryApi } from './placesLibrary';
|
||||
|
||||
const BASE = '/api/addons/collections/library/places';
|
||||
const page = { entries: [], total: 0, counts: { all: 0, trip: 0, list: 0 }, next_cursor: null };
|
||||
|
||||
let calls: Array<{ path: string; query: Record<string, string> }> = [];
|
||||
|
||||
beforeEach(() => {
|
||||
calls = [];
|
||||
});
|
||||
|
||||
function record(data: object) {
|
||||
return ({ request }: { request: Request }) => {
|
||||
const url = new URL(request.url);
|
||||
calls.push({ path: url.pathname, query: Object.fromEntries(url.searchParams) });
|
||||
return HttpResponse.json(data);
|
||||
};
|
||||
}
|
||||
|
||||
describe('placesLibraryApi', () => {
|
||||
it('FE-API-PLACES-LIBRARY-001: lists a page with the filters as query parameters', async () => {
|
||||
server.use(http.get(BASE, record(page)));
|
||||
expect(await placesLibraryApi.list()).toEqual(page);
|
||||
expect(
|
||||
await placesLibraryApi.list({ q: 'cafe', kind: 'list', collection_id: 3, limit: 20, cursor: 'abc' })
|
||||
).toEqual(page);
|
||||
expect(calls).toEqual([
|
||||
{ path: BASE, query: {} },
|
||||
{ path: BASE, query: { q: 'cafe', kind: 'list', collection_id: '3', limit: '20', cursor: 'abc' } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('FE-API-PLACES-LIBRARY-002: opens one entry by the trip place or the saved place it names', async () => {
|
||||
const answer = { entry: { key: 'trip:4' }, details: [] };
|
||||
server.use(http.get(`${BASE}/trip/4`, record(answer)), http.get(`${BASE}/list/9`, record(answer)));
|
||||
expect(await placesLibraryApi.detail('trip', 4)).toEqual(answer);
|
||||
expect(await placesLibraryApi.detail('list', 9)).toEqual(answer);
|
||||
expect(calls.map((call) => call.path)).toEqual([`${BASE}/trip/4`, `${BASE}/list/9`]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import type {
|
||||
PlacesLibraryDetailResponse,
|
||||
PlacesLibraryKind,
|
||||
PlacesLibraryPageResponse,
|
||||
PlacesLibraryQueryInput,
|
||||
} from '@trek/shared';
|
||||
import apiClient from './client';
|
||||
|
||||
const base = '/addons/collections/library/places';
|
||||
|
||||
/** PLC-07/PLC-08 "All places": one page of entries, and one entry by the trip place or saved place it was opened from. */
|
||||
export const placesLibraryApi = {
|
||||
list: (query: PlacesLibraryQueryInput = {}, signal?: AbortSignal): Promise<PlacesLibraryPageResponse> =>
|
||||
apiClient.get(base, { params: query, signal }).then((r) => r.data),
|
||||
detail: (kind: PlacesLibraryKind, id: number, signal?: AbortSignal): Promise<PlacesLibraryDetailResponse> =>
|
||||
apiClient.get(`${base}/${kind}/${id}`, { signal }).then((r) => r.data),
|
||||
};
|
||||
Reference in New Issue
Block a user