0
0
Fork 0

ディレクトリ再編

This commit is contained in:
xeltica 2021-09-04 11:00:38 +09:00
parent cb924ff92b
commit 85d471efbb
45 changed files with 204 additions and 41 deletions

View file

@ -0,0 +1,15 @@
/**
* API
* @author Xeltica
*/
import { Get, JsonController } from 'routing-controllers';
@JsonController('/meta')
export class MetaController {
@Get() get() {
return {
honi: 'ほに',
};
}
}

View file

@ -0,0 +1,31 @@
/**
* API
* @author Xeltica
*/
import { Get, JsonController, QueryParam } from 'routing-controllers';
import { getRanking } from '../functions/ranking';
import { getUserCount } from '../functions/users';
import { getState } from '../store';
@JsonController('/ranking')
export class RankingController {
@Get()
async get(@QueryParam('limit', { required: false }) limit?: string) {
return this.getResponse(getState().nowCalculating, limit ? Number(limit) : undefined);
}
private async getResponse(isCalculating: boolean, limit?: number) {
const ranking = isCalculating ? [] : (await getRanking(limit)).map((u) => ({
id: u.id,
username: u.username,
host: u.host,
rating: u.rating,
}));
return {
isCalculating,
userCount: await getUserCount(),
ranking,
};
}
}

View file

@ -0,0 +1,14 @@
/**
* API
* @author Xeltica
*/
import { CurrentUser, Get, JsonController } from 'routing-controllers';
import { User } from '../models/entities/user';
@JsonController('/session')
export class SessionController {
@Get() get(@CurrentUser({ required: true }) user: User) {
return user;
}
}