Implement basic search by id

This commit is contained in:
2026-02-10 16:49:22 +05:00
parent e154e232df
commit 4da7facb65
2 changed files with 91 additions and 0 deletions

View File

@@ -18,4 +18,15 @@ public interface KodikAPI {
@Field("limit") int limit,
@Field("with_material_data") int withMaterialData);
@FormUrlEncoded
@POST("search")
Call<KodikResponse> searchId(
@Field("token") String token,
@Field("id") String id,
@Field("kinopoisk_id") String kinopoiskId,
@Field("shikimori_id") String shikimoriId,
@Field("imdb_id") String imdbId,
@Field("limit") int limit,
@Field("with_material_data") int withMaterialData);
}

View File

@@ -50,4 +50,84 @@ public class SearchResource {
}
}
@GET
@Path("/kodik_id")
public KodikResponse searchKodikId(@QueryParam("kodikID") String kodikID) throws ServiceUnavailableException {
try {
Response<KodikResponse> response = kodikAPI
.searchId(tokenProvider.getKodikToken(),
kodikID,
null,
null,
null,
100,
1)
.execute();
if (!response.isSuccessful()) {
LOG.errorv("failed search request with kodikID {0}, response code {1}, message {2}, body {3}", kodikID,
response.code(),
response.message(),
response.raw().body());
throw new BadRequestException("bad response, code: " + response.code());
}
return searchFilterService.filter(response.body());
} catch (IOException e) {
LOG.warn("i/o error", e);
throw new ServiceUnavailableException("i/o error");
}
}
@GET
@Path("/kinopoisk_id")
public KodikResponse searchKinopoiskId(@QueryParam("kinopoiskID") String kinopoiskID)
throws ServiceUnavailableException {
try {
Response<KodikResponse> response = kodikAPI
.searchId(tokenProvider.getKodikToken(),
null,
kinopoiskID,
null,
null,
100,
1)
.execute();
if (!response.isSuccessful()) {
LOG.errorv("failed search request with kinopoiskID {0}, response code {1}, message {2}", kinopoiskID,
response.code(),
response.message());
throw new BadRequestException("bad response, code: " + response.code());
}
return searchFilterService.filter(response.body());
} catch (IOException e) {
LOG.warn("i/o error", e);
throw new ServiceUnavailableException("i/o error");
}
}
@GET
@Path("/shikimori_id")
public KodikResponse searchShikimoriId(@QueryParam("shikimoriID") String shikimoriID)
throws ServiceUnavailableException {
try {
Response<KodikResponse> response = kodikAPI
.searchId(tokenProvider.getKodikToken(),
null,
null,
shikimoriID,
null,
100,
1)
.execute();
if (!response.isSuccessful()) {
LOG.errorv("failed search request with shikimoriID {0}, response code {1}, message {2}", shikimoriID,
response.code(),
response.message());
throw new BadRequestException("bad response, code: " + response.code());
}
return searchFilterService.filter(response.body());
} catch (IOException e) {
LOG.warn("i/o error", e);
throw new ServiceUnavailableException("i/o error");
}
}
}