Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(money): add statistics controllers declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Jan 28, 2019
1 parent d930817 commit 48d9e1e
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Controller, Get, Query } from '@nestjs/common'
import {
ApiBearerAuth,
ApiOkResponse,
ApiOperation,
ApiUseTags,
} from '@nestjs/swagger'

import { DateRange } from '@back/utils/infrastructure/dto/DateRange'
import { ApiQueryDateRange } from '@back/utils/presentation/http/api/ApiQueryDateRange'
import { ParseDateRangePipe } from '@back/utils/presentation/http/pipes/dateRange/ParseDateRangePipe'
import { GroupBy } from '@shared/enum/GroupBy'

import { CategoryGroupOutcomeResponse } from '../response/CategoryGroupOutcomeResponse'
import { DateGroupResponse } from '../response/DateGroupResponse'
import { SourceGroupIncomeResponse } from '../response/SourceGroupIncomeResponse'

@Controller('money/statistics')
@ApiUseTags('money')
@ApiBearerAuth()
export class StatisticsController {
@Get('date-range')
@ApiOperation({ title: 'Show date range statistics' })
@ApiOkResponse({
description: 'Fetching stats sucess',
type: DateGroupResponse,
isArray: true,
})
@ApiQueryDateRange()
public async showDateRangeStats(
@Query(ParseDateRangePipe) range: DateRange,
@Query('by') by: GroupBy = GroupBy.Month,
): Promise<DateGroupResponse[]> {
return []
}

@Get('income-sources')
@ApiOperation({ title: 'Show income sources' })
@ApiOkResponse({
description: 'Fetching stats sucess',
type: SourceGroupIncomeResponse,
isArray: true,
})
@ApiQueryDateRange()
public async showIncomeSourcesStats(
@Query(ParseDateRangePipe) range: DateRange,
): Promise<SourceGroupIncomeResponse[]> {
return []
}

@Get('outcome-categories')
@ApiOperation({ title: 'Show outcome categories' })
@ApiOkResponse({
description: 'Fetching stats sucess',
type: CategoryGroupOutcomeResponse,
isArray: true,
})
@ApiQueryDateRange()
public async showOutcomeCategoriesStats(
@Query(ParseDateRangePipe) range: DateRange,
): Promise<CategoryGroupOutcomeResponse[]> {
return []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiModelProperty } from '@nestjs/swagger'

import { Currency } from '@shared/enum/Currency'
import { CategoryGroupOutcomeModel } from '@shared/models/money/CategoryGroupOutcomeModel'

export class CategoryGroupOutcomeResponse implements CategoryGroupOutcomeModel {
@ApiModelProperty({ example: 'NASA' })
public readonly category: string

@ApiModelProperty({ example: 20000 })
public readonly outcome: number

@ApiModelProperty({ example: Currency.RUB, enum: Object.values(Currency) })
public readonly currency: Currency
}
21 changes: 21 additions & 0 deletions back/src/money/presentation/http/response/DateGroupResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ApiModelProperty } from '@nestjs/swagger'

import { Currency } from '@shared/enum/Currency'
import { DateGroupModel } from '@shared/models/money/DateGroupModel'

export class DateGroupResponse implements DateGroupModel {
@ApiModelProperty({ example: 'Jan 2019' })
public readonly start: string

@ApiModelProperty({ example: 'Feb 2019' })
public readonly end: string

@ApiModelProperty({ example: 12000 })
public readonly income: number

@ApiModelProperty({ example: 3000 })
public readonly outcome: number

@ApiModelProperty({ example: Currency.RUB, enum: Object.values(Currency) })
public readonly currency: Currency
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class IncomeResponse implements IncomeModel {
@ApiModelProperty({ example: 1000 })
public readonly amount: number

@ApiModelProperty({ example: Currency.RUB })
@ApiModelProperty({ example: Currency.RUB, enum: Object.values(Currency) })
public readonly currency: Currency

@ApiModelProperty({ example: 'NASA' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class OutcomeResponse implements OutcomeModel {
@ApiModelProperty({ example: 1000 })
public readonly amount: number

@ApiModelProperty({ example: Currency.RUB })
@ApiModelProperty({ example: Currency.RUB, enum: Object.values(Currency) })
public readonly currency: Currency

@ApiModelProperty({ example: 'Restaurants' })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiModelProperty } from '@nestjs/swagger'

import { Currency } from '@shared/enum/Currency'
import { SourceGroupIncomeModel } from '@shared/models/money/SourceGroupIncomeModel'

export class SourceGroupIncomeResponse implements SourceGroupIncomeModel {
@ApiModelProperty({ example: 'NASA' })
public readonly source: string

@ApiModelProperty({ example: 20000 })
public readonly income: number

@ApiModelProperty({ example: Currency.RUB, enum: Object.values(Currency) })
public readonly currency: Currency
}
7 changes: 7 additions & 0 deletions shared/models/money/CategoryGroupOutcomeModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Currency } from '@shared/enum/Currency'

export interface CategoryGroupOutcomeModel {
readonly category: string
readonly outcome: number
readonly currency: Currency
}
9 changes: 9 additions & 0 deletions shared/models/money/DateGroupModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Currency } from '@shared/enum/Currency'

export interface DateGroupModel {
readonly start: string
readonly end: string
readonly income: number
readonly outcome: number
readonly currency: Currency
}
7 changes: 7 additions & 0 deletions shared/models/money/SourceGroupIncomeModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Currency } from '@shared/enum/Currency'

export interface SourceGroupIncomeModel {
readonly source: string
readonly income: number
readonly currency: Currency
}

0 comments on commit 48d9e1e

Please sign in to comment.