2024.02.23
This commit is contained in:
parent
62bd20c906
commit
3c698caa02
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"marscode.chatLanguage": "cn",
|
||||||
|
"marscode.codeCompletionPro": {
|
||||||
|
"enableCodeCompletionPro": true
|
||||||
|
},
|
||||||
|
"marscode.enableInlineCommand": true
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
import { Controller, Get, Query, Param } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Controller('goods')
|
||||||
|
export class GoodsController {
|
||||||
|
constructor() {
|
||||||
|
console.log('goods controller')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 示例1:基本查询参数
|
||||||
|
@Get('hello')
|
||||||
|
getHello(@Query('name') name?: string) {
|
||||||
|
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: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { GoodsService } from './goods.service';
|
||||||
|
import { GoodsController } from './goods.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [GoodsService],
|
||||||
|
controllers:[GoodsController]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
export class GoodsModule {}
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class GoodsService {}
|
|
@ -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,6 +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],
|
||||||
|
|
|
@ -1,10 +1,45 @@
|
||||||
import {api} from "@nice/client"
|
import {api} from "@nice/client"
|
||||||
import { useEffect } from "react"
|
import { Button,Tag } from "antd"
|
||||||
|
|
||||||
|
import {useEffect,useMemo,useState} from "react"
|
||||||
|
|
||||||
|
|
||||||
|
function HomePage() {
|
||||||
|
const { data } = api.staff.findMany.useQuery({
|
||||||
|
take: 10
|
||||||
|
})
|
||||||
|
const [counter,setCounter] = useState <number>(0)
|
||||||
|
const counterText = useMemo(() => {
|
||||||
|
return `当前计数为:${counter}`
|
||||||
|
},[counter])
|
||||||
|
|
||||||
export default function HomePage() {
|
|
||||||
const { data } = api.staff.findMany.useQuery({ take: 10 })
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
},[data])
|
},[data])
|
||||||
return <>Home</>
|
|
||||||
|
return <div className="p-2 space-y-2">
|
||||||
|
<Tag>{counterText}</Tag>
|
||||||
|
<div className="space-x-2">
|
||||||
|
<Button type="primary" onClick={() => {
|
||||||
|
setCounter(counter + 1)
|
||||||
|
}}>加1</Button>
|
||||||
|
<Button danger
|
||||||
|
onClick={() => {
|
||||||
|
setCounter(counter - 1)
|
||||||
|
}}>减1</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{
|
||||||
|
data?.map(i => {
|
||||||
|
return <div className="p-2 rounded border shadow">
|
||||||
|
<Tag>{i.username}</Tag>
|
||||||
|
</div>
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HomePage
|
||||||
|
|
|
@ -27,7 +27,8 @@ server {
|
||||||
# 压缩HTTP版本
|
# 压缩HTTP版本
|
||||||
gzip_http_version 1.1;
|
gzip_http_version 1.1;
|
||||||
# 压缩的文件类型
|
# 压缩的文件类型
|
||||||
gzip_types text/plain
|
gzip_types
|
||||||
|
text/plain
|
||||||
text/css
|
text/css
|
||||||
application/json
|
application/json
|
||||||
application/javascript
|
application/javascript
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"dev": "pnpm run --parallel dev",
|
"dev": "pnpm run --parallel dev",
|
||||||
"db:clear": "pnpm --filter common run db:clear"
|
"db:clear": "pnpm --filter common run db:clear",
|
||||||
|
"studio" :"pnpm --filter common run studio"
|
||||||
|
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "insiinc",
|
"author": "insiinc",
|
||||||
|
|
|
@ -329,3 +329,45 @@ model Resource {
|
||||||
@@index([createdAt])
|
@@index([createdAt])
|
||||||
@@map("resource")
|
@@map("resource")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//商品表
|
||||||
|
model Goods {
|
||||||
|
id String @id @default(cuid()) // 商品ID
|
||||||
|
name String @unique // 商品名称
|
||||||
|
description String? // 商品描述
|
||||||
|
price Float @default(0.0) // 商品价格
|
||||||
|
images String[] @default([]) // 商品图片
|
||||||
|
tags Tag[] @relation("GoodsTags") // 多对多关系
|
||||||
|
reviews Review[] // 一对多关系
|
||||||
|
createdAt DateTime @default(now()) @map("created_at") // 创建时间
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at") // 更新时间
|
||||||
|
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||||||
|
@@index([name])
|
||||||
|
@@map("goods")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标签表
|
||||||
|
model Tag {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
name String @unique
|
||||||
|
goods Goods[] @relation("GoodsTags")
|
||||||
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at")
|
||||||
|
deletedAt DateTime? @map("deleted_at")
|
||||||
|
@@map("tag")
|
||||||
|
}
|
||||||
|
|
||||||
|
model Review {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
content String
|
||||||
|
rating Int @default(0)
|
||||||
|
goodsId String @map("goods_id")
|
||||||
|
goods Goods @relation(fields: [goodsId], references: [id])
|
||||||
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at")
|
||||||
|
deletedAt DateTime? @map("deleted_at")
|
||||||
|
@@index([goodsId])
|
||||||
|
@@index([rating])
|
||||||
|
@@map("review")
|
||||||
|
}
|
Loading…
Reference in New Issue