diff --git a/backend/karaoqueue-backend/src/controllers/auth.controller.ts b/backend/karaoqueue-backend/src/controllers/auth.controller.ts new file mode 100644 index 0000000..af22fd5 --- /dev/null +++ b/backend/karaoqueue-backend/src/controllers/auth.controller.ts @@ -0,0 +1,15 @@ +import { Post, BodyParam, Body, Res, Req, JsonController, UseBefore, Get, CookieParam } from "routing-controllers"; +import { UserCredential } from "../models/usercredential.model"; + +@JsonController("/auth") +export class AuthenticationController { + @Post("/login") + doLogin(@Body() usercredential: UserCredential, @Res() res: any) { + return "//TODO login"; + } + + @Get("/logout") + doLogout() { + return "//TODO logout"; + } +} \ No newline at end of file diff --git a/backend/karaoqueue-backend/src/controllers/queue.controller.ts b/backend/karaoqueue-backend/src/controllers/queue.controller.ts new file mode 100644 index 0000000..0e4738e --- /dev/null +++ b/backend/karaoqueue-backend/src/controllers/queue.controller.ts @@ -0,0 +1,54 @@ +import { Controller, Get, Res, Post, Delete, Patch, Req } from "routing-controllers"; + + +@Controller("/queue") +export class QueueController { + + /* + * Fetch entry Queue content + */ + @Get() + getQueue(@Req() req: any, @Res() res: any) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify({ placeholder: "//TODO fetch" })); + } + + /* + * Add entry to Queue + */ + @Post() + addEntry(@Req() req: any, @Res() res: any) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify({ placeholder: "//TODO add" })); + } + + /* + * + */ + @Delete() + clearQueue(@Req() req: any, @Res() res: any) { + return "//TODO clear"; + } + + /* + * + */ + @Get("/:entry:id") + getEntry(@Req() req: any, @Res() res: any) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify({ placeholder: "//TODO get" })); + } + + /* + * + */ + @Patch("/:entry_id") + editEntry(@Req() req: any, @Res() res: any) { + return "//TODO edit" + } + + @Delete("/:entry_id") + deleteEntry(@Req() req: any, @Res() res: any) { + return "//TODO delete" + } +} \ No newline at end of file diff --git a/backend/karaoqueue-backend/src/controllers/rpc.controller.ts b/backend/karaoqueue-backend/src/controllers/rpc.controller.ts new file mode 100644 index 0000000..e6d7ccb --- /dev/null +++ b/backend/karaoqueue-backend/src/controllers/rpc.controller.ts @@ -0,0 +1,39 @@ +import { Controller, Get, Param, QueryParam } from "routing-controllers"; + +@Controller("/rpc") +export class RpcController { + @Get("/start_event") + doStartEvent() { + return "//TODO start_event" + } + + @Get("/end_event") + doEndEvent() { + return "//TODO end_event" + } + + @Get("/enable_registration") + doEnableRegistration() { + return "//TODO enable_registration" + } + + @Get("/disable_registration") + doDisableRegistration() { + return "//TODO disable_registration" + } + + @Get("/get_playstats") + doGetPlaystats() { + return "//TODO get_playstats" + } + + @Get("/download_playstats") + doDownloadPlaystats() { + return "//TODO download_playstats" + } + + @Get("/entry_fulfilled") + doEntryFulfilled(@QueryParam("entry_id") entryId: string) { + return `//TODO entry_fulfilled. entry_id: ${entryId}` + } +} \ No newline at end of file diff --git a/backend/karaoqueue-backend/src/controllers/songs.controller.ts b/backend/karaoqueue-backend/src/controllers/songs.controller.ts new file mode 100644 index 0000000..470d92d --- /dev/null +++ b/backend/karaoqueue-backend/src/controllers/songs.controller.ts @@ -0,0 +1,14 @@ +import { Get, QueryParam, JsonController, Put } from "routing-controllers"; + +@JsonController("/songs") +export class SongController { + @Get() + searchSongs(@QueryParam("query") query: string, @QueryParam("limit") limit: number) { + return {result: "//TODO search"} + } + + @Put() + updateSongs() { + return "//TODO update" + } +} \ No newline at end of file diff --git a/backend/karaoqueue-backend/src/controllers/statistics.controller.ts b/backend/karaoqueue-backend/src/controllers/statistics.controller.ts new file mode 100644 index 0000000..7230d21 --- /dev/null +++ b/backend/karaoqueue-backend/src/controllers/statistics.controller.ts @@ -0,0 +1,9 @@ +import { JsonController, Get } from "routing-controllers"; + +@JsonController() +export class StatisticsController { + @Get() + getStatistics() { + return "//TODO statistics" + } +} \ No newline at end of file diff --git a/backend/karaoqueue-backend/src/index.ts b/backend/karaoqueue-backend/src/index.ts index bcd9553..d5b9c60 100644 --- a/backend/karaoqueue-backend/src/index.ts +++ b/backend/karaoqueue-backend/src/index.ts @@ -1,13 +1,15 @@ -import express = require("express"); +import "reflect-metadata"; +import { createExpressServer } from "routing-controllers"; +import { QueueController } from "./controllers/queue.controller"; +import { SongController } from "./controllers/songs.controller"; +import { StatisticsController } from "./controllers/statistics.controller"; +import { AuthenticationController } from "./controllers/auth.controller"; +import { RpcController } from "./controllers/rpc.controller"; -const app: express.Application = express(); - -app.get('/', (req, res) => { - res.send('Hello World!'); - // tslint:disable-next-line: no-console - console.log(req.headers["user-agent"]); +const app = createExpressServer({ + routePrefix: "/api", + cors: true, + controllers: [QueueController, SongController, StatisticsController, AuthenticationController, RpcController] }); -app.listen(3000, () => { - // tslint:disable-next-line: no-console - console.log('App is listening on port 3000!'); -}); \ No newline at end of file + +app.listen(3000); \ No newline at end of file diff --git a/backend/karaoqueue-backend/src/models/usercredential.model.ts b/backend/karaoqueue-backend/src/models/usercredential.model.ts new file mode 100644 index 0000000..5f67b6d --- /dev/null +++ b/backend/karaoqueue-backend/src/models/usercredential.model.ts @@ -0,0 +1,4 @@ +export interface UserCredential { + username: string, + password: string +} \ No newline at end of file