From 8d6f26ecd681dcb208da03303f6ed31b2969656f Mon Sep 17 00:00:00 2001 From: hysimok Date: Sun, 5 Sep 2021 21:04:09 +0900 Subject: [PATCH] FEAT: #23 add channel module & channel entity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit channel module을 생성하였습니다. 채팅방 생성을 위한 channel entity 를 만들고 relation을 설정하였습니다. --- backend/src/app.module.ts | 2 + backend/src/channel/channel.controller.ts | 4 ++ backend/src/channel/channel.module.ts | 9 +++++ backend/src/channel/channel.service.ts | 4 ++ backend/src/channel/entity/channel.entity.ts | 41 ++++++++++++++++++++ backend/src/user/entity/user.entity.ts | 6 ++- 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 backend/src/channel/channel.controller.ts create mode 100644 backend/src/channel/channel.module.ts create mode 100644 backend/src/channel/channel.service.ts create mode 100644 backend/src/channel/entity/channel.entity.ts diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index b1ce6ef..05a1c1c 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -7,6 +7,7 @@ import { AppService } from './app.service'; import { AuthModule } from './auth/auth.module'; import { JwtMiddleware } from './auth/middleware/jwt.middleware'; import { UserModule } from './user/user.module'; +import { ChannelModule } from './channel/channel.module'; @Module({ imports: [ @@ -30,6 +31,7 @@ import { UserModule } from './user/user.module'; }), }), UserModule, + ChannelModule, ], controllers: [AppController], providers: [AppService], diff --git a/backend/src/channel/channel.controller.ts b/backend/src/channel/channel.controller.ts new file mode 100644 index 0000000..fff4d42 --- /dev/null +++ b/backend/src/channel/channel.controller.ts @@ -0,0 +1,4 @@ +import { Controller } from '@nestjs/common'; + +@Controller('channel') +export class ChannelController {} diff --git a/backend/src/channel/channel.module.ts b/backend/src/channel/channel.module.ts new file mode 100644 index 0000000..fe632c1 --- /dev/null +++ b/backend/src/channel/channel.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { ChannelController } from './channel.controller'; +import { ChannelService } from './channel.service'; + +@Module({ + controllers: [ChannelController], + providers: [ChannelService] +}) +export class ChannelModule {} diff --git a/backend/src/channel/channel.service.ts b/backend/src/channel/channel.service.ts new file mode 100644 index 0000000..fc8cd3a --- /dev/null +++ b/backend/src/channel/channel.service.ts @@ -0,0 +1,4 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class ChannelService {} diff --git a/backend/src/channel/entity/channel.entity.ts b/backend/src/channel/entity/channel.entity.ts new file mode 100644 index 0000000..49e2e22 --- /dev/null +++ b/backend/src/channel/entity/channel.entity.ts @@ -0,0 +1,41 @@ +import { + Column, + Entity, + JoinColumn, + ManyToOne, + OneToMany, + PrimaryGeneratedColumn, +} from 'typeorm'; +import { User } from '../../user/entity/user.entity'; + +@Entity('channel') +export class Channel { + @PrimaryGeneratedColumn() + id: number; + + @Column({ nullable: false }) + channelStatus: number; + + @Column() + channelPassword: number; + + @OneToMany(() => ChannelMembers, (channelMembers) => channelMembers.channelID) + channelIDs: ChannelMembers[]; +} + +@Entity('channel_members') +export class ChannelMembers { + @ManyToOne(() => Channel, (channel) => channel.channelIDs, { primary: true }) + @JoinColumn({ name: 'channelID' }) + channelID: Channel; + + @ManyToOne(() => User, (user) => user.userIDs, { primary: true }) + @JoinColumn({ name: 'userID' }) + userID: User; + + @Column() + permissionType: number; + + @Column() + penalty: number; +} diff --git a/backend/src/user/entity/user.entity.ts b/backend/src/user/entity/user.entity.ts index 99f540c..cf5e8e9 100644 --- a/backend/src/user/entity/user.entity.ts +++ b/backend/src/user/entity/user.entity.ts @@ -1,4 +1,5 @@ -import { Column, Entity, PrimaryColumn } from 'typeorm'; +import { ChannelMembers } from 'src/channel/entity/channel.entity'; +import { Column, Entity, OneToMany, PrimaryColumn } from 'typeorm'; @Entity('user') export class User { @@ -25,4 +26,7 @@ export class User { @Column({ default: 0 }) ladderLevel: number; + + @OneToMany(() => ChannelMembers, (channelMembers) => channelMembers.userID) + userIDs: ChannelMembers[]; }