Skip to content

Commit

Permalink
fix(server): add recommended function templates and limits for functi…
Browse files Browse the repository at this point in the history
…on templates (#1316)

* feat(server): add function template market

* refactor(server): refactor auth api(profile/pat) (#1226)

* feat(server): add function template market

* chore(server: Interface aggregation)

* chore(server: add metering)

* change some interface

* fix

* fix

* fix(server): Removing sensitive information and adding recommendation
templates

* feat(sever): add function template limits

* change .gitignore

* feat(sever): search add function template item name

* feat(server): Enhanced Search

* feat(server): 0fatal review

---------

Co-authored-by: maslow <wangfugen@126.com>
  • Loading branch information
HUAHUAI23 and maslow authored Jun 28, 2023
1 parent 706a2e2 commit 0808c6a
Show file tree
Hide file tree
Showing 5 changed files with 409 additions and 25 deletions.
2 changes: 0 additions & 2 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@ lerna-debug.log*

.env.local
.env

test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { CreateEnvironmentDto } from '../../application/dto/create-env.dto'
import { CreateDependencyDto } from 'src/dependency/dto/create-dependency.dto'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import {
ArrayMaxSize,
IsBoolean,
IsIn,
IsNotEmpty,
IsString,
Matches,
MaxLength,
MinLength,
ValidateNested,
} from 'class-validator'
import { Type } from 'class-transformer'
Expand Down Expand Up @@ -64,6 +66,7 @@ export class CreateFunctionTemplateDto {

@ApiPropertyOptional({ description: 'function template description' })
@IsString()
@MinLength(8)
@MaxLength(256)
description?: string

Expand All @@ -73,6 +76,7 @@ export class CreateFunctionTemplateDto {
})
@IsNotEmpty()
@ValidateNested({ each: true })
@ArrayMaxSize(20)
@Type(() => FunctionTemplateItemDto)
items: FunctionTemplateItemDto[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { CreateEnvironmentDto } from '../../application/dto/create-env.dto'
import { CreateDependencyDto } from 'src/dependency/dto/create-dependency.dto'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import {
ArrayMaxSize,
IsBoolean,
IsNotEmpty,
IsString,
Length,
MaxLength,
MinLength,
ValidateNested,
} from 'class-validator'
import { Type } from 'class-transformer'
Expand Down Expand Up @@ -43,6 +45,7 @@ export class UpdateFunctionTemplateDto {
@ApiPropertyOptional({ description: 'function template description' })
@IsString()
@MaxLength(256)
@MinLength(8)
description?: string

@ApiPropertyOptional({
Expand All @@ -51,6 +54,7 @@ export class UpdateFunctionTemplateDto {
})
@IsNotEmpty()
@ValidateNested({ each: true })
@ArrayMaxSize(20)
@Type(() => FunctionTemplateItemDto)
items: FunctionTemplateItemDto[]
}
47 changes: 47 additions & 0 deletions server/src/function-template/function-template.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ export class FunctionTemplateController {
if (!valid) {
return ResponseUtil.error('function template dependencies is invalid')
}

const counts =
await this.functionTemplateService.getCountOfFunctionTemplates(
req.user._id,
)

if (counts >= 100) {
return ResponseUtil.error('function template exceed the count limit')
}

const res = await this.functionTemplateService.createFunctionTemplate(
req.user._id,
dto,
Expand Down Expand Up @@ -331,6 +341,9 @@ export class FunctionTemplateController {
return ResponseUtil.ok(res)
}

/**
* stared function template
*/
if (type === 'stared' && keyword) {
asc = asc === 0 ? Number(asc) : 1
page = page ? Number(page) : 1
Expand Down Expand Up @@ -386,6 +399,9 @@ export class FunctionTemplateController {
return ResponseUtil.ok(res)
}

/**
* recent used function template
*/
if (type === 'recentUsed' && keyword) {
asc = asc === 0 ? Number(asc) : 1
page = page ? Number(page) : 1
Expand Down Expand Up @@ -443,6 +459,37 @@ export class FunctionTemplateController {
}
}

@ApiOperation({ summary: 'get all recommend function template' })
@ApiResponsePagination(FunctionTemplateSwagger)
@UseGuards(JwtAuthGuard)
@Get('recommend')
async getRecommendFunctionTemplate(
@Query('asc') asc: number,
@Query('page') page: number,
@Query('pageSize') pageSize: number,
@Query('keyword') keyword: string,
@Query('sort') sort: string,
) {
asc = asc === 0 ? Number(asc) : 1
page = page ? Number(page) : 1
pageSize = pageSize ? Number(pageSize) : 10

const condition = {
page,
pageSize,
asc,
hot: sort === 'hot',
name: keyword,
}

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

return ResponseUtil.ok(res)
}

@ApiOperation({ summary: 'get one function template' })
@ApiResponseArray(FunctionTemplateSwagger)
@UseGuards(JwtAuthGuard)
Expand Down
Loading

0 comments on commit 0808c6a

Please sign in to comment.