Commit 1cf37d07 authored by nanahira's avatar nanahira

ad

parent 8c172da7
Pipeline #17959 passed with stages
in 2 minutes and 46 seconds
export { Blacklist } from './models/blacklist';
export { BlacklistAccount } from './models/blacklist-account';
export { BlacklistAccountPaginatedReturnMessageDto } from './models/blacklist-account-paginated-return-message-dto';
export { Ad } from './models/ad';
export { AdReturnMessageDto } from './models/ad-return-message-dto';
export { StringReturnMessageDto } from './models/string-return-message-dto';
/* tslint:disable */
/* eslint-disable */
import { Ad } from './ad';
export interface AdReturnMessageDto {
/**
* Return data.
*/
data?: Ad;
/**
* Return message
*/
message: string;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
}
/* tslint:disable */
/* eslint-disable */
export interface Ad {
/**
* Ad click count
*/
clickCount: number;
/**
* Ad content
*/
content: string;
createTime: string;
deleteTime: string;
/**
* Ad is enabled
*/
enabled: boolean;
id: number;
/**
* Ad link
*/
link?: string;
/**
* The nth page, starting with 1.
*/
pageCount?: number;
/**
* Records per page.
*/
recordsPerPage?: number;
updateTime: string;
/**
* Ad view count
*/
viewCount: number;
}
......@@ -9,6 +9,7 @@ import { RequestBuilder } from '../request-builder';
import { Observable } from 'rxjs';
import { map, filter } from 'rxjs/operators';
import { AdReturnMessageDto } from '../models/ad-return-message-dto';
import { BlacklistAccountPaginatedReturnMessageDto } from '../models/blacklist-account-paginated-return-message-dto';
import { StringReturnMessageDto } from '../models/string-return-message-dto';
......@@ -124,7 +125,7 @@ export class ApiService extends BaseService {
/**
* Path part for operation adControllerGetAd
*/
static readonly AdControllerGetAdPath = '/api/ad';
static readonly AdControllerGetAdPath = '/api/ad/random';
/**
* Get ad.
......@@ -137,7 +138,7 @@ export class ApiService extends BaseService {
* This method doesn't expect any request body.
*/
adControllerGetAd$Response(params?: {
}): Observable<StrictHttpResponse<StringReturnMessageDto>> {
}): Observable<StrictHttpResponse<AdReturnMessageDto>> {
const rb = new RequestBuilder(this.rootUrl, ApiService.AdControllerGetAdPath, 'get');
if (params) {
......@@ -149,7 +150,7 @@ export class ApiService extends BaseService {
})).pipe(
filter((r: any) => r instanceof HttpResponse),
map((r: HttpResponse<any>) => {
return r as StrictHttpResponse<StringReturnMessageDto>;
return r as StrictHttpResponse<AdReturnMessageDto>;
})
);
}
......@@ -165,9 +166,63 @@ export class ApiService extends BaseService {
* This method doesn't expect any request body.
*/
adControllerGetAd(params?: {
}): Observable<StringReturnMessageDto> {
}): Observable<AdReturnMessageDto> {
return this.adControllerGetAd$Response(params).pipe(
map((r: StrictHttpResponse<AdReturnMessageDto>) => r.body as AdReturnMessageDto)
);
}
/**
* Path part for operation adControllerClickAd
*/
static readonly AdControllerClickAdPath = '/api/ad/click/{id}';
/**
* Click ad.
*
*
*
* This method provides access to the full `HttpResponse`, allowing access to response headers.
* To access only the response body, use `adControllerClickAd()` instead.
*
* This method doesn't expect any request body.
*/
adControllerClickAd$Response(params: {
id: number;
}): Observable<StrictHttpResponse<StringReturnMessageDto>> {
const rb = new RequestBuilder(this.rootUrl, ApiService.AdControllerClickAdPath, 'get');
if (params) {
rb.path('id', params.id, {});
}
return this.http.request(rb.build({
responseType: 'json',
accept: 'application/json'
})).pipe(
filter((r: any) => r instanceof HttpResponse),
map((r: HttpResponse<any>) => {
return r as StrictHttpResponse<StringReturnMessageDto>;
})
);
}
/**
* Click ad.
*
*
*
* This method provides access to only to the response body.
* To access the full response (for headers, for example), `adControllerClickAd$Response()` instead.
*
* This method doesn't expect any request body.
*/
adControllerClickAd(params: {
id: number;
}): Observable<StringReturnMessageDto> {
return this.adControllerClickAd$Response(params).pipe(
map((r: StrictHttpResponse<StringReturnMessageDto>) => r.body as StringReturnMessageDto)
);
}
......
......@@ -4,8 +4,8 @@
<div class="container">
<div class="row" *ngIf="ad">
<ul class="list-group">
<li class="list-group-item list-group-item-info" [innerHTML]="ad"></li>
<ul class="list-group" (click)="onAdClick()">
<li class="list-group-item list-group-item-info" [innerHTML]="ad['content']"></li>
</ul>
</div>
<br *ngIf="ad">
......
......@@ -4,6 +4,7 @@ import { BlacklistAccount } from './api/models/blacklist-account';
import { ApiService } from './api/services/api.service';
import { lastValueFrom } from 'rxjs';
import * as moment from 'moment';
import { Ad } from './api/models';
@Component({
selector: 'app-root',
......@@ -14,7 +15,7 @@ export class AppComponent implements AfterViewInit {
search = '';
displayingAccount = '';
title = '蔷蔷挂人查询';
ad = '';
ad: Ad | null = null;
result?: BlacklistAccount[];
constructor(public toast: ToastService, private api: ApiService) {}
......@@ -28,13 +29,32 @@ export class AppComponent implements AfterViewInit {
async initAd() {
try {
const ad = await lastValueFrom(this.api.adControllerGetAd());
this.ad = ad.data!;
const { data: ad } = await lastValueFrom(this.api.adControllerGetAd());
if (ad) {
this.ad = ad;
}
} catch (e) {
console.log(`Failed to load ad: ${(e as Error).toString()}`);
}
}
openInNewTab(href: string) {
Object.assign(document.createElement('a'), {
target: '_blank',
rel: 'noopener noreferrer',
href,
}).click();
}
async onAdClick() {
const clickResult = await lastValueFrom(
this.api.adControllerClickAd({ id: this.ad!.id })
);
if (clickResult?.data) {
this.openInNewTab(clickResult.data);
}
}
async onSearch() {
this.result = undefined;
const search = this.search.trim();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment