Skip to content

Commit

Permalink
Merge pull request #14 from ileostar/add-loading
Browse files Browse the repository at this point in the history
Add-loading
  • Loading branch information
ileostar authored Jan 20, 2024
2 parents 923a64a + d3de03b commit 7fec9e6
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 423 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiOperation, ApiTags } from '@nestjs/swagger'
import { AppService } from './app.service'
import { ResponseData } from './response/ResponseFormat'

@ApiTags('欢迎进入环创三轮🎉')
@ApiTags('A18-基于云计算平台构建智能温室种植平台🎉')
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Module } from '@nestjs/common'
import { TypeOrmModule } from '@nestjs/typeorm'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { ServeStaticModule } from '@nestjs/serve-static'
import loadConfig from './config/configurations'
import loadConfig from './config/dbconfig'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { UserModule } from './user/user.module'
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { AppModule } from './app.module'

function setupSwagger(app) {
const config = new DocumentBuilder()
.setTitle('前端三轮考核接口')
.setContact('考核题目链接☛', 'https://dkmjddbh0f.feishu.cn/docx/T7IAdyWpho6ZUhxkSuqciIj1nKQ?from=from_copylink', null)
.setDescription('师弟师妹们加油🦆~~~')
.setTitle('服创A18选题Nestjs API')
.setContact('选题链接☛', 'https://dkmjddbh0f.feishu.cn/docx/COSodlq6zopSwyxDg70chsdPnMg', null)
.setDescription('后端技术栈:Nestjs+TypeORM+Redis+Serverless')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, config)
Expand Down
55 changes: 10 additions & 45 deletions apps/server/src/user/dto/user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
import { ApiProperty } from '@nestjs/swagger'

export class CreateUserDto {
@ApiProperty({ description: '学生姓名' })
stuName: string
@ApiProperty({ description: '用户名' })
username: string

@ApiProperty({ description: '密码' })
password: string

@ApiProperty({ description: '校验密码' })
confirmPassword: string

@ApiProperty({ description: '学号' })
stuNum: number

@ApiProperty({ description: '性别' })
sex: string

@ApiProperty({ description: '年级' })
grade: number

@ApiProperty({ description: '邮箱' })
email: string
}

export class UserInfosDto {
@ApiProperty({ description: '学生姓名' })
stuName: string
@ApiProperty({ description: '用户名' })
username: string

@ApiProperty({ description: '学号' })
stuNum: number
@ApiProperty({ description: '头像信息' })
avatarUrl: string

@ApiProperty({ description: '性别' })
sex: string

@ApiProperty({ description: '年级' })
grade: number

@ApiProperty({ description: '邮箱' })
email: string
@ApiProperty({ description: '用户权限' })
auth: string
}

