Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GWL-116] 조금 더 구조적이고, 탄탄한 WebSocket 재 구축 #126

Merged
merged 9 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BackEnd/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, Res } from '@nestjs/common';
import { Response } from 'express';
import { join } from 'path';
import {ApiProperty, ApiTags} from "@nestjs/swagger";
import { ApiProperty, ApiTags } from '@nestjs/swagger';

@ApiTags('메인 페이지')
@Controller()
Expand Down
6 changes: 4 additions & 2 deletions BackEnd/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import { LoggerMiddleware } from './middlewares/logger.middleware';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
import { ProfilesModule } from './profiles/profiles.module';
import { LiveModule } from './lives/lives.module';
import { RecordsModule } from './records/records.module';
import { WorkoutsModule } from './workouts/workouts.module';
import { EventsModule } from './live-workouts/events/events.module';
import { MatchesModule } from './live-workouts/matches/matches.module';

@Module({
imports: [
TypeOrmModule.forRoot(typeOrmConfig),
AuthModule,
UsersModule,
ProfilesModule,
LiveModule,
RecordsModule,
WorkoutsModule,
MatchesModule,
EventsModule,
],
controllers: [AppController],
})
Expand Down
1 change: 1 addition & 0 deletions BackEnd/src/live-workouts/events/dto/create-event.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateEventDto {}
6 changes: 6 additions & 0 deletions BackEnd/src/live-workouts/events/dto/update-event.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateEventDto } from './create-event.dto';

export class UpdateEventDto extends PartialType(CreateEventDto) {
id: number;
}
1 change: 1 addition & 0 deletions BackEnd/src/live-workouts/events/entities/event.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Event {}
19 changes: 19 additions & 0 deletions BackEnd/src/live-workouts/events/events.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Test, TestingModule } from '@nestjs/testing';
import { EventsGateway } from './events.gateway';
import { EventsService } from './events.service';

describe('EventsGateway', () => {
let gateway: EventsGateway;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [EventsGateway, EventsService],
}).compile();

gateway = module.get<EventsGateway>(EventsGateway);
});

it('should be defined', () => {
expect(gateway).toBeDefined();
});
});
61 changes: 61 additions & 0 deletions BackEnd/src/live-workouts/events/events.gateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
WebSocketGateway,
SubscribeMessage,
MessageBody,
WebSocketServer,
OnGatewayConnection,
OnGatewayDisconnect,
} from '@nestjs/websockets';
import { Server, WebSocket } from 'ws';
import { EventsService } from './events.service';
import { CreateEventDto } from './dto/create-event.dto';
import { UpdateEventDto } from './dto/update-event.dto';

@WebSocketGateway(3003)
export class EventsGateway {
@WebSocketServer() server: Server;
constructor(private readonly eventsService: EventsService) {}

@SubscribeMessage('events')
onEvent(client: WebSocket, data: any): void {
console.log(`전송받은 데이터: ${data}`);
this.server.clients.forEach((others: WebSocket) => {
if (others.readyState === WebSocket.OPEN) {
others.send(data);
}
});
}

handleConnection(client: WebSocket): void {
console.log(`클라이언트 연결`);
}

handleDisconnect(client: WebSocket): void {
console.log(`클라이언트 연결 종료`);
}

@SubscribeMessage('createEvent')
create(@MessageBody() createEventDto: CreateEventDto) {
return this.eventsService.create(createEventDto);
}

@SubscribeMessage('findAllEvents')
findAll() {
return this.eventsService.findAll();
}

@SubscribeMessage('findOneEvent')
findOne(@MessageBody() id: number) {
return this.eventsService.findOne(id);
}

@SubscribeMessage('updateEvent')
update(@MessageBody() updateEventDto: UpdateEventDto) {
return this.eventsService.update(updateEventDto.id, updateEventDto);
}

@SubscribeMessage('removeEvent')
remove(@MessageBody() id: number) {
return this.eventsService.remove(id);
}
}
8 changes: 8 additions & 0 deletions BackEnd/src/live-workouts/events/events.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { EventsService } from './events.service';
import { EventsGateway } from './events.gateway';

@Module({
providers: [EventsGateway, EventsService],
})
export class EventsModule {}
18 changes: 18 additions & 0 deletions BackEnd/src/live-workouts/events/events.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { EventsService } from './events.service';

describe('EventsService', () => {
let service: EventsService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [EventsService],
}).compile();

