diff --git a/.gitea/workflows/deploy-backend.yml b/.gitea/workflows/deploy-backend.yml index 8b6a85f..3192f51 100644 --- a/.gitea/workflows/deploy-backend.yml +++ b/.gitea/workflows/deploy-backend.yml @@ -39,7 +39,6 @@ jobs: git.fascinated.cc/fascinated/scoresaber-reloaded-backend:latest build-args: | GIT_REV=${{ gitea.sha }} - SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} - name: Install kubectl uses: azure/setup-kubectl@v4 diff --git a/backend/Dockerfile b/backend/Dockerfile index 039deb8..fb4d736 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -6,6 +6,9 @@ ENV PNPM_HOME=/usr/local/bin WORKDIR /app +ARG GIT_REV +ENV GIT_REV=${GIT_REV} + # Copy necessary files for installation COPY package.json* pnpm-lock.yaml* pnpm-workspace.yaml* ./ COPY common ./common diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index d6a9ad2..3bccff4 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -1,10 +1,12 @@ import { Module } from "@nestjs/common"; import { AppController } from "./controller/app.controller"; +import { PlayerService } from "./service/player.service"; +import { PlayerController } from "./controller/player.controller"; import { AppService } from "./service/app.service"; @Module({ imports: [], - controllers: [AppController], - providers: [AppService], + controllers: [AppController, PlayerController], + providers: [AppService, PlayerService], }) export class AppModule {} diff --git a/backend/src/controller/app.controller.ts b/backend/src/controller/app.controller.ts index 6b01dc2..fb55049 100644 --- a/backend/src/controller/app.controller.ts +++ b/backend/src/controller/app.controller.ts @@ -6,7 +6,10 @@ export class AppController { constructor(private readonly appService: AppService) {} @Get("/") - getHello(): string { - return this.appService.getHello(); + getHome() { + return { + message: "ScoreSaber Reloaded API", + version: this.appService.getVersion(), + }; } } diff --git a/backend/src/controller/player.controller.ts b/backend/src/controller/player.controller.ts new file mode 100644 index 0000000..e3e3c19 --- /dev/null +++ b/backend/src/controller/player.controller.ts @@ -0,0 +1,12 @@ +import { Controller, Get, Param } from "@nestjs/common"; +import { PlayerService } from "../service/player.service"; + +@Controller("/player") +export class PlayerController { + constructor(private readonly playerService: PlayerService) {} + + @Get("/history/:id") + getHistory(@Param("id") id: string) { + return this.playerService.getHistory(id); + } +} diff --git a/backend/src/service/app.service.ts b/backend/src/service/app.service.ts index 0c0dedf..d38fc20 100644 --- a/backend/src/service/app.service.ts +++ b/backend/src/service/app.service.ts @@ -1,9 +1,14 @@ import { Injectable } from "@nestjs/common"; -import { helloMeowMeow } from "@ssr/common/dist"; +import { isProduction } from "@ssr/common/dist"; @Injectable() export class AppService { - getHello(): string { - return helloMeowMeow(); + /** + * Gets the app version. + * + * @returns the app version + */ + getVersion(): string { + return `1.0.0-${isProduction() ? process.env.GIT_REV.substring(0, 7) : "dev"}`; } } diff --git a/backend/src/service/player.service.ts b/backend/src/service/player.service.ts new file mode 100644 index 0000000..a1190f1 --- /dev/null +++ b/backend/src/service/player.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from "@nestjs/common"; + +@Injectable() +export class PlayerService { + /** + * Gets the statistic history for the given player + * + * @param id the id of the player + * @returns the players statistic history + */ + getHistory(id: string) { + return { + id: id, + }; + } +} diff --git a/common/package.json b/common/package.json index 7d7e083..0971a14 100644 --- a/common/package.json +++ b/common/package.json @@ -6,6 +6,7 @@ "build": "tsup src/index.ts" }, "devDependencies": { + "@types/node": "^22.7.4", "tsup": "^6.5.0", "typescript": "^5" } diff --git a/common/src/index.ts b/common/src/index.ts index df43c28..88e0468 100644 --- a/common/src/index.ts +++ b/common/src/index.ts @@ -1,3 +1 @@ -export function helloMeowMeow() { - return "hi"; -} +export * from "src/utils"; diff --git a/common/src/utils.ts b/common/src/utils.ts new file mode 100644 index 0000000..7179875 --- /dev/null +++ b/common/src/utils.ts @@ -0,0 +1,6 @@ +/** + * Checks if we're in production + */ +export function isProduction() { + return process.env.NODE_ENV === "production"; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be2b992..71ef1b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -98,9 +98,12 @@ importers: common: devDependencies: + '@types/node': + specifier: ^22.7.4 + version: 22.7.4 tsup: specifier: ^6.5.0 - version: 6.7.0(postcss@8.4.47)(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.6.2))(typescript@5.6.2) + version: 6.7.0(postcss@8.4.47)(ts-node@10.9.2(@types/node@22.7.4)(typescript@5.6.2))(typescript@5.6.2) typescript: specifier: ^5 version: 5.6.2 @@ -2017,6 +2020,9 @@ packages: '@types/node@20.16.10': resolution: {integrity: sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==} + '@types/node@22.7.4': + resolution: {integrity: sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==} + '@types/pg-pool@2.0.6': resolution: {integrity: sha512-TaAUE5rq2VQYxab5Ts7WZhKNmuN78Q6PiFonTDdpbx8a1H0M1vhy3rhiMjl+e2iHmogyMw7jZF4FrE6eJUy5HQ==} @@ -7040,6 +7046,10 @@ snapshots: dependencies: undici-types: 6.19.8 + '@types/node@22.7.4': + dependencies: + undici-types: 6.19.8 + '@types/pg-pool@2.0.6': dependencies: '@types/pg': 8.6.1 @@ -9505,13 +9515,13 @@ snapshots: camelcase-css: 2.0.1 postcss: 8.4.47 - postcss-load-config@3.1.4(postcss@8.4.47)(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.6.2)): + postcss-load-config@3.1.4(postcss@8.4.47)(ts-node@10.9.2(@types/node@22.7.4)(typescript@5.6.2)): dependencies: lilconfig: 2.1.0 yaml: 1.10.2 optionalDependencies: postcss: 8.4.47 - ts-node: 10.9.2(@types/node@20.16.10)(typescript@5.6.2) + ts-node: 10.9.2(@types/node@22.7.4)(typescript@5.6.2) postcss-load-config@4.0.2(postcss@8.4.47)(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.6.2)): dependencies: @@ -10309,6 +10319,25 @@ snapshots: v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + ts-node@10.9.2(@types/node@22.7.4)(typescript@5.6.2): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.11 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 22.7.4 + acorn: 8.12.1 + acorn-walk: 8.3.4 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.6.2 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + optional: true + tsafe@1.7.5: {} tsconfig-paths-webpack-plugin@4.1.0: @@ -10332,7 +10361,7 @@ snapshots: tslib@2.7.0: {} - tsup@6.7.0(postcss@8.4.47)(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.6.2))(typescript@5.6.2): + tsup@6.7.0(postcss@8.4.47)(ts-node@10.9.2(@types/node@22.7.4)(typescript@5.6.2))(typescript@5.6.2): dependencies: bundle-require: 4.2.1(esbuild@0.17.19) cac: 6.7.14 @@ -10342,7 +10371,7 @@ snapshots: execa: 5.1.1 globby: 11.1.0 joycon: 3.1.1 - postcss-load-config: 3.1.4(postcss@8.4.47)(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.6.2)) + postcss-load-config: 3.1.4(postcss@8.4.47)(ts-node@10.9.2(@types/node@22.7.4)(typescript@5.6.2)) resolve-from: 5.0.0 rollup: 3.29.5 source-map: 0.8.0-beta.0