Skip to content

Commit 96d80ab

Browse files
committed
Merge commit 'a89c7805ac8627bd3cbc0058835c759feb5b5d9f' into feature/231211-audio-replay
2 parents a078bc0 + a89c780 commit 96d80ab

File tree

9 files changed

+57
-32
lines changed

9 files changed

+57
-32
lines changed
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, Res, UseGuards } from '@nestjs/common';
2-
import { ApiBody, ApiHeader, ApiResponse, ApiTags } from '@nestjs/swagger';
1+
import { Body, Controller, HttpException, HttpStatus, Post, Res } from '@nestjs/common';
2+
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
33
import { Response } from 'express';
4-
import { CustomAuthGuard } from './auth.guard';
54
import { AuthService } from './auth.service';
65
import { ResponseSignInDto } from './dto/response-signin.dto';
76
import { SignInDto } from './dto/sign-in.dto';
@@ -13,6 +12,7 @@ export class AuthController {
1312
constructor(private authService: AuthService) {}
1413

1514
@Post('/signup')
15+
@ApiOperation({ summary: 'ํšŒ์›๊ฐ€์ž… API' })
1616
@ApiBody({ type: SignUpDto })
1717
@ApiResponse({ status: 201 })
1818
@ApiResponse({ status: 409, description: '์ด๋ฏธ ๊ฐ€์ž…๋˜์–ด ์žˆ๋Š” ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.' })
@@ -25,6 +25,7 @@ export class AuthController {
2525
}
2626

2727
@Post('/signin')
28+
@ApiOperation({ summary: '๋กœ๊ทธ์ธ API' })
2829
@ApiBody({ type: SignInDto })
2930
@ApiResponse({ status: 200, type: ResponseSignInDto })
3031
@ApiResponse({ status: 404, description: 'ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.' })
@@ -34,13 +35,6 @@ export class AuthController {
3435
throw new HttpException('ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.', HttpStatus.NOT_FOUND);
3536
}
3637
const result = await this.authService.signIn(signInDto);
37-
return res.status(HttpStatus.OK).send(new ResponseSignInDto(result));
38-
}
39-
40-
@ApiHeader({ name: 'Authorization' })
41-
@UseGuards(CustomAuthGuard)
42-
@Get('profile')
43-
getProfile(@Req() req: any) {
44-
return req.user;
38+
return res.status(HttpStatus.OK).send(result);
4539
}
4640
}

โ€Žbackend/src/auth/auth.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ConfigService } from '@nestjs/config';
77
import { decryptPassword, encryptPassword } from 'src/utils/GenerateUtils';
88
import { SignUpDto } from './dto/sign-up.dto';
99
import { SignInDto } from './dto/sign-in.dto';
10+
import { ResponseSignInDto } from './dto/response-signin.dto';
1011

