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

[ST-368]⭐과외 종료 api 추가 #40

Merged
merged 5 commits into from
Aug 7, 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
23 changes: 23 additions & 0 deletions src/agora/agora.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ export class AgoraService {
return null;
}
}

async disableWhiteBoardChannel(whiteBoardUUID: string) {
try {
const { data } = await firstValueFrom(
this.httpService.patch(
`https://api.netless.link/v5/rooms/${whiteBoardUUID}`,
{
isBan: true,
},
{
headers: {
'Content-Type': 'application/json',
token: process.env.AGORA_WHITEBOARD_SDK_TOKEN,
region: 'us-sv',
},
},
),
);
return data;
} catch (error) {
return null;
}
}
}

export interface WhiteBoardData {
Expand Down
10 changes: 10 additions & 0 deletions src/tutoring/descriptions/tutoring.operation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const TutoringOperation = {
finish: {
summary: '과외 종료',
description: '과외를 종료합니다',
},
info: {
summary: '과외 정보 조희',
description: '특정 과외의 정보를 조회합니다',
},
};
2 changes: 1 addition & 1 deletion src/tutoring/descriptions/tutoring.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const TutoringEntity = {
type: 'string',
description: '튜터링 상태',
example: 'matched',
enum: ['matched', 'started', 'ended'],
enum: ['matched', 'started', 'finished'],
},
whiteBoardUUID: {
type: 'string',
Expand Down
20 changes: 19 additions & 1 deletion src/tutoring/tutoring.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { TutoringService } from './tutoring.service';
import { Controller } from '@nestjs/common';
import { Controller, Get, Param } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { TutoringOperation } from './descriptions/tutoring.operation';

@Controller('tutoring')
export class TutoringController {
constructor(private readonly tutoringService: TutoringService) {}

@ApiBearerAuth('Authorization')
@ApiTags('User')
@Get('finish/:tutoringId')
@ApiOperation(TutoringOperation.finish)
finish(@Param('tutoringId') tutoringId: string) {
return this.tutoringService.finish(tutoringId);
}

@ApiBearerAuth('Authorization')
@ApiTags('User')
@ApiOperation(TutoringOperation.info)
@Get('info/:tutoringId')
info(@Param('tutoringId') tutoringId: string) {
return this.tutoringService.info(tutoringId);
}
}
5 changes: 4 additions & 1 deletion src/tutoring/tutoring.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TutoringService } from './tutoring.service';
import { TutoringController } from './tutoring.controller';
import { DynamooseModule } from 'nestjs-dynamoose';
import { TutoringSchema } from './entities/tutoring.schema';
import { TutoringRepository } from './tutoring.repository';
import { AgoraModule } from '../agora/agora.module';

@Module({
imports: [
Expand All @@ -12,8 +14,9 @@ import { TutoringSchema } from './entities/tutoring.schema';
schema: TutoringSchema,
},
]),
AgoraModule,
],
controllers: [TutoringController],
providers: [TutoringService],
providers: [TutoringService, TutoringRepository],
})
export class TutoringModule {}
19 changes: 19 additions & 0 deletions src/tutoring/tutoring.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,23 @@ export class TutoringRepository {

return tutoring;
}

async finishTutoring(tutoringId: string): Promise<Tutoring> {
let tutoring: Tutoring;
try {
tutoring = await this.tutoringModel.get({ id: tutoringId });
} catch (error) {
throw new Error('해당 과외를 찾을 수 없습니다.');
}
try {
if (tutoring !== undefined) {
return await this.tutoringModel.update(
{ id: tutoringId },
{ status: 'finished', endedAt: new Date().toISOString() },
);
}
} catch (error) {
throw new Error('과외 상태를 변경할 수 없습니다.');
}
}
}
30 changes: 29 additions & 1 deletion src/tutoring/tutoring.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
import { Injectable } from '@nestjs/common';
import { AgoraService } from '../agora/agora.service';
import { TutoringRepository } from './tutoring.repository';
import { Fail, Success } from '../response';

@Injectable()
export class TutoringService {
constructor() {}
constructor(
private readonly tutoringRepository: TutoringRepository,
private readonly agoraService: AgoraService,
) {}

async finish(tutoringId: string) {
//TODO: 과외에 참여한 사람이 맞는지 확인해야할까?
try {
const tutoring = await this.tutoringRepository.finishTutoring(tutoringId);
const { whiteBoardUUID } = tutoring;
await this.agoraService.disableWhiteBoardChannel(whiteBoardUUID);

return new Success('과외가 종료되었습니다.', { tutoringId });
} catch (error) {
return new Fail(error.message);
}
}

async info(tutoringId: string) {
try {
const tutoring = await this.tutoringRepository.get(tutoringId);
return new Success('과외 정보를 가져왔습니다.', { tutoring });
} catch (error) {
return new Fail(error.message);
}
}
}