This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
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.
feat(user): add api declaration for auth
- Loading branch information
1 parent
370afb6
commit 4efed72
Showing
11 changed files
with
91 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common' | ||
|
||
@Module({ }) | ||
import { UserModule } from './user/user.module' | ||
|
||
@Module({ | ||
imports: [UserModule], | ||
}) | ||
export class AppModule implements NestModule { | ||
public configure(consumer: MiddlewareConsumer) { | ||
// pass | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -24,4 +24,4 @@ const corsMiddleware = () => { | |
|
||
export default (app: INestApplication) => { | ||
app.use(corsMiddleware()) | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
back/src/user/presentation/http/controller/AuthController.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Body, Controller, Post } from '@nestjs/common' | ||
import { | ||
ApiBadRequestResponse, | ||
ApiCreatedResponse, | ||
ApiOkResponse, | ||
ApiOperation, | ||
ApiUseTags, | ||
} from '@nestjs/swagger' | ||
|
||
import { AuthRequest } from '../request/AuthRequest' | ||
import { TokenResponse } from '../response/TokenResponse' | ||
import { PostNoCreate } from './annotations/PostNoCreate' | ||
|
||
@Controller('user/auth') | ||
@ApiUseTags('user') | ||
export class AuthController { | ||
@PostNoCreate('sign-in') | ||
@ApiOperation({ title: 'Sign-in by email and password' }) | ||
@ApiOkResponse({ description: 'Valid credentials', type: TokenResponse }) | ||
@ApiBadRequestResponse({ description: 'Invalid credentials' }) | ||
public async signIn(@Body() request: AuthRequest): Promise<TokenResponse> { | ||
const { email, password } = request | ||
|
||
return { | ||
token: email + password, | ||
} | ||
} | ||
|
||
@Post('sign-up') | ||
@ApiOperation({ title: 'Sign-up by email and password' }) | ||
@ApiCreatedResponse({ description: 'User created', type: TokenResponse }) | ||
@ApiBadRequestResponse({ description: 'User already exists' }) | ||
public async signUp(@Body() request: AuthRequest): Promise<TokenResponse> { | ||
const { email, password } = request | ||
|
||
return { | ||
token: email + password, | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
back/src/user/presentation/http/controller/annotations/PostNoCreate.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ComposeMethodDecorators } from '@breadhead/detil-ts' | ||
import { HttpCode, Post } from '@nestjs/common' | ||
|
||
export const PostNoCreate = (path: string) => | ||
ComposeMethodDecorators([Post(path), HttpCode(200)]) |
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,9 @@ | ||
import { ApiModelProperty } from '@nestjs/swagger' | ||
|
||
export class AuthRequest { | ||
@ApiModelProperty({ example: 'email@email.com' }) | ||
public readonly email: string | ||
|
||
@ApiModelProperty({ example: 'Pas$w0rd' }) | ||
public readonly password: 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,8 @@ | ||
import { ApiModelProperty } from '@nestjs/swagger' | ||
|
||
import { TokenModel } from '@shared/models/user/TokenModel' | ||
|
||
export class TokenResponse implements TokenModel { | ||
@ApiModelProperty({ example: 'token-string-with-signature' }) | ||
public readonly token: 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,12 @@ | ||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common' | ||
|
||
import { AuthController } from './presentation/http/controller/AuthController' | ||
|
||
@Module({ | ||
controllers: [AuthController], | ||
}) | ||
export class UserModule implements NestModule { | ||
public configure(consumer: MiddlewareConsumer) { | ||
// pass | ||
} | ||
} |
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 interface TokenModel { | ||
readonly token: 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