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:
Maurice
2026-11-29 14:57:10 +01:00
parent 82165855c7
commit 0ecca2b46c
27 changed files with 2616 additions and 2 deletions
+47
View File
@@ -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`]);
});
});
+17
View File
@@ -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),
};
+44
View File
@@ -0,0 +1,44 @@
import type { PlacesLibraryDetailResponse, PlacesLibraryPageResponse } from '@trek/shared';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { placesLibraryApi } from '../api/placesLibrary';
import { OnlineOnlyError } from './onlineOnly';
import { placesLibraryRepo } from './placesLibraryRepo';
// FE-REPO-PLACES-LIBRARY-001 to FE-REPO-PLACES-LIBRARY-002
const network = vi.hoisted(() => ({ offline: false }));
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: () => network.offline }));
beforeEach(() => {
network.offline = false;
vi.restoreAllMocks();
});
describe('placesLibraryRepo', () => {
it('FE-REPO-PLACES-LIBRARY-001: reads only online, never from a cache', async () => {
network.offline = true;
const list = vi.spyOn(placesLibraryApi, 'list');
const detail = vi.spyOn(placesLibraryApi, 'detail');
await expect(placesLibraryRepo.list()).rejects.toBeInstanceOf(OnlineOnlyError);
await expect(placesLibraryRepo.detail('trip', 4)).rejects.toBeInstanceOf(OnlineOnlyError);
expect(list).not.toHaveBeenCalled();
expect(detail).not.toHaveBeenCalled();
});
it('FE-REPO-PLACES-LIBRARY-002: passes each call on with its signal and answers what the server said', async () => {
const page: PlacesLibraryPageResponse = {
entries: [],
total: 0,
counts: { all: 0, trip: 0, list: 0 },
next_cursor: null,
};
const answer = { entry: { key: 'list:9' }, details: [] } as unknown as PlacesLibraryDetailResponse;
const list = vi.spyOn(placesLibraryApi, 'list').mockResolvedValue(page);
const detail = vi.spyOn(placesLibraryApi, 'detail').mockResolvedValue(answer);
const signal = new AbortController().signal;
expect(await placesLibraryRepo.list({ sort: 'updated' }, signal)).toBe(page);
expect(await placesLibraryRepo.detail('list', 9, signal)).toBe(answer);
expect(list).toHaveBeenCalledWith({ sort: 'updated' }, signal);
expect(detail).toHaveBeenCalledWith('list', 9, signal);
});
});
+26
View File
@@ -0,0 +1,26 @@
import type {
PlacesLibraryDetailResponse,
PlacesLibraryKind,
PlacesLibraryPageResponse,
PlacesLibraryQueryInput,
} from '@trek/shared';
import { placesLibraryApi } from '../api/placesLibrary';
import { requireOnline } from './onlineOnly';
/**
* PLC-07/PLC-08, online only on purpose, like the collections themselves:
* "All places" reads across every list and trip the user can open, and which
* those are is decided by the server at the moment it is asked, so there is no
* cache it could answer from.
*/
export const placesLibraryRepo = {
async list(query: PlacesLibraryQueryInput = {}, signal?: AbortSignal): Promise<PlacesLibraryPageResponse> {
requireOnline();
return await placesLibraryApi.list(query, signal);
},
async detail(kind: PlacesLibraryKind, id: number, signal?: AbortSignal): Promise<PlacesLibraryDetailResponse> {
requireOnline();
return await placesLibraryApi.detail(kind, id, signal);
},
};