1112
@Injectable()
1213
export class AuthService {
@@ -22,7 +23,7 @@ export class AuthService {
2223
return { username: user.username, email: user.email };
2324
}
2425

25-
async signIn(signInDto: SignInDto): Promise<string> {
26+
async signIn(signInDto: SignInDto): Promise<ResponseSignInDto> {
2627
const user = await this.findUserByEmail(signInDto.email);
2728
if (!user) {
2829
throw new HttpException('ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.', HttpStatus.NOT_FOUND);
@@ -32,8 +33,8 @@ export class AuthService {
3233
if (!validatedPassword) {
3334
throw new HttpException('ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.', HttpStatus.NOT_FOUND);
3435
}
35-
36-
return await this.generateCookie({ username: user.username, email: user.email });
36+
const token = await this.generateCookie({ username: user.username, email: user.email });
37+
return new ResponseSignInDto(token, user.email, user.username);
3738
}
3839

3940
async findUserByEmail(email: string): Promise<User> {

โ€Žbackend/src/auth/dto/response-signin.dto.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ export class ResponseSignInDto {
44
@ApiProperty()
55
token: string;
66

7-
constructor(token: string) {
7+
@ApiProperty()
8+
email: string;
9+
10+
@ApiProperty()
11+
username: string;
12+
13+
constructor(token: string, email: string, username: string) {
814
this.token = token;
15+
this.email = email;
16+
this.username = username;
917
}
1018
}

โ€Žbackend/src/lecture/dto/create-lecture.dto.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@ export class CreateLectureDto {
66

77
@ApiProperty({ example: '์ด๋Ÿฐ์ด๋Ÿฐ ๊ฐ•์˜์ž…๋‹ˆ๋‹ค' })
88
description: string;
9-
10-
@ApiProperty({ description: '๊ฐ•์˜๋ฅผ ๋งŒ๋“  ๋ฐœํ‘œ์ž email', example: '[email protected]' })
11-
email: string;
129
}

โ€Žbackend/src/lecture/lecture.controller.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Res,
1313
UseGuards
1414
} from '@nestjs/common';
15-
import { ApiBody, ApiHeader, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
15+
import { ApiBody, ApiHeader, ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
1616
import { Response } from 'express';
1717
import { UserService } from 'src/user/user.service';
1818
import { CreateLectureDto } from './dto/create-lecture.dto';
@@ -32,11 +32,18 @@ export class LectureController {
3232
private readonly userService: UserService
3333
) {}
3434

35+
@UseGuards(CustomAuthGuard)
3536
@Post()
37+
@ApiHeader({ name: 'Authorization' })
38+
@ApiOperation({ description: '๊ฐ•์˜๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.' })
3639
@ApiBody({ type: CreateLectureDto })
3740
@ApiResponse({ status: 201 })
38-
async create(@Body() createLecture: CreateLectureDto, @Res() res: Response) {
39-
const user = await this.userService.findOneByEmail(createLecture.email);
41+
@ApiResponse({ status: 401, description: '๋กœ๊ทธ์ธ ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.' })
42+
async create(@Body() createLecture: CreateLectureDto, @Req() req: any, @Res() res: Response) {
43+
if (!req.user) {
44+
throw new HttpException('๋กœ๊ทธ์ธ ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.', HttpStatus.UNAUTHORIZED);
45+
}
46+
const user = await this.userService.findOneByEmail(req.user.email);
4047
const code = await this.lectureService.createLecture(createLecture, user.id);
4148
res.status(HttpStatus.CREATED).send({ code: code });
4249
}
@@ -54,7 +61,8 @@ export class LectureController {
5461
@ApiHeader({ name: 'Authorization' })
5562
@ApiParam({ name: 'code', type: 'string' })
5663
@ApiResponse({ status: 200 })
57-
@ApiResponse({ status: 404 })
64+
@ApiResponse({ status: 401, description: '๋กœ๊ทธ์ธ ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.' })
65+
@ApiResponse({ status: 404, description: '์œ ํšจํ•˜์ง€ ์•Š์€ ๊ฐ•์˜ ์ฐธ์—ฌ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.' })
5866
async enter(@Param('code') code: string, @Req() req: any, @Res() res: Response) {
5967
if (!req.user) {
6068
throw new HttpException('๋กœ๊ทธ์ธ ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.', HttpStatus.UNAUTHORIZED);
@@ -123,4 +131,16 @@ export class LectureController {
123131
const result = await this.lectureService.findLectureRecord(id);
124132
return res.status(HttpStatus.OK).send(result);
125133
}
134+
135+
@UseGuards(CustomAuthGuard)
136+
@Get('/list')
137+
@ApiHeader({ name: 'Authorization' })
138+
async getLectureList(@Req() req: any, @Res() res: Response) {
139+
if (!req.user) {
140+
throw new HttpException('๋กœ๊ทธ์ธ ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.', HttpStatus.UNAUTHORIZED);
141+
}
142+
143+
const result = await this.userService.findLectureList(req.user.email);
144+
return res.status(HttpStatus.OK).send(result);
145+
}
126146
}

โ€Žbackend/src/lecture/lecture.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class LectureService {
9191
}
9292

9393
async findLogs(lecture: Lecture) {
94-
return await this.whiteboardLogModel.find({ lecture_id: lecture }).exec();
94+
return await this.whiteboardLogModel.find({ lecture_id: lecture }, { _id: 0, lecture_id: 0, __v: 0 }).exec();
9595
}
9696

9797
async findLectureRecord(id: Types.ObjectId) {

โ€Žbackend/src/user/dto/userInfo.dto.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ export class UserInfoDto {
1313

1414
lecture_id: mongoose.Types.ObjectId;
1515

16-
constructor({ username, email, lecture_id }) {
16+
constructor({ username, email }) {
1717
this.username = username;
1818
this.email = email;
19-
this.lecture_id = lecture_id;
2019
}
2120
}

โ€Žbackend/src/user/user.controller.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ export class UserController {
1919
if (!req.user) {
2020
throw new HttpException('๋กœ๊ทธ์ธ ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์ž…๋‹ˆ๋‹ค.', HttpStatus.UNAUTHORIZED);
2121
}
22-
const userInfo = await (
23-
await this.userService.findOneByEmail(req.user.email)
24-
).populate({
25-
path: 'lecture_id',
26-
select: '-_id title description',
27-
populate: { path: 'presenter_id', select: '-_id username' }
28-
});
22+
const userInfo = await this.userService.findOneByEmail(req.user.email);
2923

3024
if (!userInfo) {
3125
throw new HttpException('์‚ฌ์šฉ์ž ์ •๋ณด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.', HttpStatus.NOT_FOUND);

โ€Žbackend/src/user/user.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ export class UserService {
2828
{ new: true }
2929
);
3030
}
31+
32+
async findLectureList(email: string) {
33+
return (
34+
await (
35+
await this.findOneByEmail(email)
36+
).populate({
37+
path: 'lecture_id',
38+
select: '-__v',
39+
populate: { path: 'presenter_id', select: '-_id username' }
40+
})
41+
).lecture_id;
42+
}
3143
}

0 commit comments

Comments
ย (0)