-
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.
- Loading branch information
1 parent
3747f75
commit 6baceb2
Showing
18 changed files
with
205 additions
and
69 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
4 changes: 3 additions & 1 deletion
4
apps/your-burger-api/src/app/burger-business/domain/burger-brand/burger-brand.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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Burger } from '../burger'; | ||
import { BurgerPlace } from '../burger-place/burger-place'; | ||
|
||
export class BurgerBrand { | ||
id: number; | ||
name: string; | ||
slug: string; | ||
burgerPlace: BurgerPlace; | ||
place: BurgerPlace; | ||
burger: Burger; | ||
} |
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
4 changes: 4 additions & 0 deletions
4
apps/your-burger-api/src/app/burger-business/infra/http/_shared/dto/burger-brand-item.dto.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,4 @@ | ||
export class BurgerBrandItemDto { | ||
name: string; | ||
slug: string; | ||
} |
14 changes: 14 additions & 0 deletions
14
apps/your-burger-api/src/app/burger-business/infra/http/_shared/dto/burger-item.dto.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,14 @@ | ||
// import { BurgerType } from '../../../../domain/burger'; | ||
// import { BurgerBrandItemDto } from './burger-brand-item.dto'; | ||
|
||
export class BurgerItemDto { | ||
id: string; | ||
name: string; | ||
description: string; | ||
// type: BurgerType; | ||
// brand: BurgerBrandItemDto; | ||
|
||
constructor(partial: Partial<BurgerItemDto>) { | ||
Object.assign(this, partial); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
apps/your-burger-api/src/app/burger-business/infra/http/_utils/index.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,2 @@ | ||
export * from './paginated-response'; | ||
export * from './paginated-response.dto'; |
6 changes: 6 additions & 0 deletions
6
apps/your-burger-api/src/app/burger-business/infra/http/_utils/paginated-response.dto.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,6 @@ | ||
import { Type } from 'class-transformer'; | ||
|
||
export class PaginatedResponseDto<T> { | ||
@Type(() => Array<T>) | ||
data: T[]; | ||
} |
25 changes: 25 additions & 0 deletions
25
apps/your-burger-api/src/app/burger-business/infra/http/_utils/paginated-response.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,25 @@ | ||
import { applyDecorators, Type } from '@nestjs/common'; | ||
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger'; | ||
import { PaginatedResponseDto } from './paginated-response.dto'; | ||
|
||
export const ApiOkResponsePaginated = <DataDto extends Type<unknown>>( | ||
dataDto: DataDto | ||
) => | ||
applyDecorators( | ||
ApiExtraModels(PaginatedResponseDto, dataDto), | ||
ApiOkResponse({ | ||
schema: { | ||
allOf: [ | ||
{ $ref: getSchemaPath(PaginatedResponseDto) }, | ||
{ | ||
properties: { | ||
data: { | ||
type: 'array', | ||
items: { $ref: getSchemaPath(dataDto) }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
); |
19 changes: 16 additions & 3 deletions
19
apps/your-burger-api/src/app/burger-business/infra/http/burger/burgers.controller.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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
import { API_TAGS } from '../../../../../open-api'; | ||
import { Burger } from '../../../domain/burger'; | ||
import { BurgersRepository } from '../../../domain/burgers.repository'; | ||
import { BurgerItemDto } from '../_shared/dto/burger-item.dto'; | ||
import { ApiOkResponsePaginated, PaginatedResponseDto } from '../_utils'; | ||
|
||
@Controller('burgers') | ||
@ApiTags(API_TAGS.BURGERS) | ||
export class BurgersController { | ||
constructor(private readonly burgersRepository: BurgersRepository) {} | ||
|
||
@Get() | ||
public async getBurgers(): Promise<Burger[]> { | ||
return this.burgersRepository.find(); | ||
@ApiOkResponsePaginated(BurgerItemDto) | ||
public async getBurgers(): Promise<PaginatedResponseDto<BurgerItemDto>> { | ||
const burgers = await this.burgersRepository.find(); | ||
console.log(JSON.stringify(burgers)); | ||
return { | ||
data: burgers.map( | ||
(burger) => | ||
new BurgerItemDto({ | ||
id: burger.id, | ||
name: burger.name, | ||
description: burger.description, | ||
}) | ||
), | ||
}; | ||
} | ||
} |
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
Binary file not shown.
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
Oops, something went wrong.