export class LoginDto {
@ApiProperty({ description: '学号' })
stuNum: number
@ApiProperty({ description: '用户名' })
username: string

@ApiProperty({ description: '密码' })
password: string
Expand All @@ -52,20 +34,3 @@ export class LoginRes {
@ApiProperty({ description: '认证Token' })
token: string
}

export class PagingUserData {
@ApiProperty({ description: '分页数据' })
usersData: Array<unknown>

@ApiProperty({ description: '分页总页' })
pageTotals: number

@ApiProperty({ description: '当前页面' })
pageNum: number

@ApiProperty({ description: '每一页页面条数' })
pageCount: number

@ApiProperty({ description: '数据信息条数' })
totalCount: number
}
35 changes: 12 additions & 23 deletions apps/server/src/user/models/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,31 @@ export class User {
id: string

@Column({
comment: '学生姓名',
comment: '用户名',
length: 100,
default: '',
})
@IsNotEmpty()
username: string

@Column({
comment: '学号',
type: 'bigint',
})
student_number: number

@Column({
comment: '密码',
})
password: string

@Column({
comment: '邮箱',
comment: '头像地址',
length: 100,
default: '',
default: 'https://cdn.jsdelivr.net/gh/ileostar/picx-images@master/20240120/leostar-profile.1aheunrxjl9c.avif',
})
email: string
avatarUrl: string

@Column({
comment: '性别',
length: 2,
default: '男',
})
sex: string

@Column({
comment: '年级',
comment: '用户权限',
length: 100,
default: '0',
})
grade: number
auth: string

@Column({
name: 'create_time',
Expand All @@ -61,10 +50,10 @@ export class User {

/**
* 插入密码前加密
* @return {void}
* @return {void}
*/
@BeforeInsert()
async encryptPwd() {
@BeforeInsert()
async encryptPwd() {
this.password = await bcrypt.hashSync(this.password)
}
}
}
105 changes: 8 additions & 97 deletions apps/server/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,132 +2,43 @@ import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common'
import { ApiBody, ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'
import { APIResponse } from 'src/response/ApiResponse'
import { ResponseData } from 'src/response/ResponseFormat'
import { CreateUserDto, LoginDto, LoginRes, PagingUserData, UserInfosDto } from './dto/user.dto'
import { CreateUserDto, LoginDto, LoginRes, UserInfosDto } from './dto/user.dto'
import { UserService } from './user.service'

@ApiTags('下面是需要用到的接口😀')
@ApiTags('web前台用户模块😀')
@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}

@Post('register')
@ApiBody({ type: CreateUserDto })
@APIResponse()
@ApiOperation({ summary: '用于注册用户', description: '需要输入学生姓名、密码、确认密码、学号、性别、年级、邮箱' })
@ApiOperation({ summary: '用于注册用户', description: '需要输入用户名、密码、确认密码' })
async registerUser(@Body() CreateUserDto: CreateUserDto) {
const res = await this.userService.createUser(CreateUserDto)
if (res === '注册成功')
return ResponseData.ok(null, res)
if (res === '注册成功')
return ResponseData.ok(null, res)
else
return ResponseData.fail(res, 40001)
}

@Post('login')
@APIResponse(LoginRes)
@ApiOperation({ summary: '用于登录', description: '使用学号和密码登录(返回的Token添加在请求头Header中)' })
@ApiOperation({ summary: '用于登录', description: '使用用户名和密码登录(返回的Token添加在请求头Header中)' })
async loginUser(@Body() loginDto: LoginDto) {
const res = await this.userService.login(loginDto)
if (res === '用户不存在' || res === '密码不正确' || res === '密码格式不对')
return ResponseData.fail(res, 40001)
else
else
return ResponseData.ok({ token: res }, '登陆成功')
}

@Get('findAllPaging')
@ApiQuery({
name: 'pageNum',
description: '每页条数',
required: true,
})
@ApiQuery({
name: 'pageCount',
description: '当前页数',
required: true,
})
@ApiOperation({ summary: '查询所有学生信息(分页版)', description: '这里需要做一个分页,请传入pageNum每页页数,pageCount当前页数' })
@APIResponse(PagingUserData)
async findAllPaging(
@Query('pageNum') pageNum: number,
@Query('pageCount') pageCount: number,
): Promise<ResponseData<PagingUserData>> {
if (!pageNum || !pageCount)
return ResponseData.ok(null, '参数传递错误')

const res = await this.userService.findAllPaging(pageNum, pageCount)
let msg = '查询成功'
if (res.totalCount === 0)
msg = '查询结果为空'

return ResponseData.ok(res, msg)
}


@Get('findAll')
@ApiOperation({ summary: '查询所有学生信息', description: '这里直接查询所有,用于数据可视化展示' })
@ApiOperation({ summary: '查询所有学生信息', description: '查询所有学生信息' })
@APIResponse([UserInfosDto])
async findAll(): Promise<ResponseData<Array<UserInfosDto>>> {
const res = await this.userService.findAll()
return ResponseData.ok(res, '查询成功')
}

@Get('findByStuNum')
@ApiQuery({
name: 'stuNum',
description: '学号',
required: true,
})
@APIResponse(UserInfosDto)
@ApiOperation({ summary: '根据学号查找学生信息', description: '学号不会重复,所以只返回一条信息' })
async findByStuNum(
@Query('stuNum') stuNum: number,
) {
if (!stuNum)
return ResponseData.ok(null, '参数传递错误')
const res = await this.userService.findByStuNum(stuNum)
const dto = new UserInfosDto()
let msg = '查询结果为空'
if (res) {
dto.email = res.email
dto.stuNum = res.student_number
dto.stuName = res.username
dto.grade = res.grade
dto.sex = res.sex
msg = '查询成功'
}
return ResponseData.ok(dto, msg)
}

@Get('findByStuName')
@ApiQuery({
name: 'stuName',
description: '学生姓名',
required: true,
})
@ApiQuery({
name: 'pageNum',
description: '每页条数',
required: true,
})
@ApiQuery({
name: 'pageCount',
description: '当前页数',
required: true,
})
@APIResponse(PagingUserData)
@ApiOperation({ summary: '根据学生姓名查找学生信息', description: '姓名可能会有重复的,所以会有分页' })
async findByStuName(
@Query('stuName') username: string,
@Query('pageNum') pageNum: number,
@Query('pageCount') pageCount: number,
): Promise<ResponseData<PagingUserData>> {
if (!username || !pageNum || !pageCount)
return ResponseData.ok(null, '参数传递错误')
const res = await this.userService.findByName(username, pageNum, pageCount)
let msg = '查询成功'
if (res.totalCount === 0)
msg = '查询结果为空'


return ResponseData.ok(res, msg)
}
}
Loading

0 comments on commit 7fec9e6

Please sign in to comment.