-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add swagger for some apis (#65)
- Loading branch information
1 parent
2ff7209
commit 4e3dd5c
Showing
14 changed files
with
455 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,47 @@ | ||
import { ProfileDto } from '@/api/profile/dto/profile.dto'; | ||
import { Expose, Type } from 'class-transformer'; | ||
import { | ||
BooleanFieldOptional, | ||
ClassField, | ||
ClassFieldOptional, | ||
DateFieldOptional, | ||
NumberFieldOptional, | ||
StringField, | ||
StringFieldOptional, | ||
} from '@repo/api'; | ||
|
||
export class ArticleDto { | ||
@Expose() | ||
@StringFieldOptional({ expose: true }) | ||
slug?: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
title: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
description: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
body: string; | ||
|
||
@Expose() | ||
@StringField({ each: true, expose: true }) | ||
tagList: string[]; | ||
|
||
@Expose() | ||
@DateFieldOptional({ expose: true }) | ||
createdAt?: Date; | ||
|
||
@Expose() | ||
@DateFieldOptional({ expose: true }) | ||
updatedAt?: Date; | ||
|
||
@Expose() | ||
@BooleanFieldOptional({ expose: true }) | ||
favorited?: boolean; | ||
|
||
@Expose() | ||
@NumberFieldOptional({ expose: true }) | ||
favoritesCount?: number; | ||
|
||
@Expose() | ||
@Type(() => ProfileDto) | ||
@ClassFieldOptional(() => ProfileDto, { expose: true }) | ||
author?: ProfileDto; | ||
} | ||
|
||
export class ArticleResDto { | ||
@Expose() | ||
@Type(() => ArticleDto) | ||
@ClassField(() => ArticleDto, { expose: true }) | ||
article: ArticleDto; | ||
} |
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,19 +1,35 @@ | ||
import { Body, Controller, Post, SerializeOptions } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
import { Public } from '@repo/api'; | ||
import { ApiBody, ApiTags, getSchemaPath } from '@nestjs/swagger'; | ||
import { ApiPublic } from '@repo/api/decorators/http.decorators'; | ||
import { UserResDto } from '../user/dto/user.dto'; | ||
import { AuthService } from './auth.service'; | ||
import { LoginDto } from './dto/login.dto'; | ||
import { LoginReqDto } from './dto/login.dto'; | ||
|
||
@ApiTags('Auth') | ||
@Controller() | ||
export class AuthController { | ||
constructor(private readonly authService: AuthService) {} | ||
|
||
@Post('users/login') | ||
@Public() | ||
@ApiPublic({ | ||
type: UserResDto, | ||
summary: 'Sign in', | ||
}) | ||
@ApiBody({ | ||
description: 'User login request', | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
user: { | ||
type: 'object', | ||
$ref: getSchemaPath(LoginReqDto), | ||
}, | ||
}, | ||
required: ['user'], | ||
}, | ||
}) | ||
@SerializeOptions({ type: UserResDto }) | ||
async login(@Body('user') userData: LoginDto): Promise<UserResDto> { | ||
async login(@Body('user') userData: LoginReqDto): Promise<UserResDto> { | ||
return this.authService.login(userData); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import { Expose, Type } from 'class-transformer'; | ||
import { ClassField, StringField } from '@repo/api'; | ||
|
||
export class ProfileDto { | ||
@Expose() | ||
@StringField({ expose: true }) | ||
username: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
bio: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
image: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
following: boolean; | ||
} | ||
|
||
export class ProfileResDto { | ||
@Expose() | ||
@Type(() => ProfileDto) | ||
@ClassField(() => ProfileDto, { expose: true }) | ||
profile: ProfileDto; | ||
} |
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 |
---|---|---|
@@ -1,24 +1,23 @@ | ||
import { Expose, Type } from 'class-transformer'; | ||
import { ClassField, EmailField, StringField } from '@repo/api'; | ||
|
||
export class UserDto { | ||
@Expose() | ||
@EmailField({ expose: true }) | ||
email: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
token: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
username: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
bio: string; | ||
|
||
@Expose() | ||
@StringField({ expose: true }) | ||
image: string; | ||
} | ||
|
||
export class UserResDto { | ||
@Expose() | ||
@Type(() => UserDto) | ||
@ClassField(() => UserDto, { expose: true }) | ||
user: UserDto; | ||
} |
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
Oops, something went wrong.