Skip to content

Commit

Permalink
fix: update api controllers (#86) (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
junjie-w authored Dec 30, 2024
1 parent 0f47a32 commit c0e1fc3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .changeset/slow-otters-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@api-client-sdk-streamline-sample/products-api": patch
"@api-client-sdk-streamline-sample/users-api": patch
---

update api controllers
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ npm run dev # products: 3001, users: 3002
# Products API: http://localhost:3001/api-docs
# Users API: http://localhost:3002/api-docs

# 3. Test All Endpoints: Run Test Script with Sample Data
# 3. Run Test Script with Sample Data
npm run demo # Executes try-{service}-api.sh
# products-api → try-products-api.sh
# users-api → try-users-api.sh
Expand Down Expand Up @@ -121,7 +121,7 @@ Then, OpenAPI specs are generated and pushed to SwaggerHub:
![workflow-title-push-spec](./assets/docs/workflow-title-push-spec.png)
![workflow-detail-push-spec](./assets/docs/workflow-detail-push-sepc.png)

Once published, specs are available on SwaggerHub:
Once published, API specs are available on SwaggerHub:
- 📄 [@api-client-sdk-streamline-sample | Products API](https://app.swaggerhub.com/apis/junjie.wu/sample-products-api)
- 📄 [@api-client-sdk-streamline-sample | Users API](https://app.swaggerhub.com/apis/junjie.wu/sample-users-api)

Expand All @@ -142,7 +142,7 @@ packages/
![workflow-title-publish-sdk](./assets/docs/workflow-title-publish-sdk.png)
![workflow-detail-publish-sdk](./assets/docs/workflow-detail-publish-sdk.png)

Published SDK packages:
Once published, SDK packages are available on NPM:
- 🧳 [@api-client-sdk-streamline-sample/products-api-client](https://www.npmjs.com/package/@api-client-sdk-streamline-sample/products-api-client)
- 🧳 [@api-client-sdk-streamline-sample/users-api-client](https://www.npmjs.com/package/@api-client-sdk-streamline-sample/users-api-client)

Expand Down Expand Up @@ -172,15 +172,15 @@ apps/ecom-app/
└── api-client-config/ # API client configuration
```

Client Configuration Structure:
API Client Configuration Structure:

```bash
api-client-config/
├── configs/ # Environment-based configuration
├── middlewares/ # Request & Response & onError middlewares
├── errors/ # Error handling & types
├── api-client-cache.ts # Client instance caching
├── api-client-config.ts # Base client configuration
├── api-client-config.ts # API configuration builder
├── api-client-factory.ts # Factory pattern for client creation
└── logger.ts # Logging utilities
```
Expand Down
13 changes: 10 additions & 3 deletions apps/products-api/src/products/products.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {
Query,
NotFoundException,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiQuery } from '@nestjs/swagger';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiQuery,
ApiBody,
} from '@nestjs/swagger';
import { ProductsService } from './products.service';
import { CreateProductDto } from './dto/create-product.dto';
import { Product } from './entities/product.entity';
Expand All @@ -22,6 +28,7 @@ export class ProductsController {
operationId: 'createProduct',
summary: 'Create a new product',
})
@ApiBody({ type: CreateProductDto })
@ApiResponse({
status: 201,
description: 'Product created successfully',
Expand All @@ -31,8 +38,8 @@ export class ProductsController {
status: 400,
description: 'Invalid product data',
})
async create(@Body() createProductDto: CreateProductDto) {
return this.productsService.create(createProductDto);
async create(@Body() body: CreateProductDto) {
return this.productsService.create(body);
}

@Get()
Expand Down
7 changes: 4 additions & 3 deletions apps/users-api/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Param,
NotFoundException,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger';
import { UsersService } from './users.service';
import { CreateUserDto } from './dto/create-user.dto';
import { User } from './entities/user.entity';
Expand All @@ -18,13 +18,14 @@ export class UsersController {

@Post()
@ApiOperation({ operationId: 'createUser', summary: 'Create a new user' })
@ApiBody({ type: CreateUserDto })
@ApiResponse({
status: 201,
description: 'User created successfully',
type: User,
})
async create(@Body() createUserDto: CreateUserDto) {
return this.usersService.create(createUserDto);
async create(@Body() body: CreateUserDto) {
return this.usersService.create(body);
}

@Get()
Expand Down

0 comments on commit c0e1fc3

Please sign in to comment.