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(money): add api declarations for transactions
- Loading branch information
1 parent
899d3c8
commit 7e63148
Showing
10 changed files
with
124 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common' | ||
|
||
import { TransactionController } from './presentation/http/controller/TransactionController' | ||
|
||
@Module({ | ||
controllers: [TransactionController], | ||
}) | ||
export class MoneyModule implements NestModule { | ||
public configure(consumer: MiddlewareConsumer) { | ||
// pass | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
back/src/money/presentation/http/controller/TransactionController.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,53 @@ | ||
import { Body, Controller, Post } from '@nestjs/common' | ||
import { | ||
ApiBearerAuth, | ||
ApiCreatedResponse, | ||
ApiOperation, | ||
ApiUseTags, | ||
} from '@nestjs/swagger' | ||
|
||
import { IncomeRequest } from '../request/IncomeRequest' | ||
import { OutcomeRequest } from '../request/OutcomeRequest' | ||
import { IncomeResponse } from '../response/IncomeResponse' | ||
import { OutcomeResponse } from '../response/OutcomeResponse' | ||
|
||
@Controller('money/transaction') | ||
@ApiUseTags('money') | ||
@ApiBearerAuth() | ||
export class TransactionController { | ||
@Post('income') | ||
@ApiOperation({ title: 'Create new income transaction' }) | ||
@ApiCreatedResponse({ | ||
description: 'Transaction created', | ||
type: IncomeResponse, | ||
}) | ||
public async income(@Body() request: IncomeRequest): Promise<IncomeResponse> { | ||
const { amount, currency, source, date } = request | ||
|
||
return { | ||
amount, | ||
currency, | ||
source, | ||
date, | ||
} | ||
} | ||
|
||
@Post('outcome') | ||
@ApiOperation({ title: 'Create new outcome transaction' }) | ||
@ApiCreatedResponse({ | ||
description: 'Transaction created', | ||
type: OutcomeResponse, | ||
}) | ||
public async outcome( | ||
@Body() request: OutcomeRequest, | ||
): Promise<OutcomeResponse> { | ||
const { amount, currency, category, date } = request | ||
|
||
return { | ||
amount, | ||
currency, | ||
category, | ||
date, | ||
} | ||
} | ||
} |
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 @@ | ||
export { IncomeResponse as IncomeRequest } from '../response/IncomeResponse' |
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 @@ | ||
export { OutcomeResponse as OutcomeRequest } from '../response/OutcomeResponse' |
18 changes: 18 additions & 0 deletions
18
back/src/money/presentation/http/response/IncomeResponse.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,18 @@ | ||
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger' | ||
|
||
import { Currency } from '@shared/enum/Currency' | ||
import { IncomeModel } from '@shared/models/money/IncomeModel' | ||
|
||
export class IncomeResponse implements IncomeModel { | ||
@ApiModelProperty({ example: 1000 }) | ||
public readonly amount: number | ||
|
||
@ApiModelProperty({ example: Currency.RUB }) | ||
public readonly currency: Currency | ||
|
||
@ApiModelProperty({ example: 'NASA' }) | ||
public readonly source: string | ||
|
||
@ApiModelPropertyOptional({ example: '2019-02-10' }) | ||
public readonly date?: string | ||
} |
18 changes: 18 additions & 0 deletions
18
back/src/money/presentation/http/response/OutcomeResponse.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,18 @@ | ||
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger' | ||
|
||
import { Currency } from '@shared/enum/Currency' | ||
import { OutcomeModel } from '@shared/models/money/OutcomeModel' | ||
|
||
export class OutcomeResponse implements OutcomeModel { | ||
@ApiModelProperty({ example: 1000 }) | ||
public readonly amount: number | ||
|
||
@ApiModelProperty({ example: Currency.RUB }) | ||
public readonly currency: Currency | ||
|
||
@ApiModelProperty({ example: 'Restaurants' }) | ||
public readonly category: string | ||
|
||
@ApiModelPropertyOptional({ example: '2019-02-10' }) | ||
public readonly date?: 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,3 @@ | ||
export enum Currency { | ||
RUB, | ||
} |
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 { Currency } from '@shared/enum/Currency' | ||
|
||
export interface IncomeModel { | ||
readonly amount: number // penny! | ||
readonly currency: Currency | ||
readonly source: string | ||
readonly date?: 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 { Currency } from '@shared/enum/Currency' | ||
|
||
export interface OutcomeModel { | ||
readonly amount: number // penny! | ||
readonly currency: Currency | ||
readonly category: string | ||
readonly date?: string | ||
} |