Skip to content

Commit

Permalink
feat: user 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellol77 committed Sep 11, 2024
1 parent 1bc5b05 commit 5f4c768
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 3 deletions.
Binary file modified backend/.yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -16,6 +17,7 @@ import { typeORMConfig } from 'src/configs/typeorm.config';
}),
AuthModule,
ItemModule,
GameModule,
],
controllers: [],
providers: [],
Expand Down
23 changes: 21 additions & 2 deletions backend/src/auth/auth.controller.ts
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);
}
}
3 changes: 3 additions & 0 deletions backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -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],
})
Expand Down
25 changes: 24 additions & 1 deletion backend/src/auth/auth.service.ts
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);
}
}
9 changes: 9 additions & 0 deletions backend/src/auth/dto/create-user.dto.ts
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;
}
10 changes: 10 additions & 0 deletions backend/src/auth/user.entity.ts
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;
}
7 changes: 7 additions & 0 deletions backend/src/game/game.controller.ts
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) {}
}
9 changes: 9 additions & 0 deletions backend/src/game/game.module.ts
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 {}
4 changes: 4 additions & 0 deletions backend/src/game/game.service.ts
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 added backend/src/item/item.entity.ts
Empty file.
18 changes: 18 additions & 0 deletions backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 5f4c768

Please sign in to comment.