Skip to content

Commit

Permalink
Merge pull request #163 from tmddus2/feature/231129-save-audio-data
Browse files Browse the repository at this point in the history
Feature(#162, #29): ์Œ์„ฑ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„ DB์— ์ €์žฅ, ๋ฐ์ดํ„ฐ ์ €์žฅ ์‹œ ๊ฐ•์˜ ์ข…๋ฃŒ
  • Loading branch information
platinouss authored Nov 29, 2023
2 parents d9c264c + fbd6938 commit 3773077
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 127 deletions.
2 changes: 0 additions & 2 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import * as dotenv from 'dotenv';
import { ConfigModule } from '@nestjs/config';
import { RoomModule } from './room/room.module';
import { UserModule } from './user/user.module';
import { LectureModule } from './lecture/lecture.module';

Expand All @@ -18,7 +17,6 @@ dotenv.config();
isGlobal: true
}),
AuthModule,
RoomModule,
UserModule,
LectureModule
],
Expand Down
2 changes: 1 addition & 1 deletion backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from 'src/schema/user.schema';
import { User, UserSchema } from 'src/user/user.schema';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { GoogleStrategy } from './google.strategy';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { User } from 'src/schema/user.schema';
import { User } from 'src/user/user.schema';
import { UserInfoDto } from './dto/userInfo.dto';

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class CreateRoomDto {
email: string;
export class CreateLectureDto {
title: string;
description: string;
email: string;
}
3 changes: 3 additions & 0 deletions backend/src/lecture/dto/enter-lecture.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class EnterLectureDto {
email: string;
}
4 changes: 4 additions & 0 deletions backend/src/lecture/dto/update-lecture.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class UpdateLectureDto {
code: string;
audio: string;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import mongoose from 'mongoose';
import { Lecture } from '../lecture/lecture.schema';
import { Lecture } from './lecture.schema';

@Schema()
export class EnterCode {
Expand Down
39 changes: 39 additions & 0 deletions backend/src/lecture/lecture.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Body, Controller, HttpStatus, Param, Patch, Post, Res } from '@nestjs/common';
import { Response } from 'express';
import { UserService } from 'src/user/user.service';
import { CreateLectureDto } from './dto/create-lecture.dto';
import { EnterLectureDto } from './dto/enter-lecture.dto';
import { UpdateLectureDto } from './dto/update-lecture.dto';
import { LectureService } from './lecture.service';

@Controller('lecture')
export class LectureController {
constructor(
private readonly lectureService: LectureService,
private readonly userService: UserService
) {}

@Post()
async create(@Body() createLecture: CreateLectureDto, @Res() res: Response) {
const user = await this.userService.findOneByEmail(createLecture.email);
const code = await this.lectureService.createLecture(createLecture, user.id);
res.status(HttpStatus.CREATED).send({ code: code });
}

@Patch('end')
async end(@Body() updateLectureDto: UpdateLectureDto, @Res() res: Response) {
await this.lectureService.endLecture(updateLectureDto);
res.status(HttpStatus.OK).send();
}

@Patch('/:code')
async enter(@Param('code') code: string, @Body() enterLectureDto: EnterLectureDto, @Res() res: Response) {
const enterCodeDocument = await this.lectureService.findLectureByCode(code);
if (!enterCodeDocument) {
res.status(HttpStatus.NOT_FOUND).send();
return;
}
const result = await this.userService.updateLecture(enterLectureDto.email, enterCodeDocument.lecture_id);
res.status(HttpStatus.OK).send(result);
}
}
15 changes: 14 additions & 1 deletion backend/src/lecture/lecture.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from 'src/user/user.schema';
import { UserService } from 'src/user/user.service';
import { EnterCode, EnterCodeSchema } from './lecture-code.schema';
import { LectureController } from './lecture.controller';
import { Lecture, LectureSchema } from './lecture.schema';
import { LectureService } from './lecture.service';

@Module({
imports: [MongooseModule.forFeature([{ name: Lecture.name, schema: LectureSchema }])]
imports: [
MongooseModule.forFeature([
{ name: Lecture.name, schema: LectureSchema },
{ name: EnterCode.name, schema: EnterCodeSchema },
{ name: User.name, schema: UserSchema }
])
],
controllers: [LectureController],
providers: [LectureService, UserService]
})
export class LectureModule {}
8 changes: 7 additions & 1 deletion backend/src/lecture/lecture.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import mongoose from 'mongoose';
import { User } from '../schema/user.schema';
import { User } from 'src/user/user.schema';

@Schema()
export class Lecture {
Expand All @@ -15,6 +15,12 @@ export class Lecture {

@Prop({ default: false })
is_end: boolean;

@Prop()
audio_file: string;

@Prop()
start_time: Date;
}

export const LectureSchema = SchemaFactory.createForClass(Lecture);
54 changes: 54 additions & 0 deletions backend/src/lecture/lecture.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { GenerateUtils } from 'src/utils/GenerateUtils';
import { CreateLectureDto } from './dto/create-lecture.dto';
import { UpdateLectureDto } from './dto/update-lecture.dto';
import { EnterCode } from './lecture-code.schema';
import { Lecture } from './lecture.schema';

@Injectable()
export class LectureService {
constructor(
@InjectModel(Lecture.name)
private lectureModel: Model<Lecture>,
@InjectModel(EnterCode.name)
private enterCodeModel: Model<EnterCode>
) {}

async createLecture(createLectureDto: CreateLectureDto, userId: string) {
const lecture = new this.lectureModel({
title: createLectureDto.title,
description: createLectureDto.description,
presenter_id: userId
});
const lectureCode = new this.enterCodeModel({
code: await this.generateRoomCode(),
lecture_id: lecture.id
});

await Promise.all([lecture.save(), lectureCode.save()]);

return lectureCode.code;
}

async endLecture(updateLectureDto: UpdateLectureDto) {
const lecture = await this.findLectureByCode(updateLectureDto.code);
return await this.lectureModel
.findByIdAndUpdate(lecture.lecture_id, { $set: { is_end: true, audio_file: updateLectureDto.audio } })
.exec();
}

async generateRoomCode() {
const generateUtils = new GenerateUtils();
let lectureCode = generateUtils.generateRandomNumber();
while (await this.findLectureByCode(lectureCode)) {
lectureCode = generateUtils.generateRandomNumber();
}
return lectureCode;
}

async findLectureByCode(code: string) {
return await this.enterCodeModel.findOne({ code: code });
}
}
3 changes: 0 additions & 3 deletions backend/src/room/dto/enter-room.dto.ts

This file was deleted.

31 changes: 0 additions & 31 deletions backend/src/room/room.controller.ts

This file was deleted.

21 changes: 0 additions & 21 deletions backend/src/room/room.module.ts

This file was deleted.

18 changes: 0 additions & 18 deletions backend/src/room/room.schema.ts

This file was deleted.

43 changes: 0 additions & 43 deletions backend/src/room/room.service.ts

This file was deleted.

2 changes: 1 addition & 1 deletion backend/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from '../schema/user.schema';
import { User, UserSchema } from './user.schema';
import { UserController } from './user.controller';
import { UserService } from './user.service';

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { User, UserDocument } from '../schema/user.schema';
import { User, UserDocument } from './user.schema';
import { Model } from 'mongoose';

@Injectable()
Expand Down

0 comments on commit 3773077

Please sign in to comment.