Commit d2d27f7c authored by nanahira's avatar nanahira

add api

parent a12f4540
Pipeline #19571 passed with stages
in 3 minutes and 7 seconds
This diff is collapsed.
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
"start": "ng serve", "start": "ng serve",
"build": "ng build", "build": "ng build",
"watch": "ng build --watch --configuration development", "watch": "ng build --watch --configuration development",
"test": "ng test" "test": "ng test",
"gen": "ng-openapi-gen --input http://localhost:3000/docs-json --output src/app/api"
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
"karma-coverage": "~2.1.0", "karma-coverage": "~2.1.0",
"karma-jasmine": "~4.0.0", "karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0", "karma-jasmine-html-reporter": "~1.7.0",
"ng-openapi-gen": "^0.23.0",
"typescript": "~4.6.2" "typescript": "~4.6.2"
} }
} }
/* tslint:disable */
/* eslint-disable */
import { Injectable } from '@angular/core';
/**
* Global configuration
*/
@Injectable({
providedIn: 'root',
})
export class ApiConfiguration {
rootUrl: string = '';
}
/**
* Parameters for `ApiModule.forRoot()`
*/
export interface ApiConfigurationParams {
rootUrl?: string;
}
/* tslint:disable */
/* eslint-disable */
import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ApiConfiguration, ApiConfigurationParams } from './api-configuration';
import { TournamentService } from './services/tournament.service';
import { ParticipantService } from './services/participant.service';
import { MatchService } from './services/match.service';
/**
* Module that provides all services and configuration.
*/
@NgModule({
imports: [],
exports: [],
declarations: [],
providers: [
TournamentService,
ParticipantService,
MatchService,
ApiConfiguration
],
})
export class ApiModule {
static forRoot(params: ApiConfigurationParams): ModuleWithProviders<ApiModule> {
return {
ngModule: ApiModule,
providers: [
{
provide: ApiConfiguration,
useValue: params
}
]
}
}
constructor(
@Optional() @SkipSelf() parentModule: ApiModule,
@Optional() http: HttpClient
) {
if (parentModule) {
throw new Error('ApiModule is already loaded. Import in your base AppModule only.');
}
if (!http) {
throw new Error('You need to import the HttpClientModule in your AppModule! \n' +
'See also https://github.com/angular/angular/issues/20575');
}
}
}
/* tslint:disable */
/* eslint-disable */
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ApiConfiguration } from './api-configuration';
/**
* Base class for services
*/
@Injectable()
export class BaseService {
constructor(
protected config: ApiConfiguration,
protected http: HttpClient
) {
}
private _rootUrl: string = '';
/**
* Returns the root url for all operations in this service. If not set directly in this
* service, will fallback to `ApiConfiguration.rootUrl`.
*/
get rootUrl(): string {
return this._rootUrl || this.config.rootUrl;
}
/**
* Sets the root URL for API operations in this service.
*/
set rootUrl(rootUrl: string) {
this._rootUrl = rootUrl;
}
}
export { RuleSettingsPartial } from './models/rule-settings-partial';
export { CreateTournamentDto } from './models/create-tournament-dto';
export { Match } from './models/match';
export { ParticipantScore } from './models/participant-score';
export { Participant } from './models/participant';
export { Tournament } from './models/tournament';
export { TournamentReturnMessageDto } from './models/tournament-return-message-dto';
export { TournamentPaginatedReturnMessageDto } from './models/tournament-paginated-return-message-dto';
export { UpdateTournamentDto } from './models/update-tournament-dto';
export { BlankReturnMessageDto } from './models/blank-return-message-dto';
export { CreateParticipantDto } from './models/create-participant-dto';
export { ParticipantReturnMessageDto } from './models/participant-return-message-dto';
export { ParticipantPaginatedReturnMessageDto } from './models/participant-paginated-return-message-dto';
export { UpdateParticipantDto } from './models/update-participant-dto';
export { CreateParticipantDtoImportData } from './models/create-participant-dto-import-data';
export { ParticipantImportEntry } from './models/participant-import-entry';
export { ParticipantImportEntryReturnMessageDto } from './models/participant-import-entry-return-message-dto';
export { MatchReturnMessageDto } from './models/match-return-message-dto';
export { MatchPaginatedReturnMessageDto } from './models/match-paginated-return-message-dto';
export { UpdateMatchDto } from './models/update-match-dto';
/* tslint:disable */
/* eslint-disable */
export interface BlankReturnMessageDto {
/**
* Return message
*/
message: string;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
}
/* tslint:disable */
/* eslint-disable */
import { CreateParticipantDto } from './create-participant-dto';
export interface CreateParticipantDtoImportData {
/**
* Import data
*/
data: Array<CreateParticipantDto>;
}
/* tslint:disable */
/* eslint-disable */
export interface CreateParticipantDto {
/**
* 名称
*/
name: string;
/**
* 是否已经退赛
*/
quit: boolean;
/**
* 比赛 ID。
*/
tournamentId: number;
}
/* tslint:disable */
/* eslint-disable */
import { RuleSettingsPartial } from './rule-settings-partial';
export interface CreateTournamentDto {
/**
* 协作者 MC ID
*/
collaborators?: Array<number>;
/**
* 描述
*/
description: string;
/**
* 名称
*/
name: string;
/**
* 规则
*/
rule: 'SingleElimination' | 'Swiss';
ruleSettings?: RuleSettingsPartial;
/**
* 可见性
*/
visibility: 'Public' | 'Internal' | 'Private';
}
/* tslint:disable */
/* eslint-disable */
import { Match } from './match';
export interface MatchPaginatedReturnMessageDto {
/**
* Return data.
*/
data?: Array<Match>;
/**
* Return message
*/
message: string;
/**
* Current page.
*/
pageCount: number;
/**
* Records per page.
*/
recordsPerPage: number;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
/**
* Total record count.
*/
total: number;
/**
* Total page count.
*/
totalPages: number;
}
/* tslint:disable */
/* eslint-disable */
import { Match } from './match';
export interface MatchReturnMessageDto {
/**
* Return data.
*/
data?: Match;
/**
* Return message
*/
message: string;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
}
/* tslint:disable */
/* eslint-disable */
import { Participant } from './participant';
import { Tournament } from './tournament';
export interface Match {
childMatch: Match;
/**
* 晋级通往的比赛 ID
*/
childMatchId?: number;
createTime: string;
deleteTime: string;
id: number;
/**
* 是否为季军赛。
*/
isThirdPlaceMatch: boolean;
/**
* The nth page, starting with 1.
*/
pageCount?: number;
parentMatches: Array<Match>;
player1: Participant;
/**
* 玩家 1 ID
*/
player1Id: number;
/**
* 玩家 1 分数
*/
player1Score?: number;
player2: Participant;
/**
* 玩家 2 ID
*/
player2Id: number;
/**
* 玩家 2 分数
*/
player2Score?: number;
/**
* Records per page.
*/
recordsPerPage?: number;
/**
* 比赛轮次。
*/
round: number;
/**
* 比赛状态
*/
status: 'Pending' | 'Running' | 'Finished' | 'Abandoned';
tournament: Tournament;
/**
* 比赛 ID。
*/
tournamentId: number;
updateTime: string;
winner: Participant;
/**
* 胜者 ID
*/
winnerId: number;
}
/* tslint:disable */
/* eslint-disable */
import { ParticipantImportEntry } from './participant-import-entry';
export interface ParticipantImportEntryReturnMessageDto {
/**
* Return data.
*/
data?: ParticipantImportEntry;
/**
* Return message
*/
message: string;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
}
/* tslint:disable */
/* eslint-disable */
import { Participant } from './participant';
export interface ParticipantImportEntry {
/**
* Import entry
*/
entry: Participant;
/**
* Import result
*/
result: string;
}
/* tslint:disable */
/* eslint-disable */
import { Participant } from './participant';
export interface ParticipantPaginatedReturnMessageDto {
/**
* Return data.
*/
data?: Array<Participant>;
/**
* Return message
*/
message: string;
/**
* Current page.
*/
pageCount: number;
/**
* Records per page.
*/
recordsPerPage: number;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
/**
* Total record count.
*/
total: number;
/**
* Total page count.
*/
totalPages: number;
}
/* tslint:disable */
/* eslint-disable */
import { Participant } from './participant';
export interface ParticipantReturnMessageDto {
/**
* Return data.
*/
data?: Participant;
/**
* Return message
*/
message: string;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
}
/* tslint:disable */
/* eslint-disable */
export interface ParticipantScore {
/**
* 轮空
*/
bye: number;
/**
* 平场
*/
draw: number;
/**
* 负场
*/
lose: number;
/**
* 排名
*/
rank: number;
/**
* 得分
*/
score: number;
/**
* 平局分
*/
tieBreaker: number;
/**
* 胜场
*/
win: number;
}
/* tslint:disable */
/* eslint-disable */
import { Match } from './match';
import { ParticipantScore } from './participant-score';
import { Tournament } from './tournament';
export interface Participant {
createTime: string;
deleteTime: string;
id: number;
/**
* 参与的比赛。
*/
matches: Array<Match>;
matches1: Array<Match>;
matches2: Array<Match>;
/**
* 名称
*/
name: string;
/**
* The nth page, starting with 1.
*/
pageCount?: number;
/**
* 是否已经退赛
*/
quit: boolean;
/**
* Records per page.
*/
recordsPerPage?: number;
score: ParticipantScore;
tournament: Tournament;
/**
* 比赛 ID。
*/
tournamentId: number;
updateTime: string;
wonMatches: Array<Match>;
}
/* tslint:disable */
/* eslint-disable */
export interface RuleSettingsPartial {
/**
* 瑞士轮轮空分。
*/
byeScore?: number;
/**
* 瑞士轮平局分。
*/
drawScore?: number;
/**
* 淘汰赛中是否是季军塞
*/
hasThirdPlaceMatch?: boolean;
/**
* 瑞士轮局数。
*/
rounds?: number;
/**
* 瑞士轮胜利分。
*/
winScore?: number;
}
/* tslint:disable */
/* eslint-disable */
import { Tournament } from './tournament';
export interface TournamentPaginatedReturnMessageDto {
/**
* Return data.
*/
data?: Array<Tournament>;
/**
* Return message
*/
message: string;
/**
* Current page.
*/
pageCount: number;
/**
* Records per page.
*/
recordsPerPage: number;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
/**
* Total record count.
*/
total: number;
/**
* Total page count.
*/
totalPages: number;
}
/* tslint:disable */
/* eslint-disable */
import { Tournament } from './tournament';
export interface TournamentReturnMessageDto {
/**
* Return data.
*/
data?: Tournament;
/**
* Return message
*/
message: string;
/**
* Return code
*/
statusCode: number;
/**
* Whether success.
*/
success: boolean;
}
/* tslint:disable */
/* eslint-disable */
import { Match } from './match';
import { Participant } from './participant';
import { RuleSettingsPartial } from './rule-settings-partial';
export interface Tournament {
/**
* 协作者 MC ID
*/
collaborators?: Array<number>;
createTime: string;
/**
* 创建时间
*/
createdAt: string;
/**
* 创建者 MC ID
*/
creator: number;
deleteTime: string;
/**
* 描述
*/
description: string;
id: number;
/**
* 对阵图树
*/
matchTree: Match;
matches: Array<Match>;
/**
* 名称
*/
name: string;
/**
* The nth page, starting with 1.
*/
pageCount?: number;
participants: Array<Participant>;
/**
* Records per page.
*/
recordsPerPage?: number;
/**
* 规则
*/
rule: 'SingleElimination' | 'Swiss';
ruleSettings?: RuleSettingsPartial;
/**
* 状态
*/
status: 'Ready' | 'Running' | 'Finished';
updateTime: string;
/**
* 可见性
*/
visibility: 'Public' | 'Internal' | 'Private';
}
/* tslint:disable */
/* eslint-disable */
export interface UpdateMatchDto {
/**
* 玩家 1 分数
*/
player1Score?: number;
/**
* 玩家 2 分数
*/
player2Score?: number;
/**
* 胜者 ID
*/
winnerId?: number;
}
/* tslint:disable */
/* eslint-disable */
export interface UpdateParticipantDto {
/**
* 名称
*/
name?: string;
/**
* 是否已经退赛
*/
quit?: boolean;
}
/* tslint:disable */
/* eslint-disable */
export interface UpdateTournamentDto {
/**
* 协作者 MC ID
*/
collaborators?: Array<number>;
/**
* 描述
*/
description?: string;
/**
* 名称
*/
name?: string;
/**
* 可见性
*/
visibility?: 'Public' | 'Internal' | 'Private';
}
This diff is collapsed.
export { TournamentService } from './services/tournament.service';
export { ParticipantService } from './services/participant.service';
export { MatchService } from './services/match.service';
/* tslint:disable */
/* eslint-disable */
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse, HttpContext } from '@angular/common/http';
import { BaseService } from '../base-service';
import { ApiConfiguration } from '../api-configuration';
import { StrictHttpResponse } from '../strict-http-response';
import { RequestBuilder } from '../request-builder';
import { Observable } from 'rxjs';
import { map, filter } from 'rxjs/operators';
import { BlankReturnMessageDto } from '../models/blank-return-message-dto';
import { MatchPaginatedReturnMessageDto } from '../models/match-paginated-return-message-dto';
import { MatchReturnMessageDto } from '../models/match-return-message-dto';
import { UpdateMatchDto } from '../models/update-match-dto';
@Injectable({
providedIn: 'root',
})
export class MatchService extends BaseService {
constructor(
config: ApiConfiguration,
http: HttpClient
) {
super(config, http);
}
/**
* Path part for operation matchControllerFindOne
*/
static readonly MatchControllerFindOnePath = '/api/match/{id}';
/**
* Find a Match by id.
*
*
*
* This method provides access to the full `HttpResponse`, allowing access to response headers.
* To access only the response body, use `matchControllerFindOne()` instead.
*
* This method doesn't expect any request body.
*/
matchControllerFindOne$Response(params: {
/**
* MC Token
*/
Authorization?: string;
id: number;
context?: HttpContext
}
): Observable<StrictHttpResponse<MatchReturnMessageDto>> {
const rb = new RequestBuilder(this.rootUrl, MatchService.MatchControllerFindOnePath, 'get');
if (params) {
rb.header('Authorization', params.Authorization, {});
rb.path('id', params.id, {});
}
return this.http.request(rb.build({
responseType: 'json',
accept: 'application/json',
context: params?.context
})).pipe(
filter((r: any) => r instanceof HttpResponse),
map((r: HttpResponse<any>) => {
return r as StrictHttpResponse<MatchReturnMessageDto>;
})
);
}
/**
* Find a Match by id.
*
*
*
* This method provides access to only to the response body.
* To access the full response (for headers, for example), `matchControllerFindOne$Response()` instead.
*
* This method doesn't expect any request body.
*/
matchControllerFindOne(params: {
/**
* MC Token
*/
Authorization?: string;
id: number;
context?: HttpContext
}
): Observable<MatchReturnMessageDto> {
return this.matchControllerFindOne$Response(params).pipe(
map((r: StrictHttpResponse<MatchReturnMessageDto>) => r.body as MatchReturnMessageDto)
);
}
/**
* Path part for operation matchControllerUpdate
*/
static readonly MatchControllerUpdatePath = '/api/match/{id}';
/**
* Update a Match by id.
*
*
*
* This method provides access to the full `HttpResponse`, allowing access to response headers.
* To access only the response body, use `matchControllerUpdate()` instead.
*
* This method sends `application/json` and handles request body of type `application/json`.
*/
matchControllerUpdate$Response(params: {
/**
* MC Token
*/
Authorization?: string;
id: number;
context?: HttpContext
body: UpdateMatchDto
}
): Observable<StrictHttpResponse<BlankReturnMessageDto>> {
const rb = new RequestBuilder(this.rootUrl, MatchService.MatchControllerUpdatePath, 'patch');
if (params) {
rb.header('Authorization', params.Authorization, {});
rb.path('id', params.id, {});
rb.body(params.body, 'application/json');
}
return this.http.request(rb.build({
responseType: 'json',
accept: 'application/json',
context: params?.context
})).pipe(
filter((r: any) => r instanceof HttpResponse),
map((r: HttpResponse<any>) => {
return r as StrictHttpResponse<BlankReturnMessageDto>;
})
);
}
/**
* Update a Match by id.
*
*
*
* This method provides access to only to the response body.
* To access the full response (for headers, for example), `matchControllerUpdate$Response()` instead.
*
* This method sends `application/json` and handles request body of type `application/json`.
*/
matchControllerUpdate(params: {
/**
* MC Token
*/
Authorization?: string;
id: number;
context?: HttpContext
body: UpdateMatchDto
}
): Observable<BlankReturnMessageDto> {
return this.matchControllerUpdate$Response(params).pipe(
map((r: StrictHttpResponse<BlankReturnMessageDto>) => r.body as BlankReturnMessageDto)
);
}
/**
* Path part for operation matchControllerFindAll
*/
static readonly MatchControllerFindAllPath = '/api/match';
/**
* Find all Match.
*
*
*
* This method provides access to the full `HttpResponse`, allowing access to response headers.
* To access only the response body, use `matchControllerFindAll()` instead.
*
* This method doesn't expect any request body.
*/
matchControllerFindAll$Response(params?: {
/**
* MC Token
*/
Authorization?: string;
/**
* The nth page, starting with 1.
*/
pageCount?: number;
/**
* Records per page.
*/
recordsPerPage?: number;
id?: number;
/**
* 比赛 ID。
*/
tournamentId?: number;
/**
* 比赛轮次。
*/
round?: number;
/**
* 是否为季军赛。
*/
isThirdPlaceMatch?: boolean;
/**
* 比赛状态
*/
status?: 'Pending' | 'Running' | 'Finished' | 'Abandoned';
/**
* 玩家 1 ID
*/
player1Id?: number;
/**
* 玩家 1 分数
*/
player1Score?: number;
/**
* 玩家 2 ID
*/
player2Id?: number;
/**
* 玩家 2 分数
*/
player2Score?: number;
/**
* 胜者 ID
*/
winnerId?: number;
/**
* 晋级通往的比赛 ID
*/
childMatchId?: number;
context?: HttpContext
}
): Observable<StrictHttpResponse<MatchPaginatedReturnMessageDto>> {
const rb = new RequestBuilder(this.rootUrl, MatchService.MatchControllerFindAllPath, 'get');
if (params) {
rb.header('Authorization', params.Authorization, {});
rb.query('pageCount', params.pageCount, {});
rb.query('recordsPerPage', params.recordsPerPage, {});
rb.query('id', params.id, {});
rb.query('tournamentId', params.tournamentId, {});
rb.query('round', params.round, {});
rb.query('isThirdPlaceMatch', params.isThirdPlaceMatch, {});
rb.query('status', params.status, {});
rb.query('player1Id', params.player1Id, {});
rb.query('player1Score', params.player1Score, {});
rb.query('player2Id', params.player2Id, {});
rb.query('player2Score', params.player2Score, {});
rb.query('winnerId', params.winnerId, {});
rb.query('childMatchId', params.childMatchId, {});
}
return this.http.request(rb.build({
responseType: 'json',
accept: 'application/json',
context: params?.context
})).pipe(
filter((r: any) => r instanceof HttpResponse),
map((r: HttpResponse<any>) => {
return r as StrictHttpResponse<MatchPaginatedReturnMessageDto>;
})
);
}
/**
* Find all Match.
*
*
*
* This method provides access to only to the response body.
* To access the full response (for headers, for example), `matchControllerFindAll$Response()` instead.
*
* This method doesn't expect any request body.
*/
matchControllerFindAll(params?: {
/**
* MC Token
*/
Authorization?: string;
/**
* The nth page, starting with 1.
*/
pageCount?: number;
/**
* Records per page.
*/
recordsPerPage?: number;
id?: number;
/**
* 比赛 ID。
*/
tournamentId?: number;
/**
* 比赛轮次。
*/
round?: number;
/**
* 是否为季军赛。
*/
isThirdPlaceMatch?: boolean;
/**
* 比赛状态
*/
status?: 'Pending' | 'Running' | 'Finished' | 'Abandoned';
/**
* 玩家 1 ID
*/
player1Id?: number;
/**
* 玩家 1 分数
*/
player1Score?: number;
/**
* 玩家 2 ID
*/
player2Id?: number;
/**
* 玩家 2 分数
*/
player2Score?: number;
/**
* 胜者 ID
*/
winnerId?: number;
/**
* 晋级通往的比赛 ID
*/
childMatchId?: number;
context?: HttpContext
}
): Observable<MatchPaginatedReturnMessageDto> {
return this.matchControllerFindAll$Response(params).pipe(
map((r: StrictHttpResponse<MatchPaginatedReturnMessageDto>) => r.body as MatchPaginatedReturnMessageDto)
);
}
}
This diff is collapsed.
This diff is collapsed.
/* tslint:disable */
/* eslint-disable */
import { HttpResponse } from '@angular/common/http';
/**
* Constrains the http response to not have the body defined as `T | null`, but `T` only.
*/
export type StrictHttpResponse<T> = HttpResponse<T> & {
readonly body: T;
}
...@@ -6,10 +6,19 @@ import { AppComponent } from './app.component'; ...@@ -6,10 +6,19 @@ import { AppComponent } from './app.component';
import { ToastComponent } from './toast/toast.component'; import { ToastComponent } from './toast/toast.component';
import { TournamentComponent } from './tournament/tournament.component'; import { TournamentComponent } from './tournament/tournament.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { ApiModule } from './api/api.module';
import { environment } from 'src/environments/environment';
@NgModule({ @NgModule({
declarations: [AppComponent, ToastComponent, TournamentComponent], declarations: [AppComponent, ToastComponent, TournamentComponent],
imports: [BrowserModule, AppRoutingModule, NgbModule], imports: [
BrowserModule,
AppRoutingModule,
NgbModule,
ApiModule.forRoot({
rootUrl: environment.production ? '' : 'http://localhost:3000',
}),
],
providers: [], providers: [],
bootstrap: [AppComponent], bootstrap: [AppComponent],
}) })
......
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