Skip to content

Commit

Permalink
fix: update docs for video controller (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirily11 authored May 23, 2023
1 parent ae0d200 commit 671b604
Show file tree
Hide file tree
Showing 17 changed files with 406 additions and 69 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist && npx prisma generate",
"prebuild": "rimraf dist",
"postinstall": "prisma generate",
"build": "nest build --webpack",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
Expand Down
75 changes: 38 additions & 37 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ import {
import { AuthService } from './auth.service';
import { LocalAuthGuard } from './local-auth.guard';
import { CreateUserDto } from '../user/dto/create-user.dto';
import { ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
import {
ApiBadRequestResponse,
ApiBody,
ApiCreatedResponse,
ApiOkResponse,
ApiOperation,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { SignupResponse } from './dto/signup.dto';
import { SignInResponse } from './dto/signin.dto';

@Controller('auth')
@ApiTags('auth')
Expand All @@ -18,10 +28,28 @@ export class AuthController {
// eslint-disable-next-line prettier/prettier
}

@ApiOperation({
summary: 'Sign up',
description: 'Sign up with username and password',
})
@ApiCreatedResponse({
description: 'Signed up successfully',
type: SignupResponse,
})
@ApiBadRequestResponse({
description: 'Cannot sign up with the given username',
schema: {
type: 'object',
properties: {
message: {
type: 'string',
example: 'Username already exists',
},
},
},
})
@Post('signUp')
async signup(
@Body() body: CreateUserDto,
): Promise<{ user: any; accessToken: string }> {
async signup(@Body() body: CreateUserDto): Promise<SignupResponse> {
try {
const user = await this.authService.signUp(body);
const loginedUser = await this.authService.accessToken(user);
Expand All @@ -33,13 +61,15 @@ export class AuthController {
if (e.code === 'P2002') {
throw new BadRequestException('Username already exists');
}
console.log(e);
throw new Error('Something went wrong');
}
}

@UseGuards(LocalAuthGuard)
@Post('signIn')
@ApiOperation({
summary: 'Sign in',
})
@ApiBody({
schema: {
type: 'object',
Expand All @@ -56,42 +86,13 @@ export class AuthController {
@ApiResponse({
status: 200,
description: 'Signed in',
schema: {
type: 'object',
properties: {
user: {
type: 'object',
properties: {
id: {
type: 'string',
},
username: {
type: 'string',
},
name: {
type: 'string',
},
Wallet: {
type: 'object',
properties: {
address: {
type: 'string',
},
},
},
},
},
accessToken: {
type: 'string',
},
},
},
type: SignInResponse,
})
async signIn(@Request() req): Promise<{ user: any; accessToken: string }> {
const loginedUser = await this.authService.accessToken(req.user);
const signInUser = await this.authService.accessToken(req.user);
return {
user: req.user,
accessToken: loginedUser,
accessToken: signInUser,
};
}
}
13 changes: 13 additions & 0 deletions src/auth/dto/signin.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { GetUserResponse } from '../../user/dto/get-user.dto';

export class SignInResponse {
@ApiProperty({
description: 'User object',
})
user: GetUserResponse;
@ApiProperty({
description: 'JWT Access token',
})
accessToken: string;
}
13 changes: 13 additions & 0 deletions src/auth/dto/signup.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { GetUserResponse } from '../../user/dto/get-user.dto';

export class SignupResponse {
@ApiProperty({
description: 'User object',
})
user: GetUserResponse;
@ApiProperty({
description: 'JWT Access token',
})
accessToken: string;
}
8 changes: 7 additions & 1 deletion src/category/category.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger';
import {
ApiExtraModels,
ApiOkResponse,
ApiTags,
getSchemaPath,
} from '@nestjs/swagger';

import { GetCategoryDto } from './dto/get-category.dto';
import { CategoryService } from './category.service';

@ApiTags('category')
@Controller('category')
export class CategoryController {
constructor(private readonly categoryService: CategoryService) {}
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function buildApiDocument() {
return new DocumentBuilder()
.setTitle('Video Trading server')
.setDescription('API for Api Trading server')
.addTag(
'video',
'This api is used for handling video upload, analyze, list, etc',
)
.addBearerAuth(
// defines the authentication type
// we have defined the permission role called `admin` in this example,
Expand All @@ -27,6 +31,13 @@ function buildApiDocument() {
},
'user',
)
.addBearerAuth(
{
description: 'Transcoding worker permission',
type: 'http',
},
'worker',
)
.setVersion('1.0')
.build();
}
Expand Down
3 changes: 2 additions & 1 deletion src/payment/payment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
} from '@nestjs/common';
import { PaymentService } from './payment.service';
import { JwtAuthGuard } from '../auth/jwt-auth-guard';
import { ApiOkResponse } from '@nestjs/swagger';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { CheckoutDto, CheckoutWithTokenDto } from './dto/checkout.dto';
import { RequestWithUser } from '../common/types';

@ApiTags('payment')
@Controller('payment')
export class PaymentController {
constructor(private readonly paymentService: PaymentService) {}
Expand Down
12 changes: 11 additions & 1 deletion src/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@ import { VideoQuality } from 'src/common/video';
import * as process from 'process';
import { config } from '../common/utils/config/config';
import { z } from 'zod';
import { ApiProperty } from '@nestjs/swagger';

export enum Operation {
GET = 'getObject',
HEAD = 'headObject',
PUT = 'putObject',
}

export interface SignedUrl {
export class SignedUrl {
/**
* Granted PutObject permission
*/
@ApiProperty({
description: 'Pre-signed URL for uploading the file',
})
url: string;
@ApiProperty({
description: 'Key of the file',
})
key: string;
/**
* Granted Get Object permission
*/
@ApiProperty({
description: 'Pre-signed URL for downloading the file',
})
previewUrl?: string;
}

Expand Down
8 changes: 2 additions & 6 deletions src/token/token.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import { JwtAuthGuard } from '../auth/jwt-auth-guard';
import { RequestWithUser } from 'src/common/types';
import { TokenService } from './token.service';
import { getPageAndLimit } from '../common/pagination';
import { ApiTags } from '@nestjs/swagger';

interface AddTokenDto {
tx: string;
timestamp: number;
value: string;
}

@ApiTags('token')
@Controller('token')
export class TokenController {
constructor(private readonly tokenService: TokenService) {}
Expand Down
3 changes: 2 additions & 1 deletion src/transaction/transaction.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Controller, Get, Param, Query, Req, UseGuards } from '@nestjs/common';
import { TransactionService } from './transaction.service';
import { getPageAndLimit } from '../common/pagination';
import { ApiOkResponse } from '@nestjs/swagger';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/jwt-auth-guard';
import { RequestWithUser } from '../common/types';

@ApiTags('transaction')
@Controller('transaction')
export class TransactionController {
constructor(private readonly transactionService: TransactionService) {}
Expand Down
55 changes: 55 additions & 0 deletions src/user/dto/get-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ApiProperty } from '@nestjs/swagger';
class GetUserWalletResponse {
id: string;
@ApiProperty({
description: 'User wallet address',
})
address: string;
createdAt: Date;
updatedAt: Date;
}

export class GetUserResponse {
@ApiProperty({
description: 'User id',
})
id: string;
@ApiProperty({
description: 'User email',
})
email: string;
@ApiProperty({
description: 'User name',
})
name: string;
@ApiProperty({
description: 'User name',
})
username: string;
@ApiProperty({
description: 'Created date',
})
createdAt: Date;
@ApiProperty({
description: 'Updated date',
})
updatedAt: Date;
@ApiProperty({
description: 'User avatar',
})
avatar: string;
@ApiProperty({
description: "User's short description",
})
shortDescription: string;
@ApiProperty({
description: "User's long description",
})
longDescription: string;
version: number;
walletId: string;
@ApiProperty({
description: 'User wallet',
})
Wallet: GetUserWalletResponse;
}
2 changes: 2 additions & 0 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {
ApiAcceptedResponse,
ApiBearerAuth,
ApiOkResponse,
ApiTags,
} from '@nestjs/swagger';
import { Operation, StorageService } from '../storage/storage.service';
import { JwtAuthGuard } from '../auth/jwt-auth-guard';

@ApiTags('user')
@Controller('user')
export class UserController {
constructor(
Expand Down
Loading

1 comment on commit 671b604

@vercel
Copy link

@vercel vercel bot commented on 671b604 May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.