service = module.get<EventsService>(EventsService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
26 changes: 26 additions & 0 deletions BackEnd/src/live-workouts/events/events.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateEventDto } from './dto/create-event.dto';
import { UpdateEventDto } from './dto/update-event.dto';

@Injectable()
export class EventsService {
create(createEventDto: CreateEventDto) {
return 'This action adds a new event';
}

findAll() {
return `This action returns all events`;
}

findOne(id: number) {
return `This action returns a #${id} event`;
}

update(id: number, updateEventDto: UpdateEventDto) {
return `This action updates a #${id} event`;
}

remove(id: number) {
return `This action removes a #${id} event`;
}
}
1 change: 1 addition & 0 deletions BackEnd/src/live-workouts/matches/dto/create-match.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateMatchDto {}
4 changes: 4 additions & 0 deletions BackEnd/src/live-workouts/matches/dto/update-match.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateMatchDto } from './create-match.dto';

export class UpdateMatchDto extends PartialType(CreateMatchDto) {}
1 change: 1 addition & 0 deletions BackEnd/src/live-workouts/matches/entities/match.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Match {}
20 changes: 20 additions & 0 deletions BackEnd/src/live-workouts/matches/matches.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { MatchesController } from './matches.controller';
import { MatchesService } from './matches.service';

describe('MatchesController', () => {
let controller: MatchesController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [MatchesController],
providers: [MatchesService],
}).compile();

controller = module.get<MatchesController>(MatchesController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
42 changes: 42 additions & 0 deletions BackEnd/src/live-workouts/matches/matches.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
} from '@nestjs/common';
import { MatchesService } from './matches.service';
import { CreateMatchDto } from './dto/create-match.dto';
import { UpdateMatchDto } from './dto/update-match.dto';

@Controller('matches')
export class MatchesController {
constructor(private readonly matchesService: MatchesService) {}

@Post()
create(@Body() createMatchDto: CreateMatchDto) {
return this.matchesService.create(createMatchDto);
}

@Get()
findAll() {
return this.matchesService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.matchesService.findOne(+id);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateMatchDto: UpdateMatchDto) {
return this.matchesService.update(+id, updateMatchDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.matchesService.remove(+id);
}
}
9 changes: 9 additions & 0 deletions BackEnd/src/live-workouts/matches/matches.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { MatchesService } from './matches.service';
import { MatchesController } from './matches.controller';

@Module({
controllers: [MatchesController],
providers: [MatchesService],
})
export class MatchesModule {}
18 changes: 18 additions & 0 deletions BackEnd/src/live-workouts/matches/matches.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { MatchesService } from './matches.service';

describe('MatchesService', () => {
let service: MatchesService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MatchesService],
}).compile();

service = module.get<MatchesService>(MatchesService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
26 changes: 26 additions & 0 deletions BackEnd/src/live-workouts/matches/matches.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateMatchDto } from './dto/create-match.dto';
import { UpdateMatchDto } from './dto/update-match.dto';

@Injectable()
export class MatchesService {
create(createMatchDto: CreateMatchDto) {
return 'This action adds a new match';
}

findAll() {
return `This action returns all matches`;
}

findOne(id: number) {
return `This action returns a #${id} match`;
}

update(id: number, updateMatchDto: UpdateMatchDto) {
return `This action updates a #${id} match`;
}

remove(id: number) {
return `This action removes a #${id} match`;
}
}
31 changes: 0 additions & 31 deletions BackEnd/src/lives/lives.gateway.ts

This file was deleted.

7 changes: 0 additions & 7 deletions BackEnd/src/lives/lives.module.ts

This file was deleted.

7 changes: 4 additions & 3 deletions BackEnd/src/records/entities/records.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {
Column,
CreateDateColumn,
ManyToOne,
OneToOne, JoinColumn,
OneToOne,
JoinColumn,
} from 'typeorm';
import { Post } from '../../posts/entities/posts.entity';
import { Profile } from '../../profiles/entities/profiles.entity';
import { IsNumber, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import {Workout} from "../../workouts/entities/workout.entity";
import { Workout } from '../../workouts/entities/workout.entity';

@Entity()
export class Record {
Expand Down Expand Up @@ -83,6 +84,6 @@ export class Record {

@ApiProperty({ example: '달리기', description: '선택한 운동 종료' })
@ManyToOne(() => Workout, (workout) => workout.records)
@JoinColumn({ name: "id" })
@JoinColumn({ name: 'id' })
workout: Workout;
}
Loading
Loading