Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(server): refactor function template #1476

Merged
merged 5 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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