02232017
This commit is contained in:
parent
5df00eeacd
commit
28132992c8
|
@ -1,9 +1,41 @@
|
||||||
import { Controller, Get } from '@nestjs/common';
|
import { Controller, Get, Query, Param } from '@nestjs/common';
|
||||||
|
|
||||||
@Controller('goods')
|
@Controller('goods')
|
||||||
export class GoodsController {
|
export class GoodsController {
|
||||||
|
constructor() {
|
||||||
|
console.log('goods controller')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 示例1:基本查询参数
|
||||||
@Get('hello')
|
@Get('hello')
|
||||||
getHello(): string {
|
getHello(@Query('name') name?: string) {
|
||||||
return 'Hello World!';
|
return {
|
||||||
|
message: 'Hello World!',
|
||||||
|
name: name || 'Guest'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 示例2:路径参数
|
||||||
|
@Get('detail/:id')
|
||||||
|
getDetail(@Param('id') id: string) {
|
||||||
|
return {
|
||||||
|
id: id,
|
||||||
|
detail: `Detail for product ${id}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 示例3:多个查询参数
|
||||||
|
@Get('search')
|
||||||
|
searchProducts(
|
||||||
|
@Query('keyword') keyword: string,
|
||||||
|
@Query('page') page: number = 1,
|
||||||
|
@Query('limit') limit: number = 10
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
keyword,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
results: []
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { RoleMapModule } from '@server/models/rbac/rbac.module';
|
||||||
import { TransformModule } from '@server/models/transform/transform.module';
|
import { TransformModule } from '@server/models/transform/transform.module';
|
||||||
|
|
||||||
import { ResourceModule } from '@server/models/resource/resource.module';
|
import { ResourceModule } from '@server/models/resource/resource.module';
|
||||||
|
import { GoodsModule } from '@server/models/goods/goods.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -33,8 +34,9 @@ import { ResourceModule } from '@server/models/resource/resource.module';
|
||||||
VisitModule,
|
VisitModule,
|
||||||
WebSocketModule,
|
WebSocketModule,
|
||||||
ResourceModule,
|
ResourceModule,
|
||||||
|
GoodsModule
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [TrpcService, TrpcRouter, Logger],
|
providers: [TrpcService, TrpcRouter, Logger],
|
||||||
})
|
})
|
||||||
export class TrpcModule {}
|
export class TrpcModule { }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { api } from "@nice/client"
|
import { api } from "@nice/client"
|
||||||
|
import { apiClient } from "@web/src/utils"
|
||||||
import { Button, Tag } from "antd"
|
import { Button, Tag } from "antd"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
|
|
||||||
|
@ -10,9 +11,14 @@ function HomePage() {
|
||||||
const counterText = useMemo(() => {
|
const counterText = useMemo(() => {
|
||||||
return `当前计数为:${counter}`
|
return `当前计数为:${counter}`
|
||||||
}, [counter])
|
}, [counter])
|
||||||
|
|
||||||
|
const getData = async () => {
|
||||||
|
const res = await apiClient.get("/goods/hello")
|
||||||
|
console.log(res)
|
||||||
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(data)
|
getData()
|
||||||
}, [data])
|
}, [])
|
||||||
return <div className="p-2 space-y-2">
|
return <div className="p-2 space-y-2">
|
||||||
<Tag>{counterText}</Tag>
|
<Tag>{counterText}</Tag>
|
||||||
<div className="space-x-2" >
|
<div className="space-x-2" >
|
||||||
|
|
Loading…
Reference in New Issue