diff --git a/apps/api/package.json b/apps/api/package.json index da3a788d7..190aff24d 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -32,7 +32,8 @@ "class-validator": "^0.14.1", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", - "start": "^5.1.0" + "start": "^5.1.0", + "superagent": "^8.1.2" }, "devDependencies": { "@nestjs/cli": "^10.0.0", diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 20a209275..9a82c325f 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -4,6 +4,7 @@ import { UserModule } from '../user/user.module'; import { AuthModule } from '../auth/auth.module'; import { CourseModule } from '../course/course.module'; import { UserProgressModule } from '../user-progress/user-progress.module'; +import { ToolModule } from 'src/tool/tool.module'; @Module({ imports: [ @@ -12,6 +13,7 @@ import { UserProgressModule } from '../user-progress/user-progress.module'; AuthModule, CourseModule, UserProgressModule, + ToolModule, ], }) export class AppModule {} diff --git a/apps/api/src/tool/tool.controller.ts b/apps/api/src/tool/tool.controller.ts new file mode 100644 index 000000000..82a5bec77 --- /dev/null +++ b/apps/api/src/tool/tool.controller.ts @@ -0,0 +1,12 @@ +import { Controller, Get } from '@nestjs/common'; +import { ToolService } from './tool.service'; + +@Controller('tool') +export class ToolController { + constructor(private readonly toolService: ToolService) {} + + @Get('dailySentence') + dailySentence() { + return this.toolService.dailySentence(); + } +} diff --git a/apps/api/src/tool/tool.module.ts b/apps/api/src/tool/tool.module.ts new file mode 100644 index 000000000..ffcc93e48 --- /dev/null +++ b/apps/api/src/tool/tool.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { ToolService } from './tool.service'; +import { ToolController } from './tool.controller'; + +@Module({ + controllers: [ToolController], + providers: [ToolService], +}) +export class ToolModule {} diff --git a/apps/api/src/tool/tool.service.ts b/apps/api/src/tool/tool.service.ts new file mode 100644 index 000000000..40db804f3 --- /dev/null +++ b/apps/api/src/tool/tool.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +import * as superagent from 'superagent'; + +@Injectable() +export class ToolService { + async dailySentence() { + const { text } = await superagent.get( + 'https://open.iciba.com/dsapi/?date=2023-05-03', + ); + const data = JSON.parse(text); + const res = { + zh: data.note, + en: data.content, + }; + return res; + } +} diff --git a/apps/api/src/user-progress/model/update-user-progress.dto.ts b/apps/api/src/user-progress/model/user-progress.dto.ts similarity index 63% rename from apps/api/src/user-progress/model/update-user-progress.dto.ts rename to apps/api/src/user-progress/model/user-progress.dto.ts index a37b3a2cb..a4b64571a 100644 --- a/apps/api/src/user-progress/model/update-user-progress.dto.ts +++ b/apps/api/src/user-progress/model/user-progress.dto.ts @@ -6,3 +6,9 @@ export class CreateUserProgressDto { @IsNotEmpty({ message: '课程不能为空' }) courseId: number; } + +export class UpdateUserProgressDto { + @ApiProperty() + @IsNotEmpty({ message: '课程不能为空' }) + courseId: number; +} diff --git a/apps/api/src/user-progress/user-progress.controller.ts b/apps/api/src/user-progress/user-progress.controller.ts index 87443984b..ae4c179ec 100644 --- a/apps/api/src/user-progress/user-progress.controller.ts +++ b/apps/api/src/user-progress/user-progress.controller.ts @@ -6,11 +6,13 @@ import { Request, Get, Put, - Param, } from '@nestjs/common'; import { UserProgressService } from './user-progress.service'; import { AuthGuard } from '../auth/auth.guard'; -import { CreateUserProgressDto } from './model/update-user-progress.dto'; +import { + CreateUserProgressDto, + UpdateUserProgressDto, +} from './model/user-progress.dto'; @Controller('user-progress') export class UserProgressController { @@ -29,8 +31,8 @@ export class UserProgressController { } @UseGuards(AuthGuard) - @Put(':courseId') - updateOne(@Request() req, @Param('courseId') courseId: number) { - return this.userProgressService.update(+req.user.userId, +courseId); + @Put() + updateOne(@Request() req, @Body() dto: UpdateUserProgressDto) { + return this.userProgressService.update(+req.user.userId, +dto.courseId); } } diff --git a/apps/client/api/tool.ts b/apps/client/api/tool.ts new file mode 100644 index 000000000..2f57de24b --- /dev/null +++ b/apps/client/api/tool.ts @@ -0,0 +1,10 @@ +import { http } from "./http"; + +interface DailySentenceVo { + zh: string + en: string +} + +export async function fetchDailySentence() { + return await http.get("/tool/dailySentence"); +} diff --git a/apps/client/api/userProgress.ts b/apps/client/api/userProgress.ts new file mode 100644 index 000000000..fbfd3652a --- /dev/null +++ b/apps/client/api/userProgress.ts @@ -0,0 +1,17 @@ +import { http } from "./http"; + +interface UserProgressVo { + courseId: number +} + +interface UserProgressDto { + courseId: number +} + +export async function fetchUserProgress() { + return await http.get("/user-progress"); +} + +export async function fetchUpdateProgress(dto: UserProgressDto) { + return await http.put("/user-progress", dto); +} diff --git a/apps/client/components/main/Summary.vue b/apps/client/components/main/Summary.vue index 605c3f8d0..5c976eb1f 100644 --- a/apps/client/components/main/Summary.vue +++ b/apps/client/components/main/Summary.vue @@ -1,31 +1,76 @@