diff --git a/backend/.yarn/install-state.gz b/backend/.yarn/install-state.gz index a13a9b2..f2f637e 100644 Binary files a/backend/.yarn/install-state.gz and b/backend/.yarn/install-state.gz differ diff --git a/backend/package.json b/backend/package.json index 5329668..0ca217d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -22,6 +22,7 @@ "dependencies": { "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", + "@nestjs/mapped-types": "*", "@nestjs/platform-express": "^10.0.0", "cross-env": "^7.0.3", "reflect-metadata": "^0.1.13", diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 853636e..c70d0a4 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -4,6 +4,7 @@ import { ConfigModule } from '@nestjs/config'; import { ItemModule } from './item/item.module'; import { TypeOrmModule } from '@nestjs/typeorm'; import { typeORMConfig } from 'src/configs/typeorm.config'; +import { GameModule } from './game/game.module'; @Module({ imports: [ @@ -16,6 +17,7 @@ import { typeORMConfig } from 'src/configs/typeorm.config'; }), AuthModule, ItemModule, + GameModule, ], controllers: [], providers: [], diff --git a/backend/src/auth/auth.controller.ts b/backend/src/auth/auth.controller.ts index 268eeb2..f66d050 100644 --- a/backend/src/auth/auth.controller.ts +++ b/backend/src/auth/auth.controller.ts @@ -1,4 +1,23 @@ -import { Controller } from '@nestjs/common'; +import { User } from 'src/auth/user.entity'; +import { AuthService } from './auth.service'; +import { Body, Controller, Get, Logger, Post } from '@nestjs/common'; +import { CreateUserDto } from 'src/auth/dto/create-user.dto'; @Controller('auth') -export class AuthController {} +export class AuthController { + private logger = new Logger('AuthController'); + + constructor(private readonly authService: AuthService) {} + + @Get() + findOne(): Promise { + this.logger.log('Handling Find One Users request'); + return this.authService.findOne(2); + } + + @Post('/test') + async test(@Body() createUserDto: CreateUserDto): Promise { + this.logger.log('Handling create user'); + return this.authService.createUser(createUserDto); + } +} diff --git a/backend/src/auth/auth.module.ts b/backend/src/auth/auth.module.ts index a7d9fbc..ee3ef16 100644 --- a/backend/src/auth/auth.module.ts +++ b/backend/src/auth/auth.module.ts @@ -1,8 +1,11 @@ import { Module } from '@nestjs/common'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { User } from 'src/auth/user.entity'; @Module({ + imports: [TypeOrmModule.forFeature([User])], controllers: [AuthController], providers: [AuthService], }) diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index a41c649..f0fb737 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -1,4 +1,27 @@ import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { CreateUserDto } from 'src/auth/dto/create-user.dto'; +import { User } from 'src/auth/user.entity'; +import { Repository } from 'typeorm'; @Injectable() -export class AuthService {} +export class AuthService { + constructor( + @InjectRepository(User) + private usersRepository: Repository, + ) {} + + findOne(userId: number): Promise { + return this.usersRepository.findOneBy({ userId }); + } + + async createUser(createUserDto: CreateUserDto): Promise { + // Create a new User entity from the DTO + const user = new User(); + user.username = createUserDto.username; + user.userId = createUserDto.userId; + + // Save the entity to the database + return this.usersRepository.save(user); + } +} diff --git a/backend/src/auth/dto/create-user.dto.ts b/backend/src/auth/dto/create-user.dto.ts new file mode 100644 index 0000000..00625eb --- /dev/null +++ b/backend/src/auth/dto/create-user.dto.ts @@ -0,0 +1,9 @@ +import { IsNotEmpty } from 'class-validator'; + +export class CreateUserDto { + @IsNotEmpty() + userId: number; + + @IsNotEmpty() + username: string; +} diff --git a/backend/src/auth/user.entity.ts b/backend/src/auth/user.entity.ts index e69de29..d73d5e6 100644 --- a/backend/src/auth/user.entity.ts +++ b/backend/src/auth/user.entity.ts @@ -0,0 +1,10 @@ +import { BaseEntity, Column, Entity, PrimaryColumn } from 'typeorm'; + +@Entity() +export class User extends BaseEntity { + @PrimaryColumn({ unique: true }) + userId: number; + + @Column() + username: string; +} diff --git a/backend/src/game/game.controller.ts b/backend/src/game/game.controller.ts new file mode 100644 index 0000000..b3a3953 --- /dev/null +++ b/backend/src/game/game.controller.ts @@ -0,0 +1,7 @@ +import { Controller } from '@nestjs/common'; +import { GameService } from './game.service'; + +@Controller('game') +export class GameController { + constructor(private readonly gameService: GameService) {} +} diff --git a/backend/src/game/game.module.ts b/backend/src/game/game.module.ts new file mode 100644 index 0000000..d375e00 --- /dev/null +++ b/backend/src/game/game.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { GameService } from './game.service'; +import { GameController } from './game.controller'; + +@Module({ + controllers: [GameController], + providers: [GameService], +}) +export class GameModule {} diff --git a/backend/src/game/game.service.ts b/backend/src/game/game.service.ts new file mode 100644 index 0000000..18ca270 --- /dev/null +++ b/backend/src/game/game.service.ts @@ -0,0 +1,4 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class GameService {} diff --git a/backend/src/item/item.entity.ts b/backend/src/item/item.entity.ts new file mode 100644 index 0000000..e69de29 diff --git a/backend/yarn.lock b/backend/yarn.lock index 10f07fc..73d6b54 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -979,6 +979,23 @@ __metadata: languageName: node linkType: hard +"@nestjs/mapped-types@npm:*": + version: 2.0.5 + resolution: "@nestjs/mapped-types@npm:2.0.5" + peerDependencies: + "@nestjs/common": ^8.0.0 || ^9.0.0 || ^10.0.0 + class-transformer: ^0.4.0 || ^0.5.0 + class-validator: ^0.13.0 || ^0.14.0 + reflect-metadata: ^0.1.12 || ^0.2.0 + peerDependenciesMeta: + class-transformer: + optional: true + class-validator: + optional: true + checksum: 10c0/f92743cb4c0fe3b1eecdf0c7c6a40f0e7478574a9e1a25ebdbd29db29a7319c2ae608c08d07f7b9525bea01a5e20dbd73222100204d3a13500db4f56676446a1 + languageName: node + linkType: hard + "@nestjs/platform-express@npm:^10.0.0": version: 10.4.1 resolution: "@nestjs/platform-express@npm:10.4.1" @@ -2139,6 +2156,7 @@ __metadata: "@nestjs/common": "npm:^10.0.0" "@nestjs/config": "npm:^3.2.3" "@nestjs/core": "npm:^10.0.0" + "@nestjs/mapped-types": "npm:*" "@nestjs/platform-express": "npm:^10.0.0" "@nestjs/schematics": "npm:^10.0.0" "@nestjs/testing": "npm:^10.0.0"