feat: demo manga search

This commit is contained in:
2024-07-05 01:04:49 +03:00
parent c7d76419f7
commit 37149c83c4
8 changed files with 174 additions and 10 deletions

View File

@@ -0,0 +1,27 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable, catchError, map, throwError } from "rxjs";
import { ESiteUrls } from "../urls";
import { IRulibSearchResult } from "./rulib.dto";
//TODO: Make abstract classes
@Injectable({
providedIn: "root",
})
export class LibSocialParserService {
private readonly url = ESiteUrls.LIB_SOCIAL;
constructor(private readonly http: HttpClient) {}
searchManga(query: string): Observable<IRulibSearchResult> {
return this.http
.get(`${this.url}/api/manga?fields[]=rate_avg&fields[]=rate&q=${query}&site_id[]=1`)
.pipe(
map((data: object) => {
return data as IRulibSearchResult;
}),
catchError((error) => {
return throwError(() => `Now found ${error}`);
}),
);
}
}

View File

@@ -0,0 +1,79 @@
export interface IRulibSearchResult {
data: Datum[];
links: Links;
meta: Meta;
}
//TODO: Make normal namings
export interface Datum {
id: number;
name: string;
rus_name: string;
eng_name: string;
slug: string;
slug_url: string;
cover: Cover;
ageRestriction: AgeRestriction;
site: number;
type: AgeRestriction;
rating: Rating;
is_licensed: boolean;
model: Model;
status: AgeRestriction;
releaseDateString: string;
}
export interface AgeRestriction {
id: number;
label: Label;
}
export enum Label {
The12 = "12+",
The6 = "6+",
Завершён = "Завершён",
КомиксЗападный = "Комикс западный",
Манга = "Манга",
Манхва = "Манхва",
Маньхуа = "Маньхуа",
Нет = "Нет",
Онгоинг = "Онгоинг",
Приостановлен = "Приостановлен",
}
export interface Cover {
filename: string;
thumbnail: string;
default: string;
md: string;
}
export enum Model {
Manga = "manga",
}
export interface Rating {
average: string;
averageFormated: string;
votes: number;
votesFormated: string;
user: number;
}
export interface Links {
first: string;
last: null;
prev: null;
next: string;
}
export interface Meta {
current_page: number;
from: number;
path: string;
per_page: number;
to: number;
page: number;
has_next_page: boolean;
seed: string;
}