Skip to content

Commit

Permalink
refactor(server): refactor function template (#1476)
Browse files Browse the repository at this point in the history
* refactor(server): refactor function template

* chore

* refactor Reducing redundant code

* chore
  • Loading branch information
HUAHUAI23 authored Aug 23, 2023
1 parent cfb475f commit 77ce3de
Show file tree
Hide file tree
Showing 3 changed files with 460 additions and 416 deletions.
6 changes: 6 additions & 0 deletions server/src/function-template/dto/function-templates.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export class FunctionTemplatesDto {

@ApiPropertyOptional({ type: UserInfo })
user?: UserInfo

@ApiProperty({ type: String })
author?: string

@ApiProperty({ type: Boolean })
stared?: boolean
}

export class GetMyStaredFunctionTemplatesDto {
Expand Down
50 changes: 26 additions & 24 deletions server/src/function-template/function-template.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,35 +304,42 @@ export class FunctionTemplateController {
}

if (type === 'default' && keyword) {
const res =
await this.functionTemplateService.findMyFunctionTemplatesByName(
asc,
page,
pageSize,
req.user._id,
keyword,
)
const condition = {
asc,
page,
pageSize,
name: keyword,
}
const res = await this.functionTemplateService.findMyFunctionTemplates(
req.user._id,
condition,
)
return ResponseUtil.ok(res)
}

if (type === 'default' && sort === 'hot') {
const hot = true
const res = await this.functionTemplateService.findMyFunctionTemplates(
asc,
const condition = {
page,
pageSize,
asc,
hot: true,
}
const res = await this.functionTemplateService.findMyFunctionTemplates(
req.user._id,
hot,
condition,
)
return ResponseUtil.ok(res)
}

if (type === 'default') {
const res = await this.functionTemplateService.findMyFunctionTemplates(
const condition = {
asc,
page,
pageSize,
}
const res = await this.functionTemplateService.findMyFunctionTemplates(
req.user._id,
condition,
)
return ResponseUtil.ok(res)
}
Expand Down Expand Up @@ -442,6 +449,7 @@ export class FunctionTemplateController {
@Query('pageSize') pageSize: number,
@Query('keyword') keyword: string,
@Query('sort') sort: string,
@Req() req: IRequest,
) {
asc = asc === 0 ? Number(asc) : 1
page = page ? Number(page) : 1
Expand All @@ -460,6 +468,7 @@ export class FunctionTemplateController {

const res =
await this.functionTemplateService.findRecommendFunctionTemplates(
req.user._id,
condition,
)

Expand Down Expand Up @@ -508,6 +517,7 @@ export class FunctionTemplateController {
@Query('pageSize') pageSize: number,
@Query('keyword') keyword: string,
@Query('sort') sort: string,
@Req() req: IRequest,
) {
asc = asc === 0 ? Number(asc) : 1
page = page ? Number(page) : 1
Expand All @@ -522,25 +532,17 @@ export class FunctionTemplateController {
page,
pageSize,
keyword,
req.user._id,
)
return ResponseUtil.ok(res)
}

if (sort === 'hot') {
const hot = true
const res = await this.functionTemplateService.findFunctionTemplates(
asc,
page,
pageSize,
hot,
)
return ResponseUtil.ok(res)
}

const res = await this.functionTemplateService.findFunctionTemplates(
asc,
page,
pageSize,
req.user._id,
sort,
)

return ResponseUtil.ok(res)
Expand Down
Loading

0 comments on commit 77ce3de

Please sign in to comment.