Skip to content

Commit

Permalink
[Issue #219] Allow encoded values in the issue number.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Jun 21, 2020
1 parent 4263185 commit bcdda4f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 53 deletions.
Expand Up @@ -131,7 +131,7 @@ export class ScrapingAdaptor {
new ScrapingGetIssue({
apiKey: apiKey,
volumeId: volumeId,
issueNumber: issueNumber,
issueNumber: encodeURI(issueNumber),
skipCache: skipCache
})
);
Expand Down
2 changes: 1 addition & 1 deletion comixed-frontend/src/app/comics/comics.constants.ts
Expand Up @@ -37,7 +37,7 @@ 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_ISSUE_URL = `${API_ROOT_URL}/scraping/volumes/\${volume}/issues/\${issue}`;
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
Expand Up @@ -19,4 +19,5 @@
export interface GetScrapingIssueRequest {
apiKey: string;
skipCache: boolean;
issueNumber: string;
}
Expand Up @@ -101,14 +101,14 @@ describe('ScrapingService', () => {

const req = httpMock.expectOne(
interpolate(GET_ISSUE_URL, {
volume: SCRAPING_VOLUME.id,
issue: ISSUE.issueNumber
volume: SCRAPING_VOLUME.id
})
);
expect(req.request.method).toEqual('POST');
expect(req.request.body).toEqual({
apiKey: API_KEY,
skipCache: SKIP_CACHE
skipCache: SKIP_CACHE,
issueNumber: ISSUE.issueNumber
} as GetScrapingIssueRequest);
req.flush(ISSUE);
});
Expand Down
72 changes: 37 additions & 35 deletions comixed-frontend/src/app/comics/services/scraping.service.ts
Expand Up @@ -16,36 +16,37 @@
* 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, {series: series}), {
apiKey: apiKey,
series: series,
volume: volume,
Expand All @@ -54,38 +55,39 @@ export class ScrapingService {
}

getIssue(
apiKey: string,
volumeId: number,
issueId: 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} issueId=${issueId} 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}`, issue: issueId }),
{
apiKey: apiKey,
skipCache: skipCache
} 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
);
}
}
Expand Up @@ -48,19 +48,17 @@ public class ComicVineScraperController {
@Autowired private ComicService comicService;

@PostMapping(
value = "/volumes/{volume}/issues/{issue}",
value = "/volumes/{volume}/issues",
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
public ScrapingIssue queryForIssue(
@PathVariable("volume") final Integer volume,
@PathVariable("issue") final String issue,
@RequestBody() final GetScrapingIssueRequest request)
throws ComicVineAdaptorException {
String issue = request.getIssueNumber();
boolean skipCache = request.isSkipCache();
this.log.info(
"Preparing to retrieve issue={} for volume={} (skipCache={})",
issue,
volume,
request.isSkipCache());
"Preparing to retrieve issue={} for volume={} (skipCache={})", issue, volume, skipCache);

return this.queryForIssuesAdaptor.execute(request.getApiKey(), volume, issue);
}
Expand Down
Expand Up @@ -18,16 +18,25 @@

package org.comixed.net;

public class GetScrapingIssueRequest {
import com.fasterxml.jackson.annotation.JsonProperty;

public class GetScrapingIssueRequest {
@JsonProperty("apiKey")
private String apiKey;

@JsonProperty("skipCache")
private boolean skipCache;

@JsonProperty("issueNumber")
private String issueNumber;

public GetScrapingIssueRequest() {}

public GetScrapingIssueRequest(final String apiKey, final boolean skipCache) {
public GetScrapingIssueRequest(
final String apiKey, final boolean skipCache, final String issueNumber) {
this.apiKey = apiKey;
this.skipCache = skipCache;
this.issueNumber = issueNumber;
}

public String getApiKey() {
Expand All @@ -37,4 +46,8 @@ public String getApiKey() {
public boolean isSkipCache() {
return skipCache;
}

public String getIssueNumber() {
return issueNumber;
}
}
Expand Up @@ -40,7 +40,8 @@ public ScrapingIssue execute(String apiKey, Integer volume, String issueNumber)

while (!issueNumber.isEmpty()
&& !issueNumber.equals("0")
&& "123456789".indexOf(issueNumber.substring(0, 1)) == -1) {
&& "123456789%ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(issueNumber.toUpperCase().substring(0, 1))
== -1) {
issueNumber = issueNumber.substring(1);
}

Expand Down
Expand Up @@ -124,8 +124,7 @@ public void testQueryForIssueAdaptorRaisesException() throws ComicVineAdaptorExc
try {
controller.queryForIssue(
TEST_VOLUME,
TEST_ISSUE_NUMBER,
new GetScrapingIssueRequest(TEST_API_KEY, TEST_SKIP_CACHE));
new GetScrapingIssueRequest(TEST_API_KEY, TEST_SKIP_CACHE, TEST_ISSUE_NUMBER));
} finally {
Mockito.verify(queryForIssueAdaptor, Mockito.times(1))
.execute(TEST_API_KEY, TEST_VOLUME, TEST_ISSUE_NUMBER);
Expand All @@ -142,8 +141,7 @@ public void testQueryForIssue() throws ComicVineAdaptorException {
ScrapingIssue result =
controller.queryForIssue(
TEST_VOLUME,
TEST_ISSUE_NUMBER,
new GetScrapingIssueRequest(TEST_API_KEY, TEST_SKIP_CACHE));
new GetScrapingIssueRequest(TEST_API_KEY, TEST_SKIP_CACHE, TEST_ISSUE_NUMBER));

assertNotNull(result);
assertSame(comicIssue, result);
Expand Down

0 comments on commit bcdda4f

Please sign in to comment.