-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<User> { | ||
this.logger.log('Handling Find One Users request'); | ||
return this.authService.findOne(2); | ||
} | ||
|
||
@Post('/test') | ||
async test(@Body() createUserDto: CreateUserDto): Promise<User> { | ||
this.logger.log('Handling create user'); | ||
return this.authService.createUser(createUserDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<User>, | ||
) {} | ||
|
||
findOne(userId: number): Promise<User> { | ||
return this.usersRepository.findOneBy({ userId }); | ||
} | ||
|
||
async createUser(createUserDto: CreateUserDto): Promise<User> { | ||
// 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export class CreateUserDto { | ||
@IsNotEmpty() | ||
userId: number; | ||
|
||
@IsNotEmpty() | ||
username: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { GameService } from './game.service'; | ||
|
||
@Controller('game') | ||
export class GameController { | ||
constructor(private readonly gameService: GameService) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class GameService {} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters