Skip to content

Commit a5b18a1

Browse files
committed
fix(lore): better support for additional lore data
1 parent d57b196 commit a5b18a1

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/model/lore-search-result.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Pagination } from './pagination';
22

33
export interface LoreSearchResult {
4+
Data?: any;
45
Results: {
56
Context: string;
67
Source: string;
78
SourceID: number;
89
Text: string;
9-
};
10+
}[];
1011
Pagination: Pagination;
1112
}

src/xivapi.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,20 @@ export class XivapiService {
4444
* Makes a request on a given endpoint with an id.
4545
*
4646
* @param query Text to search inside the lore.
47+
* @param dataColumns
4748
*/
48-
public searchLore(query: string): Observable<LoreSearchResult> {
49-
return this.doGet<LoreSearchResult>(`${XivapiService.API_BASE_URL}/lore`, new HttpParams().set('string', query));
49+
public searchLore(query: string, dataColumns?: string[]): Observable<LoreSearchResult> {
50+
let httpParams: HttpParams = new HttpParams().set('string', query);
51+
if (dataColumns && dataColumns.length > 0) {
52+
httpParams = httpParams.set('columns', [
53+
'Context',
54+
'Source',
55+
'SourceID',
56+
'Text',
57+
...dataColumns.map(col => `Data.${col}`)
58+
].join(','));
59+
}
60+
return this.doGet<LoreSearchResult>(`${XivapiService.API_BASE_URL}/lore`, httpParams);
5061
}
5162

5263
/**

test/xivapi.service.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@ describe('Client tests', () => {
5353
expect(req.request.params.has('string')).toBeTruthy();
5454
expect(req.request.params.get('string')).toEqual('legendary');
5555
});
56+
57+
it('Should search Lore properly with custom data columns', () => {
58+
const service: XivapiService = new XivapiService(httpClient);
59+
service.searchLore('legendary', ['Icon']).subscribe();
60+
const req: TestRequest = <TestRequest>httpMock.match({method: 'GET'})
61+
.find(row => row.request.url === `${XivapiService.API_BASE_URL}/lore`);
62+
expect(req).not.toBeUndefined();
63+
expect(req.request.params.has('string')).toBeTruthy();
64+
expect(req.request.params.get('string')).toEqual('legendary');
65+
expect(req.request.params.get('columns')).toEqual('Context,Source,SourceID,Text,Data.Icon');
66+
});
5667
});

0 commit comments

Comments
 (0)