-
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.
Merge pull request #163 from tmddus2/feature/231129-save-audio-data
- Loading branch information
Showing
19 changed files
with
128 additions
and
127 deletions.
There are no files selected for viewing
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
4 changes: 2 additions & 2 deletions
4
backend/src/room/dto/create-room.dto.ts โ ...end/src/lecture/dto/create-lecture.dto.ts
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,5 +1,5 @@ | ||
export class CreateRoomDto { | ||
email: string; | ||
export class CreateLectureDto { | ||
title: string; | ||
description: string; | ||
email: 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,3 @@ | ||
export class EnterLectureDto { | ||
email: 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,4 @@ | ||
export class UpdateLectureDto { | ||
code: string; | ||
audio: string; | ||
} |
2 changes: 1 addition & 1 deletion
2
backend/src/room/room-code.schema.ts โ backend/src/lecture/lecture-code.schema.ts
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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,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 {} |
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 |
---|---|---|
@@ -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 }); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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