From 5292366899e5dc32f31e1c607ecf0703c5033a1d Mon Sep 17 00:00:00 2001 From: LingandRX Date: Wed, 14 May 2025 21:17:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(controller):=20=E6=96=B0=E5=A2=9E=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E6=8E=A7=E5=88=B6=E5=99=A8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 CategoryController、CollectionController、CommentController 等多个控制器类 - 实现了分类、收藏、评论、消息等功能的接口 - 优化了部分方法名称,提高了代码可读性 --- gradlew | 8 +- gradlew.bat | 22 ++-- .../controller/CategoryController.java | 89 +++++++++++++ .../controller/CollectionController.java | 86 ++++++++++++ .../controller/CollectionNoteController.java | 9 ++ .../controller/CommentController.java | 105 +++++++++++++++ .../controller/EmailController.java | 36 ++++++ .../controller/MessageController.java | 88 +++++++++++++ .../controller/NoteController.java | 122 ++++++++++++++++++ .../controller/NoteLikeController.java | 28 ++++ .../controller/NotificationController.java | 40 ++++++ .../controller/QuestionController.java | 117 +++++++++++++++++ .../controller/QuestionListController.java | 89 +++++++++++++ .../QuestionListItemController.java | 94 ++++++++++++++ .../controller/SearchController.java | 44 +++++++ .../controller/StatisticController.java | 27 ++++ .../controller/TestController.java | 29 +++++ .../controller/UploadController.java | 30 +++++ .../service/CollectionService.java | 2 +- .../copykamanotes/service/NoteService.java | 2 +- .../service/QuestionListItemService.java | 2 +- .../service/QuestionService.java | 2 +- .../copykamanotes/service/SearchService.java | 2 +- .../service/StatisticService.java | 2 +- .../service/impl/CollectionServiceImpl.java | 2 +- .../service/impl/NoteServiceImpl.java | 2 +- .../impl/QuestionListItemServiceImpl.java | 2 +- .../service/impl/QuestionServiceImpl.java | 2 +- .../service/impl/SearchServiceImpl.java | 2 +- .../service/impl/StatisticServiceImpl.java | 2 +- .../service/impl/UserServiceImpl.java | 22 ++-- 31 files changed, 1072 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/example/copykamanotes/controller/CategoryController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/CollectionController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/CollectionNoteController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/CommentController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/EmailController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/MessageController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/NoteController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/NoteLikeController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/NotificationController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/QuestionController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/QuestionListController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/QuestionListItemController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/SearchController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/StatisticController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/TestController.java create mode 100644 src/main/java/com/example/copykamanotes/controller/UploadController.java diff --git a/gradlew b/gradlew index 1aa94a4..faf9300 100644 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -84,7 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -203,7 +205,7 @@ fi DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/src/main/java/com/example/copykamanotes/controller/CategoryController.java b/src/main/java/com/example/copykamanotes/controller/CategoryController.java new file mode 100644 index 0000000..b7de6ac --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/CategoryController.java @@ -0,0 +1,89 @@ +package com.example.copykamanotes.controller; + +import java.util.List; + +import javax.validation.Valid; +import javax.validation.constraints.Min; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.category.CreateCategoryBody; +import com.example.copykamanotes.model.dto.category.UpdateCategoryBody; +import com.example.copykamanotes.model.vo.category.CategoryVO; +import com.example.copykamanotes.model.vo.category.CreateCategoryVO; +import com.example.copykamanotes.service.CategoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class CategoryController { + + @Autowired + private CategoryService categoryService; + + /** + * 获取分类列表(用户端)。 + * + * @return 包含分类列表的响应。 + */ + @GetMapping("/categories") + public ApiResponse> userCategories() { + return categoryService.categoryList(); + } + + /** + * 获取分类列表(管理员端)。 + * + * @return 包含分类列表的响应。 + */ + @GetMapping("/admin/categories") + public ApiResponse> categories() { + return categoryService.categoryList(); + } + + /** + * 创建新的分类。 + * + * @param createCategoryBody 包含分类创建信息的请求体。 + * @return 包含创建成功的分类信息的响应。 + */ + @PostMapping("/admin/categories") + public ApiResponse createCategory( + @Valid @RequestBody CreateCategoryBody createCategoryBody) { + return categoryService.createCategory(createCategoryBody); + } + + /** + * 更新指定的分类信息。 + * + * @param categoryId 分类ID,必须为正整数。 + * @param updateCategoryBody 包含更新信息的请求体。 + * @return 包含更新操作结果的响应。 + */ + @PatchMapping("/admin/categories/{categoryId}") + public ApiResponse updateCategory( + @Min(value = 1, message = "categoryId 必须为正整数") @PathVariable Integer categoryId, + @Valid @RequestBody UpdateCategoryBody updateCategoryBody) { + return categoryService.updateCategory(categoryId, updateCategoryBody); + } + + /** + * 删除指定的分类。 + * + * @param categoryId 分类ID,必须为正整数。 + * @return 包含删除操作结果的响应。 + */ + @DeleteMapping("/admin/categories/{categoryId}") + public ApiResponse deleteCategory( + @Min(value = 1, message = "categoryId 必须为正整数") @PathVariable Integer categoryId) { + return categoryService.deleteCategory(categoryId); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/CollectionController.java b/src/main/java/com/example/copykamanotes/controller/CollectionController.java new file mode 100644 index 0000000..e9ff25b --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/CollectionController.java @@ -0,0 +1,86 @@ +package com.example.copykamanotes.controller; + +import java.util.List; + +import javax.validation.Valid; +import javax.validation.constraints.Min; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.collection.CollectionQueryParams; +import com.example.copykamanotes.model.dto.collection.CreateCollectionBody; +import com.example.copykamanotes.model.dto.collection.UpdateCollectionBody; +import com.example.copykamanotes.model.vo.collection.CollectionVO; +import com.example.copykamanotes.model.vo.collection.CreateCollectionVO; +import com.example.copykamanotes.service.CollectionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class CollectionController { + + @Autowired + private CollectionService collectionService; + + /** + * 获取收藏夹列表接口 + * + * @param queryParams 查询参数 + * @return 收藏夹列表 + */ + @GetMapping("/collections") + public ApiResponse> getCollections( + @Valid + CollectionQueryParams queryParams) { + return collectionService.getCollections(queryParams); + } + + /** + * 创建收藏夹接口 + * + * @param requestBody 创建收藏夹请求体 + * @return 创建结果,如果成功则包含收藏夹 ID + */ + @PostMapping("/collections") + public ApiResponse createCollection( + @Valid + @RequestBody + CreateCollectionBody requestBody) { + return collectionService.createCollection(requestBody); + } + + /** + * 删除收藏夹接口 + * + * @param collectionId 收藏夹 ID + * @return 返回删除结果 + */ + @DeleteMapping("/collections/{collectionId}") + public ApiResponse deleteCollection( + @PathVariable + @Min(value = 1, message = "collectionId 必须为正整数") + Integer collectionId) { + return collectionService.deleteCollection(collectionId); + } + + /** + * 批量修改收藏夹接口 + * + * @param collectionBody 收藏夹 ID + * @return 返回修改结果 + */ + @PostMapping("/collections/batch") + public ApiResponse batchModifyCollection( + @Valid + @RequestBody + UpdateCollectionBody collectionBody) { + return collectionService.batchModifyCollection(collectionBody); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/CollectionNoteController.java b/src/main/java/com/example/copykamanotes/controller/CollectionNoteController.java new file mode 100644 index 0000000..2b6e8e6 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/CollectionNoteController.java @@ -0,0 +1,9 @@ +package com.example.copykamanotes.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class CollectionNoteController { +} diff --git a/src/main/java/com/example/copykamanotes/controller/CommentController.java b/src/main/java/com/example/copykamanotes/controller/CommentController.java new file mode 100644 index 0000000..d92bccd --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/CommentController.java @@ -0,0 +1,105 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.comment.CommentQueryParams; +import com.example.copykamanotes.model.dto.comment.CreateCommentRequest; +import com.example.copykamanotes.model.dto.comment.UpdateCommentRequest; +import com.example.copykamanotes.model.vo.comment.CommentVO; +import com.example.copykamanotes.service.CommentService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +/** + * 评论控制器 + */ +@Slf4j +@RestController +@RequestMapping("/api") +public class CommentController { + + @Autowired + private CommentService commentService; + + /** + * 创建评论 + * + * @param request 创建评论请求 + * @return 创建的评论ID + */ + @PostMapping("/comments") + public ApiResponse createComment( + @Valid + @RequestBody + CreateCommentRequest request) { + return commentService.createComment(request); + } + + /** + * 更新评论 + * + * @param commentId 评论ID + * @param request 更新评论请求 + * @return 空响应 + */ + @PatchMapping("/comments/{commentId}") + public ApiResponse updateComment( + @PathVariable("commentId") Integer commentId, + @Valid + @RequestBody + UpdateCommentRequest request) { + return commentService.updateComment(commentId, request); + } + + /** + * 删除评论 + * + * @param commentId 评论ID + * @return 空响应 + */ + @DeleteMapping("/comments/{commentId}") + public ApiResponse deleteComment( + @PathVariable("commentId") Integer commentId) { + return commentService.deleteComment(commentId); + } + + /** + * 获取评论列表 + * + * @param params 查询参数 + * @return 评论列表 + */ + @GetMapping("/comments") + public ApiResponse> getComments( + @Valid CommentQueryParams params) { + return commentService.getComments(params); + } + + /** + * 点赞评论 + * + * @param commentId 评论ID + * @return 空响应 + */ + @PostMapping("/comments/{commentId}/like") + public ApiResponse likeComment( + @PathVariable("commentId") Integer commentId) { + return commentService.likeComment(commentId); + } + + /** + * 取消点赞评论 + * + * @param commentId 评论ID + * @return 空响应 + */ + @DeleteMapping("/comments/{commentId}/like") + public ApiResponse unlikeComment( + @PathVariable("commentId") Integer commentId) { + return commentService.unlikeComment(commentId); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/copykamanotes/controller/EmailController.java b/src/main/java/com/example/copykamanotes/controller/EmailController.java new file mode 100644 index 0000000..b76eb5c --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/EmailController.java @@ -0,0 +1,36 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.service.EmailService; +import com.example.copykamanotes.utils.ApiResponseUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; + +@RestController +@RequestMapping("/api/email") +@RequiredArgsConstructor +public class EmailController { + + private final EmailService emailService; + + @GetMapping("/verify-code") + public ApiResponse sendVerifyCode( + @RequestParam @NotBlank @Email String email, + @RequestParam @NotBlank String type) { + + // 检查是否可以发送 + if (!emailService.canSendCode(email)) { + return ApiResponseUtils.error("发送太频繁,请稍后再试"); + } + + try { + emailService.sendVerifyCode(email, type); + return ApiResponseUtils.success(null); + } catch (Exception e) { + return ApiResponseUtils.error(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/copykamanotes/controller/MessageController.java b/src/main/java/com/example/copykamanotes/controller/MessageController.java new file mode 100644 index 0000000..c0b2c47 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/MessageController.java @@ -0,0 +1,88 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.base.PageVO; +import com.example.copykamanotes.model.dto.message.MessageQueryParams; +import com.example.copykamanotes.model.vo.message.MessageVO; +import com.example.copykamanotes.model.vo.message.UnreadCountByType; +import com.example.copykamanotes.service.MessageService; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 消息控制器 + */ +@RestController +@RequestMapping("/api/messages") +@RequiredArgsConstructor +public class MessageController { + + private final MessageService messageService; + + /** + * 获取消息列表 + * + * @param params 查询参数 + * @return 消息列表,带分页信息 + */ + @GetMapping + public ApiResponse> getMessages(@Validated MessageQueryParams params) { + return messageService.getMessages(params); + } + + /** + * 标记消息为已读 + * + * @param messageId 消息ID + * @return 空响应 + */ + @PutMapping("/{messageId}/read") + public ApiResponse markAsRead(@PathVariable Integer messageId) { + return messageService.markAsRead(messageId); + } + + /** + * 标记所有消息为已读 + * + * @return 空响应 + */ + @PutMapping("/read/all") + public ApiResponse markAllAsRead() { + return messageService.markAllAsRead(); + } + + /** + * 删除消息 + * + * @param messageId 消息ID + * @return 空响应 + */ + @DeleteMapping("/{messageId}") + public ApiResponse deleteMessage(@PathVariable Integer messageId) { + return messageService.deleteMessage(messageId); + } + + /** + * 获取未读消息数量 + * + * @return 未读消息数量 + */ + @GetMapping("/unread/count") + public ApiResponse getUnreadCount() { + return messageService.getUnreadCount(); + } + + /** + * 获取各类型未读消息数量 + * + * @return 各类型未读消息数量 + */ + @GetMapping("/unread/count/type") + public ApiResponse> getUnreadCountByType() { + return messageService.getUnreadCountByType(); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/copykamanotes/controller/NoteController.java b/src/main/java/com/example/copykamanotes/controller/NoteController.java new file mode 100644 index 0000000..45fc792 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/NoteController.java @@ -0,0 +1,122 @@ +package com.example.copykamanotes.controller; + +import java.util.List; + +import javax.validation.Valid; +import javax.validation.constraints.Min; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.note.CreateNoteRequest; +import com.example.copykamanotes.model.dto.note.NoteQueryParams; +import com.example.copykamanotes.model.dto.note.UpdateNoteRequest; +import com.example.copykamanotes.model.vo.note.*; +import com.example.copykamanotes.service.NoteService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import lombok.extern.log4j.Log4j2; + +/** + * 笔记控制器 + */ +@Log4j2 +@RestController +@RequestMapping("/api") +public class NoteController { + + // 自动注入 NoteService 实例,用于处理笔记相关的业务逻辑 + @Autowired + private NoteService noteService; + + /** + * 查询笔记列表 + * + * @param params 查询参数对象,包含筛选条件 + * @return 返回一个包含笔记列表的 ApiResponse 对象 + */ + @GetMapping("/notes") + public ApiResponse> getNotes( + @Valid NoteQueryParams params) { + return noteService.getNotes(params); + } + + /** + * 发布笔记 + * + * @param request 创建笔记的请求对象,包含笔记的内容等信息 + * @return 返回一个包含新创建笔记信息的 ApiResponse 对象 + */ + @PostMapping("/notes") + public ApiResponse createNote( + @Valid @RequestBody CreateNoteRequest request) { + return noteService.createNote(request); + } + + /** + * 更新笔记 + * + * @param noteId 笔记的唯一标识符,用于定位要更新的笔记 + * @param request 更新笔记的请求对象,包含需要修改的信息 + * @return 返回一个包含更新后笔记信息的 ApiResponse 对象 + */ + @PatchMapping("/notes/{noteId}") + public ApiResponse updateNote( + @Min(value = 1, message = "noteId 必须为正整数") @PathVariable Integer noteId, + @Valid @RequestBody UpdateNoteRequest request) { + return noteService.updateNote(noteId, request); + } + + /** + * 删除笔记 + * + * @param noteId 笔记的唯一标识符,用于定位要删除的笔记 + * @return 返回一个包含删除结果信息的 ApiResponse 对象 + */ + @DeleteMapping("/notes/{noteId}") + public ApiResponse deleteNote( + @Min(value = 1, message = "noteId 必须为正整数") + @PathVariable Integer noteId) { + return noteService.deleteNote(noteId); + } + + /** + * 下载笔记 + * @return + */ + @GetMapping("/notes/download") + public ApiResponse downloadNote() { + return noteService.downloadNote(); + } + + /** + * 提交笔记排行榜 + */ + @GetMapping("/notes/ranklist") + public ApiResponse> submitNoteRank() { + return noteService.submitNoteRank(); + } + + /** + * 用户提交热力图 + */ + @GetMapping("/notes/heatmap") + public ApiResponse> submitNoteHeatMap() { + return noteService.submitNoteHeatMap(); + } + + /** + * 用户提交 top3 count + */ + @GetMapping("/notes/top3count") + public ApiResponse submitNoteTop3Count() { + return noteService.submitNoteTop3Count(); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/NoteLikeController.java b/src/main/java/com/example/copykamanotes/controller/NoteLikeController.java new file mode 100644 index 0000000..aebe63c --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/NoteLikeController.java @@ -0,0 +1,28 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.service.NoteLikeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class NoteLikeController { + @Autowired + private NoteLikeService noteLikeService; + + @PostMapping("/like/note/{noteId}") + public ApiResponse likeNote(@PathVariable Integer noteId) { + return noteLikeService.likeNote(noteId); + } + + @DeleteMapping("/like/note/{noteId}") + public ApiResponse unlikeNote(@PathVariable Integer noteId) { + return noteLikeService.unlikeNote(noteId); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/NotificationController.java b/src/main/java/com/example/copykamanotes/controller/NotificationController.java new file mode 100644 index 0000000..ef11e2c --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/NotificationController.java @@ -0,0 +1,40 @@ +package com.example.copykamanotes.controller; + +import javax.validation.Valid; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.notification.NotificationDTO; +import com.example.copykamanotes.model.vo.notification.NotificationVO; +import com.example.copykamanotes.service.RedisService; +import com.example.copykamanotes.utils.ApiResponseUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class NotificationController { + + // 由于比较简单,直接全写在 controller 内了,免得出现透传 + @Autowired + private RedisService redisService; + + @GetMapping("/notification") + public ApiResponse getNotifications() { + NotificationVO notificationVO = new NotificationVO(); + Object o = redisService.get("kamanote:notification"); + String content = o == null ? "" : o.toString(); + notificationVO.setContent(content); + return ApiResponseUtils.success("获取通知成功", notificationVO); + } + + @PostMapping("/notification") + public ApiResponse setNotifications(@Valid @RequestBody NotificationDTO notificationDTO) { + redisService.set("kamanote:notification", notificationDTO.getContent()); + return ApiResponseUtils.success("设置通知成功"); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/QuestionController.java b/src/main/java/com/example/copykamanotes/controller/QuestionController.java new file mode 100644 index 0000000..5ca876d --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/QuestionController.java @@ -0,0 +1,117 @@ +package com.example.copykamanotes.controller; + +import java.util.List; + +import javax.validation.Valid; +import javax.validation.constraints.Min; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.question.CreateQuestionBody; +import com.example.copykamanotes.model.dto.question.QuestionQueryParam; +import com.example.copykamanotes.model.dto.question.SearchQuestionBody; +import com.example.copykamanotes.model.dto.question.UpdateQuestionBody; +import com.example.copykamanotes.model.vo.question.CreateQuestionVO; +import com.example.copykamanotes.model.vo.question.QuestionNoteVO; +import com.example.copykamanotes.model.vo.question.QuestionUserVO; +import com.example.copykamanotes.model.vo.question.QuestionVO; +import com.example.copykamanotes.service.QuestionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class QuestionController { + + @Autowired + private QuestionService questionService; + + /** + * 用户端获取问题列表 + * + * @param queryParams 查询参数,用于过滤问题列表(如关键词、分类等) + * @return 包含用户可见问题的视图对象列表的响应 + */ + @GetMapping("/questions") + public ApiResponse> userGetQuestions(@Valid QuestionQueryParam queryParams) { + return questionService.userGetQuestions(queryParams); + } + + /** + * 用户端搜索问题 + * + * @param body 包含搜索关键词的请求体 + * @return 包含搜索结果的视图对象列表的响应 + */ + @PostMapping("/questions/search") + public ApiResponse> searchQuestions(@Valid @RequestBody SearchQuestionBody body) { + return questionService.searchQuestions(body); + } + + /** + * 用户端获取单个问题详情 + * + * @param questionId 问题ID,必须为正整数 + * @return 包含问题详情及关联笔记的视图对象的响应 + */ + @GetMapping("/questions/{questionId}") + public ApiResponse userGetQuestion(@Min(value = 1, message = "questionId 必须为正整数") + @PathVariable Integer questionId) { + return questionService.userGetQuestion(questionId); + } + + /** + * 管理端获取问题列表 + * + * @param queryParams 查询参数,用于过滤问题列表(如关键词、时间范围等) + * @return 包含所有问题的视图对象列表的响应 + */ + @GetMapping("/admin/questions") + public ApiResponse> getQuestions(@Valid QuestionQueryParam queryParams) { + return questionService.getQuestions(queryParams); + } + + /** + * 管理端创建新问题 + * + * @param createQuestionBody 创建问题的请求体,包含问题的标题、内容等信息 + * @return 包含新创建问题视图对象的响应 + */ + @PostMapping("/admin/questions") + public ApiResponse createQuestion(@Valid @RequestBody CreateQuestionBody createQuestionBody) { + return questionService.createQuestion(createQuestionBody); + } + + /** + * 管理端更新问题 + * + * @param questionId 问题ID,必须为正整数 + * @param updateQuestionBody 更新问题的请求体,包含要更新的字段和值 + * @return 空视图对象的响应,表示更新操作成功 + */ + @PatchMapping("/admin/questions/{questionId}") + public ApiResponse updateQuestion(@Min(value = 1, message = "questionId 必须为正整数") + @PathVariable Integer questionId, + @Valid @RequestBody UpdateQuestionBody updateQuestionBody) { + return questionService.updateQuestion(questionId, updateQuestionBody); + } + + /** + * 管理端删除问题 + * + * @param questionId 问题ID,必须为正整数 + * @return 空视图对象的响应,表示删除操作成功 + */ + @DeleteMapping("/admin/questions/{questionId}") + public ApiResponse deleteQuestion(@Min(value = 1, message = "questionId 必须为正整数") + @PathVariable Integer questionId) { + return questionService.deleteQuestion(questionId); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/QuestionListController.java b/src/main/java/com/example/copykamanotes/controller/QuestionListController.java new file mode 100644 index 0000000..3d7b549 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/QuestionListController.java @@ -0,0 +1,89 @@ +package com.example.copykamanotes.controller; + +import java.util.List; + +import javax.validation.Valid; +import javax.validation.constraints.Min; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.questionList.CreateQuestionListBody; +import com.example.copykamanotes.model.dto.questionList.UpdateQuestionListBody; +import com.example.copykamanotes.model.entity.QuestionList; +import com.example.copykamanotes.model.vo.questionList.CreateQuestionListVO; +import com.example.copykamanotes.service.QuestionListService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class QuestionListController { + + @Autowired + private QuestionListService questionListService; + + /** + * 获取题单。 + * + * @return 包含题单列表的响应。 + */ + @GetMapping("/admin/questionlists/{questionListId}") + public ApiResponse getQuestionList(@Min(value = 1, message = "questionListId 必须为正整数") + @PathVariable Integer questionListId) { + return questionListService.getQuestionList(questionListId); + } + + /** + * 获取题单列表。 + * + * @return 包含题单列表的响应。 + */ + @GetMapping("/admin/questionlists") + public ApiResponse> getQuestionLists() { + return questionListService.getQuestionLists(); + } + + /** + * 创建新的题单。 + * + * @param body 包含题单创建信息的请求体。 + * @return 包含创建成功的题单信息的响应。 + */ + @PostMapping("/admin/questionlists") + public ApiResponse createQuestionList(@Valid @RequestBody CreateQuestionListBody body) { + return questionListService.createQuestionList(body); + } + + /** + * 删除指定的题单。 + * + * @param questionListId 要删除的题单ID,必须为正整数。 + * @return 包含删除操作结果的响应。 + */ + @DeleteMapping("/admin/questionlists/{questionListId}") + public ApiResponse deleteQuestionList(@Min(value = 1, message = "questionListId 必须为正整数") + @PathVariable Integer questionListId) { + return questionListService.deleteQuestionList(questionListId); + } + + /** + * 更新指定的题单信息。 + * + * @param questionListId 要更新的题单ID,必须为正整数。 + * @param body 包含更新信息的请求体。 + * @return 包含更新操作结果的响应。 + */ + @PatchMapping("/admin/questionlists/{questionListId}") + public ApiResponse updateQuestionList(@Min(value = 1, message = "questionListId 必须为正整数") + @PathVariable Integer questionListId, + @Valid @RequestBody UpdateQuestionListBody body) { + return questionListService.updateQuestionList(questionListId, body); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/QuestionListItemController.java b/src/main/java/com/example/copykamanotes/controller/QuestionListItemController.java new file mode 100644 index 0000000..2b9269c --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/QuestionListItemController.java @@ -0,0 +1,94 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.base.EmptyVO; +import com.example.copykamanotes.model.dto.questionListItem.CreateQuestionListItemBody; +import com.example.copykamanotes.model.dto.questionListItem.QuestionListItemQueryParams; +import com.example.copykamanotes.model.dto.questionListItem.SortQuestionListItemBody; +import com.example.copykamanotes.model.vo.questionListItem.CreateQuestionListItemVO; +import com.example.copykamanotes.model.vo.questionListItem.QuestionListItemUserVO; +import com.example.copykamanotes.model.vo.questionListItem.QuestionListItemVO; +import com.example.copykamanotes.service.QuestionListItemService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import javax.validation.constraints.Min; +import java.util.List; + +@RestController +@RequestMapping("/api") +public class QuestionListItemController { + + @Autowired + private QuestionListItemService questionListItemService; + + /** + * 获取指定题单中的题单项列表(用户端)。 + * + * @param queryParams 查询参数 + * @return 包含题单项列表的响应。 + */ + @GetMapping("/questionlist-items") + public ApiResponse> userGetQuestionListItems( + @Valid QuestionListItemQueryParams queryParams) { + return questionListItemService.userGetQuestionListItems(queryParams); + } + + /** + * 获取指定题单中的题单项列表(管理端)。 + * + * @param questionListId 题单ID,可选参数,若提供则获取指定题单的题单项。 + * @return 包含题单项列表的响应。 + */ + @GetMapping("/admin/questionlist-items/{questionListId}") + public ApiResponse> getQuestionListItems( + @Min(value = 1, message = "questionListId 必须为正整数") + @PathVariable Integer questionListId) { + return questionListItemService.getQuestionListItems(questionListId); + } + + /** + * 创建新的题单项。 + * + * @param body 包含题单项创建信息的请求体。 + * @return 包含创建成功的题单项信息的响应。 + */ + @PostMapping("/admin/questionlist-items") + public ApiResponse createQuestionListItem( + @Valid + @RequestBody + CreateQuestionListItemBody body) { + return questionListItemService.createQuestionListItem(body); + } + + /** + * 删除指定的题单项。 + * + * @param questionListId 题单ID,必须为正整数。 + * @param questionId 题目ID,必须为正整数。 + * @return 包含删除操作结果的响应。 + */ + @DeleteMapping("/admin/questionlist-items/{questionListId}/{questionId}") + public ApiResponse deleteQuestionListItem( + @Min(value = 1, message = "questionListId 必须为正整数") + @PathVariable Integer questionListId, + @Min(value = 1, message = "questionId 必须为正整数") + @PathVariable Integer questionId) { + return questionListItemService.deleteQuestionListItem(questionListId, questionId); + } + + /** + * 更新题单项的排序。 + * + * @param body 包含题单项排序信息的请求体。 + * @return 包含更新操作结果的响应。 + */ + @PatchMapping("/admin/questionlist-items/sort") + public ApiResponse sortQuestionListItem( + @Valid + @RequestBody + SortQuestionListItemBody body) { + return questionListItemService.sortQuestionListItem(body); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/SearchController.java b/src/main/java/com/example/copykamanotes/controller/SearchController.java new file mode 100644 index 0000000..6ec71d4 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/SearchController.java @@ -0,0 +1,44 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.entity.Note; +import com.example.copykamanotes.model.entity.User; +import com.example.copykamanotes.service.SearchService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import javax.validation.constraints.Min; +import java.util.List; + +@RestController +@RequestMapping("/api/search") +@RequiredArgsConstructor +public class SearchController { + + private final SearchService searchService; + + @GetMapping("/notes") + public ApiResponse> searchNotes( + @RequestParam String keyword, + @RequestParam(defaultValue = "1") @Min(1) Integer page, + @RequestParam(defaultValue = "20") @Min(1) Integer pageSize) { + return searchService.searchNotes(keyword, page, pageSize); + } + + @GetMapping("/users") + public ApiResponse> searchUsers( + @RequestParam String keyword, + @RequestParam(defaultValue = "1") @Min(1) Integer page, + @RequestParam(defaultValue = "20") @Min(1) Integer pageSize) { + return searchService.searchUsers(keyword, page, pageSize); + } + + @GetMapping("/notes/tag") + public ApiResponse> searchNotesByTag( + @RequestParam String keyword, + @RequestParam String tag, + @RequestParam(defaultValue = "1") @Min(1) Integer page, + @RequestParam(defaultValue = "20") @Min(1) Integer pageSize) { + return searchService.searchNotesByTag(keyword, tag, page, pageSize); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/copykamanotes/controller/StatisticController.java b/src/main/java/com/example/copykamanotes/controller/StatisticController.java new file mode 100644 index 0000000..507ed60 --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/StatisticController.java @@ -0,0 +1,27 @@ +package com.example.copykamanotes.controller; + +import java.util.List; + +import javax.validation.Valid; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.dto.statistic.StatisticQueryParam; +import com.example.copykamanotes.model.entity.Statistic; +import com.example.copykamanotes.service.StatisticService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class StatisticController { + + @Autowired + StatisticService statisticService; + + @GetMapping("/statistic") + public ApiResponse> getStatistic(@Valid StatisticQueryParam queryParam) { + return statisticService.getStatistic(queryParam); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/TestController.java b/src/main/java/com/example/copykamanotes/controller/TestController.java new file mode 100644 index 0000000..0efb0ba --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/TestController.java @@ -0,0 +1,29 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.scope.RequestScopeData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class TestController { + + @Autowired + private RequestScopeData requestScopeData; + + @GetMapping("/hello") + public String hello() { + + System.out.println("get data in /test/hello"); + System.out.println(requestScopeData.getUserId()); + System.out.println(requestScopeData.getToken()); + return "Hello World!"; + } + + @GetMapping("/exception") + public String exception() { + throw new RuntimeException("test exception"); + } +} diff --git a/src/main/java/com/example/copykamanotes/controller/UploadController.java b/src/main/java/com/example/copykamanotes/controller/UploadController.java new file mode 100644 index 0000000..6c177dd --- /dev/null +++ b/src/main/java/com/example/copykamanotes/controller/UploadController.java @@ -0,0 +1,30 @@ +package com.example.copykamanotes.controller; + +import com.example.copykamanotes.model.base.ApiResponse; +import com.example.copykamanotes.model.vo.upload.ImageVO; +import com.example.copykamanotes.service.UploadService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +/** + * 文件上传控制器 + */ +@RestController +@RequestMapping("/api") +public class UploadController { + + @Autowired + private UploadService uploadService; + + /** + * 上传图片 + */ + @PostMapping("/upload/image") + public ApiResponse uploadImage(@RequestParam("file") MultipartFile file) { + return uploadService.uploadImage(file); + } +} diff --git a/src/main/java/com/example/copykamanotes/service/CollectionService.java b/src/main/java/com/example/copykamanotes/service/CollectionService.java index 066f0a8..21fe075 100644 --- a/src/main/java/com/example/copykamanotes/service/CollectionService.java +++ b/src/main/java/com/example/copykamanotes/service/CollectionService.java @@ -13,7 +13,7 @@ import java.util.List; @Transactional public interface CollectionService { - ApiResponse> getCollection(CollectionQueryParams queryParams); + ApiResponse> getCollections(CollectionQueryParams queryParams); ApiResponse createCollection(CreateCollectionBody createCollectionBody); diff --git a/src/main/java/com/example/copykamanotes/service/NoteService.java b/src/main/java/com/example/copykamanotes/service/NoteService.java index 84b0684..334c66e 100644 --- a/src/main/java/com/example/copykamanotes/service/NoteService.java +++ b/src/main/java/com/example/copykamanotes/service/NoteService.java @@ -17,7 +17,7 @@ public interface NoteService { ApiResponse deleteNote(Integer noteId); - ApiResponse downloadNote(Integer noteId); + ApiResponse downloadNote(); ApiResponse> submitNoteRank(); diff --git a/src/main/java/com/example/copykamanotes/service/QuestionListItemService.java b/src/main/java/com/example/copykamanotes/service/QuestionListItemService.java index 8119a27..a09afc7 100644 --- a/src/main/java/com/example/copykamanotes/service/QuestionListItemService.java +++ b/src/main/java/com/example/copykamanotes/service/QuestionListItemService.java @@ -14,7 +14,7 @@ import java.util.List; @Transactional public interface QuestionListItemService { - ApiResponse> useGetQuestionListItemUserVO(QuestionListItemQueryParams questionListItemQueryParams); + ApiResponse> userGetQuestionListItems(QuestionListItemQueryParams questionListItemQueryParams); ApiResponse> getQuestionListItems(Integer questionListId); diff --git a/src/main/java/com/example/copykamanotes/service/QuestionService.java b/src/main/java/com/example/copykamanotes/service/QuestionService.java index 6177074..22cb929 100644 --- a/src/main/java/com/example/copykamanotes/service/QuestionService.java +++ b/src/main/java/com/example/copykamanotes/service/QuestionService.java @@ -35,5 +35,5 @@ public interface QuestionService { ApiResponse userGetQuestion(Integer questionId); - ApiResponse> searchQuestion(SearchQuestionBody body); + ApiResponse> searchQuestions(SearchQuestionBody body); } diff --git a/src/main/java/com/example/copykamanotes/service/SearchService.java b/src/main/java/com/example/copykamanotes/service/SearchService.java index 6f02352..b773cf5 100644 --- a/src/main/java/com/example/copykamanotes/service/SearchService.java +++ b/src/main/java/com/example/copykamanotes/service/SearchService.java @@ -7,7 +7,7 @@ import com.example.copykamanotes.model.entity.User; import java.util.List; public interface SearchService { - ApiResponse> searchNote(String keyword, int page, int pageSize); + ApiResponse> searchNotes(String keyword, int page, int pageSize); ApiResponse> searchUsers(String keyword, int page, int pageSize); diff --git a/src/main/java/com/example/copykamanotes/service/StatisticService.java b/src/main/java/com/example/copykamanotes/service/StatisticService.java index e4e1904..5c01c8e 100644 --- a/src/main/java/com/example/copykamanotes/service/StatisticService.java +++ b/src/main/java/com/example/copykamanotes/service/StatisticService.java @@ -10,5 +10,5 @@ import java.util.List; @Transactional public interface StatisticService { - ApiResponse> getStatistics(StatisticQueryParam queryParam); + ApiResponse> getStatistic(StatisticQueryParam queryParam); } diff --git a/src/main/java/com/example/copykamanotes/service/impl/CollectionServiceImpl.java b/src/main/java/com/example/copykamanotes/service/impl/CollectionServiceImpl.java index 4db98ea..4bd4305 100644 --- a/src/main/java/com/example/copykamanotes/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/example/copykamanotes/service/impl/CollectionServiceImpl.java @@ -36,7 +36,7 @@ public class CollectionServiceImpl implements CollectionService { private final NoteMapper noteMapper; @Override - public ApiResponse> getCollection(CollectionQueryParams queryParams) { + public ApiResponse> getCollections(CollectionQueryParams queryParams) { List collections = collectionMapper.findByCreatorId(queryParams.getCreatorId()); List collectionIds = collections.stream().map(Collection::getCollectionId).toList(); final Set collectionNoteIdCollectionIds; diff --git a/src/main/java/com/example/copykamanotes/service/impl/NoteServiceImpl.java b/src/main/java/com/example/copykamanotes/service/impl/NoteServiceImpl.java index 070fb71..5faead5 100644 --- a/src/main/java/com/example/copykamanotes/service/impl/NoteServiceImpl.java +++ b/src/main/java/com/example/copykamanotes/service/impl/NoteServiceImpl.java @@ -185,7 +185,7 @@ public class NoteServiceImpl implements NoteService { } @Override - public ApiResponse downloadNote(Integer noteId) { + public ApiResponse downloadNote() { Long userId = requestScopeData.getUserId(); List userNotes = noteMapper.findByAuthorId(userId); diff --git a/src/main/java/com/example/copykamanotes/service/impl/QuestionListItemServiceImpl.java b/src/main/java/com/example/copykamanotes/service/impl/QuestionListItemServiceImpl.java index 93fd346..72d7982 100644 --- a/src/main/java/com/example/copykamanotes/service/impl/QuestionListItemServiceImpl.java +++ b/src/main/java/com/example/copykamanotes/service/impl/QuestionListItemServiceImpl.java @@ -39,7 +39,7 @@ public class QuestionListItemServiceImpl implements QuestionListItemService { private final UserMapper userMapper; @Override - public ApiResponse> useGetQuestionListItemUserVO(QuestionListItemQueryParams questionListItemQueryParams) { + public ApiResponse> userGetQuestionListItems(QuestionListItemQueryParams questionListItemQueryParams) { int offset = questionListItemQueryParams.getPage() * questionListItemQueryParams.getPageSize(); int total = questionListItemMapper.countByQuestionListId(questionListItemQueryParams.getQuestionListId()); diff --git a/src/main/java/com/example/copykamanotes/service/impl/QuestionServiceImpl.java b/src/main/java/com/example/copykamanotes/service/impl/QuestionServiceImpl.java index 9c75c75..1fed856 100644 --- a/src/main/java/com/example/copykamanotes/service/impl/QuestionServiceImpl.java +++ b/src/main/java/com/example/copykamanotes/service/impl/QuestionServiceImpl.java @@ -182,7 +182,7 @@ public class QuestionServiceImpl implements QuestionService { } @Override - public ApiResponse> searchQuestion(SearchQuestionBody body) { + public ApiResponse> searchQuestions(SearchQuestionBody body) { String keyword = body.getKeyword(); List questionList = questionMapper.findByKeyword(keyword); diff --git a/src/main/java/com/example/copykamanotes/service/impl/SearchServiceImpl.java b/src/main/java/com/example/copykamanotes/service/impl/SearchServiceImpl.java index 49cc86d..4db65c5 100644 --- a/src/main/java/com/example/copykamanotes/service/impl/SearchServiceImpl.java +++ b/src/main/java/com/example/copykamanotes/service/impl/SearchServiceImpl.java @@ -29,7 +29,7 @@ public class SearchServiceImpl implements SearchService { private static final long CACHE_EXPIRE_TIME = 30; // 分钟 @Override - public ApiResponse> searchNote(String keyword, int page, int pageSize) { + public ApiResponse> searchNotes(String keyword, int page, int pageSize) { try { String cacheKey = String.format(NOTE_SEARCH_CACHE_KEY, keyword, page, pageSize); diff --git a/src/main/java/com/example/copykamanotes/service/impl/StatisticServiceImpl.java b/src/main/java/com/example/copykamanotes/service/impl/StatisticServiceImpl.java index bc984de..1c1df62 100644 --- a/src/main/java/com/example/copykamanotes/service/impl/StatisticServiceImpl.java +++ b/src/main/java/com/example/copykamanotes/service/impl/StatisticServiceImpl.java @@ -20,7 +20,7 @@ public class StatisticServiceImpl implements StatisticService { private final StatisticMapper statisticMapper; @Override - public ApiResponse> getStatistics(StatisticQueryParam queryParam) { + public ApiResponse> getStatistic(StatisticQueryParam queryParam) { Integer page = queryParam.getPage(); Integer pageSize = queryParam.getPageSize(); diff --git a/src/main/java/com/example/copykamanotes/service/impl/UserServiceImpl.java b/src/main/java/com/example/copykamanotes/service/impl/UserServiceImpl.java index 3b3a5a9..9b91976 100644 --- a/src/main/java/com/example/copykamanotes/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/copykamanotes/service/impl/UserServiceImpl.java @@ -47,19 +47,20 @@ public class UserServiceImpl implements UserService { @Override @Transactional(rollbackFor = Exception.class) - public ApiResponse register(RegisterRequest registerRequest) { - User existingUser = userMapper.findByAccount(registerRequest.getAccount()); + public ApiResponse register(RegisterRequest request) { + + // 判断账号 + User existingUser = userMapper.findByAccount(request.getAccount()); if (existingUser != null) { return ApiResponseUtils.error("账号重复"); } - if (registerRequest.getEmail() != null && !registerRequest.getEmail().isEmpty()) { - // 验证邮箱是否重复 - existingUser = userMapper.findByEmail(registerRequest.getEmail()); + // 判断邮箱 + if (request.getEmail() != null && !request.getEmail().isEmpty()) { + existingUser = userMapper.findByEmail(request.getEmail()); if (existingUser != null) { return ApiResponseUtils.error("邮箱重复"); } - // if (registerRequest.getVerifyCode() == null || registerRequest.getVerifyCode().isEmpty()) { // return ApiResponseUtil.error("验证码不能为空"); // } @@ -70,18 +71,15 @@ public class UserServiceImpl implements UserService { } User user = new User(); - BeanUtils.copyProperties(registerRequest, user); - user.setPassword(passwordEncoder.encode(registerRequest.getPassword())); - user.setEmailVerified(registerRequest.getEmail() != null && !registerRequest.getEmail().isEmpty()); + BeanUtils.copyProperties(request, user); + user.setPassword(passwordEncoder.encode(request.getPassword())); +// user.setEmailVerified(request.getEmail() != null && !request.getEmail().isEmpty()); try { userMapper.insert(user); - String token = jwtUtil.generateToken(user.getUserId()); - RegisterVO registerVO = new RegisterVO(); BeanUtils.copyProperties(user, registerVO); - userMapper.updateLastLoginAt(user.getUserId()); return ApiResponseUtils.success("注册成功", registerVO, token); } catch (Exception e) {