Skip to content

Commit

Permalink
[Issue comixed#208] Move the series name to the request body.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed May 8, 2020
1 parent e37aece commit cc0d628
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 52 deletions.
2 changes: 1 addition & 1 deletion comixed-frontend/src/app/comics/comics.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const GET_PAGE_CONTENT_URL = `${API_ROOT_URL}/pages/\${id}/content`;
export const BLOCK_PAGE_HASH_URL = `${API_ROOT_URL}/pages/\${id}/block/\${hash}`;
export const UNBLOCK_PAGE_HASH_URL = `${API_ROOT_URL}/pages/\${id}/unblock/\${hash}`;

export const GET_VOLUMES_URL = `${API_ROOT_URL}/scraping/series/\${series}`;
export const GET_VOLUMES_URL = `${API_ROOT_URL}/scraping/series`;
export const GET_ISSUE_URL = `${API_ROOT_URL}/scraping/volumes/\${volume}/issues`;

export const LOAD_METADATA_URL = `${API_ROOT_URL}/scraping/comics/\${comicId}/issue/\${issueId}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('ScrapingService', () => {
.subscribe(response => expect(response).toEqual(VOLUMES));

const req = httpMock.expectOne(
interpolate(GET_VOLUMES_URL, { series: SERIES })
interpolate(GET_VOLUMES_URL)
);
expect(req.request.method).toEqual('POST');
expect(req.request.body).toEqual({
Expand Down
73 changes: 36 additions & 37 deletions comixed-frontend/src/app/comics/services/scraping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {HttpClient} from '@angular/common/http';
import {interpolate} from 'app/app.functions';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { interpolate } from 'app/app.functions';
import {
GET_ISSUE_URL,
GET_VOLUMES_URL,
LOAD_METADATA_URL
} from 'app/comics/comics.constants';
import {GetVolumesRequest} from 'app/comics/models/net/get-volumes-request';
import {GetScrapingIssueRequest} from 'app/comics/models/net/get-scraping-issue-request';
import {LoadMetadataRequest} from 'app/comics/models/net/load-metadata-request';
import {LoggerService} from '@angular-ru/logger';
import { GetVolumesRequest } from 'app/comics/models/net/get-volumes-request';
import { GetScrapingIssueRequest } from 'app/comics/models/net/get-scraping-issue-request';
import { LoadMetadataRequest } from 'app/comics/models/net/load-metadata-request';
import { LoggerService } from '@angular-ru/logger';

@Injectable({
providedIn: 'root'
})
export class ScrapingService {
constructor(private logger: LoggerService, private http: HttpClient) {
}
constructor(private logger: LoggerService, private http: HttpClient) {}

getVolumes(
apiKey: string,
series: string,
volume: string,
skipCache: boolean
apiKey: string,
series: string,
volume: string,
skipCache: boolean
): Observable<any> {
this.logger.debug(
`[POST] http request: get volumes: apiKey=${apiKey} series=${series} volume=${volume} skipCache=${skipCache}`
`[POST] http request: get volumes: apiKey=${apiKey} series=${series} volume=${volume} skipCache=${skipCache}`
);
return this.http.post(interpolate(GET_VOLUMES_URL, {series: series}), {
return this.http.post(interpolate(GET_VOLUMES_URL), {
apiKey: apiKey,
series: series,
volume: volume,
Expand All @@ -55,39 +54,39 @@ export class ScrapingService {
}

getIssue(
apiKey: string,
volumeId: number,
issueNumber: string,
skipCache: boolean
apiKey: string,
volumeId: number,
issueNumber: string,
skipCache: boolean
): Observable<any> {
this.logger.debug(
`[POST] http request: get scraping issue: apiKey=${apiKey} volumeId=${volumeId} issueNumber=${issueNumber} skipCache=${skipCache}`
`[POST] http request: get scraping issue: apiKey=${apiKey} volumeId=${volumeId} issueNumber=${issueNumber} skipCache=${skipCache}`
);
return this.http.post(
interpolate(GET_ISSUE_URL, {volume: `${volumeId}`}),
{
apiKey: apiKey,
skipCache: skipCache,
issueNumber: issueNumber
} as GetScrapingIssueRequest
interpolate(GET_ISSUE_URL, { volume: `${volumeId}` }),
{
apiKey: apiKey,
skipCache: skipCache,
issueNumber: issueNumber
} as GetScrapingIssueRequest
);
}

loadMetadata(
apiKey: string,
comicId: number,
issueId: string,
skipCache: boolean
apiKey: string,
comicId: number,
issueId: string,
skipCache: boolean
): Observable<any> {
this.logger.debug(
`[POST] http request: load metadata: apiKey=${apiKey} comicId=${comicId} issueId=${issueId} skipCache=${skipCache}`
`[POST] http request: load metadata: apiKey=${apiKey} comicId=${comicId} issueId=${issueId} skipCache=${skipCache}`
);
return this.http.post(
interpolate(LOAD_METADATA_URL, {comicId: comicId, issueId: issueId}),
{
apiKey: apiKey,
skipCache: skipCache
} as LoadMetadataRequest
interpolate(LOAD_METADATA_URL, { comicId: comicId, issueId: issueId }),
{
apiKey: apiKey,
skipCache: skipCache
} as LoadMetadataRequest
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,16 @@ public ScrapingIssue queryForIssue(
}

@PostMapping(
value = "/series/{seriesName}",
value = "/series",
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
public List<ScrapingVolume> queryForVolumes(
@PathVariable("seriesName") final String seriesName,
@RequestBody() final GetVolumesRequest request)
public List<ScrapingVolume> queryForVolumes(@RequestBody() final GetVolumesRequest request)
throws WebRequestException, ComicVineAdaptorException {
String series = request.getSeries();
this.log.info(
"Getting volumes: series={}{}",
seriesName,
request.getSkipCache() ? " (Skipping cache)" : "");
"Getting volumes: series={}{}", series, request.getSkipCache() ? " (Skipping cache)" : "");

return this.queryForVolumesAdaptor.execute(
request.getApiKey(), seriesName, request.getSkipCache());
return this.queryForVolumesAdaptor.execute(request.getApiKey(), series, request.getSkipCache());
}

@PostMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@ public class GetVolumesRequest {
@JsonProperty("apiKey")
private String apiKey;

@JsonProperty("series")
private String series;

@JsonProperty("skipCache")
private Boolean skipCache;

public GetVolumesRequest() {}

public GetVolumesRequest(final String apiKey, final Boolean skipCache) {
public GetVolumesRequest(final String apiKey, final String series, final Boolean skipCache) {
this.apiKey = apiKey;
this.series = series;
this.skipCache = skipCache;
}

public String getApiKey() {
return apiKey;
}

public String getSeries() {
return series;
}

public Boolean getSkipCache() {
return skipCache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testQueryForVolumesAdaptorRaisesException()
.thenThrow(new ComicVineAdaptorException("expected"));

try {
controller.queryForVolumes(TEST_SERIES_NAME, new GetVolumesRequest(TEST_API_KEY, false));
controller.queryForVolumes(new GetVolumesRequest(TEST_API_KEY, TEST_SERIES_NAME, false));
} finally {
Mockito.verify(queryForVolumesAdaptor, Mockito.times(1))
.execute(TEST_API_KEY, TEST_SERIES_NAME, false);
Expand All @@ -90,7 +90,7 @@ public void testQueryForVolumes() throws ComicVineAdaptorException, WebRequestEx
.thenReturn(comicVolumeList);

final List<ScrapingVolume> result =
controller.queryForVolumes(TEST_SERIES_NAME, new GetVolumesRequest(TEST_API_KEY, false));
controller.queryForVolumes(new GetVolumesRequest(TEST_API_KEY, TEST_SERIES_NAME, false));

assertSame(comicVolumeList, result);

Expand All @@ -106,7 +106,7 @@ public void testQueryForVolumesSkipCache() throws ComicVineAdaptorException, Web
.thenReturn(comicVolumeList);

final List<ScrapingVolume> result =
controller.queryForVolumes(TEST_SERIES_NAME, new GetVolumesRequest(TEST_API_KEY, true));
controller.queryForVolumes(new GetVolumesRequest(TEST_API_KEY, TEST_SERIES_NAME, true));

assertSame(comicVolumeList, result);

Expand Down

0 comments on commit cc0d628

Please sign in to comment.