Compare commits
2 Commits
0244267ab7
...
a3fa04596a
| Author | SHA1 | Date | |
|---|---|---|---|
| a3fa04596a | |||
| 5292366899 |
8
gradlew
vendored
8
gradlew
vendored
@ -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.
|
||||
|
||||
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@ -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
|
||||
|
||||
|
||||
@ -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<List<CategoryVO>> userCategories() {
|
||||
return categoryService.categoryList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类列表(管理员端)。
|
||||
*
|
||||
* @return 包含分类列表的响应。
|
||||
*/
|
||||
@GetMapping("/admin/categories")
|
||||
public ApiResponse<List<CategoryVO>> categories() {
|
||||
return categoryService.categoryList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的分类。
|
||||
*
|
||||
* @param createCategoryBody 包含分类创建信息的请求体。
|
||||
* @return 包含创建成功的分类信息的响应。
|
||||
*/
|
||||
@PostMapping("/admin/categories")
|
||||
public ApiResponse<CreateCategoryVO> createCategory(
|
||||
@Valid @RequestBody CreateCategoryBody createCategoryBody) {
|
||||
return categoryService.createCategory(createCategoryBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指定的分类信息。
|
||||
*
|
||||
* @param categoryId 分类ID,必须为正整数。
|
||||
* @param updateCategoryBody 包含更新信息的请求体。
|
||||
* @return 包含更新操作结果的响应。
|
||||
*/
|
||||
@PatchMapping("/admin/categories/{categoryId}")
|
||||
public ApiResponse<EmptyVO> 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<EmptyVO> deleteCategory(
|
||||
@Min(value = 1, message = "categoryId 必须为正整数") @PathVariable Integer categoryId) {
|
||||
return categoryService.deleteCategory(categoryId);
|
||||
}
|
||||
}
|
||||
@ -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<List<CollectionVO>> getCollections(
|
||||
@Valid
|
||||
CollectionQueryParams queryParams) {
|
||||
return collectionService.getCollections(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建收藏夹接口
|
||||
*
|
||||
* @param requestBody 创建收藏夹请求体
|
||||
* @return 创建结果,如果成功则包含收藏夹 ID
|
||||
*/
|
||||
@PostMapping("/collections")
|
||||
public ApiResponse<CreateCollectionVO> createCollection(
|
||||
@Valid
|
||||
@RequestBody
|
||||
CreateCollectionBody requestBody) {
|
||||
return collectionService.createCollection(requestBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除收藏夹接口
|
||||
*
|
||||
* @param collectionId 收藏夹 ID
|
||||
* @return 返回删除结果
|
||||
*/
|
||||
@DeleteMapping("/collections/{collectionId}")
|
||||
public ApiResponse<EmptyVO> deleteCollection(
|
||||
@PathVariable
|
||||
@Min(value = 1, message = "collectionId 必须为正整数")
|
||||
Integer collectionId) {
|
||||
return collectionService.deleteCollection(collectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改收藏夹接口
|
||||
*
|
||||
* @param collectionBody 收藏夹 ID
|
||||
* @return 返回修改结果
|
||||
*/
|
||||
@PostMapping("/collections/batch")
|
||||
public ApiResponse<EmptyVO> batchModifyCollection(
|
||||
@Valid
|
||||
@RequestBody
|
||||
UpdateCollectionBody collectionBody) {
|
||||
return collectionService.batchModifyCollection(collectionBody);
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
}
|
||||
@ -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<Integer> createComment(
|
||||
@Valid
|
||||
@RequestBody
|
||||
CreateCommentRequest request) {
|
||||
return commentService.createComment(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新评论
|
||||
*
|
||||
* @param commentId 评论ID
|
||||
* @param request 更新评论请求
|
||||
* @return 空响应
|
||||
*/
|
||||
@PatchMapping("/comments/{commentId}")
|
||||
public ApiResponse<EmptyVO> updateComment(
|
||||
@PathVariable("commentId") Integer commentId,
|
||||
@Valid
|
||||
@RequestBody
|
||||
UpdateCommentRequest request) {
|
||||
return commentService.updateComment(commentId, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评论
|
||||
*
|
||||
* @param commentId 评论ID
|
||||
* @return 空响应
|
||||
*/
|
||||
@DeleteMapping("/comments/{commentId}")
|
||||
public ApiResponse<EmptyVO> deleteComment(
|
||||
@PathVariable("commentId") Integer commentId) {
|
||||
return commentService.deleteComment(commentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论列表
|
||||
*
|
||||
* @param params 查询参数
|
||||
* @return 评论列表
|
||||
*/
|
||||
@GetMapping("/comments")
|
||||
public ApiResponse<List<CommentVO>> getComments(
|
||||
@Valid CommentQueryParams params) {
|
||||
return commentService.getComments(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞评论
|
||||
*
|
||||
* @param commentId 评论ID
|
||||
* @return 空响应
|
||||
*/
|
||||
@PostMapping("/comments/{commentId}/like")
|
||||
public ApiResponse<EmptyVO> likeComment(
|
||||
@PathVariable("commentId") Integer commentId) {
|
||||
return commentService.likeComment(commentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消点赞评论
|
||||
*
|
||||
* @param commentId 评论ID
|
||||
* @return 空响应
|
||||
*/
|
||||
@DeleteMapping("/comments/{commentId}/like")
|
||||
public ApiResponse<EmptyVO> unlikeComment(
|
||||
@PathVariable("commentId") Integer commentId) {
|
||||
return commentService.unlikeComment(commentId);
|
||||
}
|
||||
}
|
||||
@ -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<Void> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<PageVO<MessageVO>> getMessages(@Validated MessageQueryParams params) {
|
||||
return messageService.getMessages(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记消息为已读
|
||||
*
|
||||
* @param messageId 消息ID
|
||||
* @return 空响应
|
||||
*/
|
||||
@PutMapping("/{messageId}/read")
|
||||
public ApiResponse<EmptyVO> markAsRead(@PathVariable Integer messageId) {
|
||||
return messageService.markAsRead(messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记所有消息为已读
|
||||
*
|
||||
* @return 空响应
|
||||
*/
|
||||
@PutMapping("/read/all")
|
||||
public ApiResponse<EmptyVO> markAllAsRead() {
|
||||
return messageService.markAllAsRead();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除消息
|
||||
*
|
||||
* @param messageId 消息ID
|
||||
* @return 空响应
|
||||
*/
|
||||
@DeleteMapping("/{messageId}")
|
||||
public ApiResponse<EmptyVO> deleteMessage(@PathVariable Integer messageId) {
|
||||
return messageService.deleteMessage(messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读消息数量
|
||||
*
|
||||
* @return 未读消息数量
|
||||
*/
|
||||
@GetMapping("/unread/count")
|
||||
public ApiResponse<Integer> getUnreadCount() {
|
||||
return messageService.getUnreadCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取各类型未读消息数量
|
||||
*
|
||||
* @return 各类型未读消息数量
|
||||
*/
|
||||
@GetMapping("/unread/count/type")
|
||||
public ApiResponse<List<UnreadCountByType>> getUnreadCountByType() {
|
||||
return messageService.getUnreadCountByType();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
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<List<NoteVO>> getNotes(
|
||||
@Valid NoteQueryParams params) {
|
||||
return noteService.getNotes(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布笔记
|
||||
*
|
||||
* @param request 创建笔记的请求对象,包含笔记的内容等信息
|
||||
* @return 返回一个包含新创建笔记信息的 ApiResponse 对象
|
||||
*/
|
||||
@PostMapping("/notes")
|
||||
public ApiResponse<CreateNoteVO> createNote(
|
||||
@Valid @RequestBody CreateNoteRequest request) {
|
||||
return noteService.createNote(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新笔记
|
||||
*
|
||||
* @param noteId 笔记的唯一标识符,用于定位要更新的笔记
|
||||
* @param request 更新笔记的请求对象,包含需要修改的信息
|
||||
* @return 返回一个包含更新后笔记信息的 ApiResponse 对象
|
||||
*/
|
||||
@PatchMapping("/notes/{noteId}")
|
||||
public ApiResponse<EmptyVO> 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<EmptyVO> deleteNote(
|
||||
@Min(value = 1, message = "noteId 必须为正整数")
|
||||
@PathVariable Integer noteId) {
|
||||
return noteService.deleteNote(noteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载笔记
|
||||
*/
|
||||
@GetMapping("/notes/download")
|
||||
public ApiResponse<DownloadNoteVO> downloadNote() {
|
||||
return noteService.downloadNote();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交笔记排行榜
|
||||
*/
|
||||
@GetMapping("/notes/ranklist")
|
||||
public ApiResponse<List<NoteRankListItem>> submitNoteRank() {
|
||||
return noteService.submitNoteRank();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户提交热力图
|
||||
*/
|
||||
@GetMapping("/notes/heatmap")
|
||||
public ApiResponse<List<NoteHeatMapItem>> submitNoteHeatMap() {
|
||||
return noteService.submitNoteHeatMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户提交 top3 count
|
||||
*/
|
||||
@GetMapping("/notes/top3count")
|
||||
public ApiResponse<Top3Count> submitNoteTop3Count() {
|
||||
return noteService.submitNoteTop3Count();
|
||||
}
|
||||
}
|
||||
@ -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<EmptyVO> likeNote(@PathVariable Integer noteId) {
|
||||
return noteLikeService.likeNote(noteId);
|
||||
}
|
||||
|
||||
@DeleteMapping("/like/note/{noteId}")
|
||||
public ApiResponse<EmptyVO> unlikeNote(@PathVariable Integer noteId) {
|
||||
return noteLikeService.unlikeNote(noteId);
|
||||
}
|
||||
}
|
||||
@ -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<NotificationVO> 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<EmptyVO> setNotifications(@Valid @RequestBody NotificationDTO notificationDTO) {
|
||||
redisService.set("kamanote:notification", notificationDTO.getContent());
|
||||
return ApiResponseUtils.success("设置通知成功");
|
||||
}
|
||||
}
|
||||
@ -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<List<QuestionUserVO>> userGetQuestions(@Valid QuestionQueryParam queryParams) {
|
||||
return questionService.userGetQuestions(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户端搜索问题
|
||||
*
|
||||
* @param body 包含搜索关键词的请求体
|
||||
* @return 包含搜索结果的视图对象列表的响应
|
||||
*/
|
||||
@PostMapping("/questions/search")
|
||||
public ApiResponse<List<QuestionVO>> searchQuestions(@Valid @RequestBody SearchQuestionBody body) {
|
||||
return questionService.searchQuestions(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户端获取单个问题详情
|
||||
*
|
||||
* @param questionId 问题ID,必须为正整数
|
||||
* @return 包含问题详情及关联笔记的视图对象的响应
|
||||
*/
|
||||
@GetMapping("/questions/{questionId}")
|
||||
public ApiResponse<QuestionNoteVO> userGetQuestion(@Min(value = 1, message = "questionId 必须为正整数")
|
||||
@PathVariable Integer questionId) {
|
||||
return questionService.userGetQuestion(questionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端获取问题列表
|
||||
*
|
||||
* @param queryParams 查询参数,用于过滤问题列表(如关键词、时间范围等)
|
||||
* @return 包含所有问题的视图对象列表的响应
|
||||
*/
|
||||
@GetMapping("/admin/questions")
|
||||
public ApiResponse<List<QuestionVO>> getQuestions(@Valid QuestionQueryParam queryParams) {
|
||||
return questionService.getQuestions(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端创建新问题
|
||||
*
|
||||
* @param createQuestionBody 创建问题的请求体,包含问题的标题、内容等信息
|
||||
* @return 包含新创建问题视图对象的响应
|
||||
*/
|
||||
@PostMapping("/admin/questions")
|
||||
public ApiResponse<CreateQuestionVO> createQuestion(@Valid @RequestBody CreateQuestionBody createQuestionBody) {
|
||||
return questionService.createQuestion(createQuestionBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端更新问题
|
||||
*
|
||||
* @param questionId 问题ID,必须为正整数
|
||||
* @param updateQuestionBody 更新问题的请求体,包含要更新的字段和值
|
||||
* @return 空视图对象的响应,表示更新操作成功
|
||||
*/
|
||||
@PatchMapping("/admin/questions/{questionId}")
|
||||
public ApiResponse<EmptyVO> 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<EmptyVO> deleteQuestion(@Min(value = 1, message = "questionId 必须为正整数")
|
||||
@PathVariable Integer questionId) {
|
||||
return questionService.deleteQuestion(questionId);
|
||||
}
|
||||
}
|
||||
@ -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<QuestionList> getQuestionList(@Min(value = 1, message = "questionListId 必须为正整数")
|
||||
@PathVariable Integer questionListId) {
|
||||
return questionListService.getQuestionList(questionListId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取题单列表。
|
||||
*
|
||||
* @return 包含题单列表的响应。
|
||||
*/
|
||||
@GetMapping("/admin/questionlists")
|
||||
public ApiResponse<List<QuestionList>> getQuestionLists() {
|
||||
return questionListService.getQuestionLists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的题单。
|
||||
*
|
||||
* @param body 包含题单创建信息的请求体。
|
||||
* @return 包含创建成功的题单信息的响应。
|
||||
*/
|
||||
@PostMapping("/admin/questionlists")
|
||||
public ApiResponse<CreateQuestionListVO> createQuestionList(@Valid @RequestBody CreateQuestionListBody body) {
|
||||
return questionListService.createQuestionList(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的题单。
|
||||
*
|
||||
* @param questionListId 要删除的题单ID,必须为正整数。
|
||||
* @return 包含删除操作结果的响应。
|
||||
*/
|
||||
@DeleteMapping("/admin/questionlists/{questionListId}")
|
||||
public ApiResponse<EmptyVO> 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<EmptyVO> updateQuestionList(@Min(value = 1, message = "questionListId 必须为正整数")
|
||||
@PathVariable Integer questionListId,
|
||||
@Valid @RequestBody UpdateQuestionListBody body) {
|
||||
return questionListService.updateQuestionList(questionListId, body);
|
||||
}
|
||||
}
|
||||
@ -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<List<QuestionListItemUserVO>> userGetQuestionListItems(
|
||||
@Valid QuestionListItemQueryParams queryParams) {
|
||||
return questionListItemService.userGetQuestionListItems(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定题单中的题单项列表(管理端)。
|
||||
*
|
||||
* @param questionListId 题单ID,可选参数,若提供则获取指定题单的题单项。
|
||||
* @return 包含题单项列表的响应。
|
||||
*/
|
||||
@GetMapping("/admin/questionlist-items/{questionListId}")
|
||||
public ApiResponse<List<QuestionListItemVO>> getQuestionListItems(
|
||||
@Min(value = 1, message = "questionListId 必须为正整数")
|
||||
@PathVariable Integer questionListId) {
|
||||
return questionListItemService.getQuestionListItems(questionListId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的题单项。
|
||||
*
|
||||
* @param body 包含题单项创建信息的请求体。
|
||||
* @return 包含创建成功的题单项信息的响应。
|
||||
*/
|
||||
@PostMapping("/admin/questionlist-items")
|
||||
public ApiResponse<CreateQuestionListItemVO> createQuestionListItem(
|
||||
@Valid
|
||||
@RequestBody
|
||||
CreateQuestionListItemBody body) {
|
||||
return questionListItemService.createQuestionListItem(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的题单项。
|
||||
*
|
||||
* @param questionListId 题单ID,必须为正整数。
|
||||
* @param questionId 题目ID,必须为正整数。
|
||||
* @return 包含删除操作结果的响应。
|
||||
*/
|
||||
@DeleteMapping("/admin/questionlist-items/{questionListId}/{questionId}")
|
||||
public ApiResponse<EmptyVO> 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<EmptyVO> sortQuestionListItem(
|
||||
@Valid
|
||||
@RequestBody
|
||||
SortQuestionListItemBody body) {
|
||||
return questionListItemService.sortQuestionListItem(body);
|
||||
}
|
||||
}
|
||||
@ -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<List<Note>> 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<List<User>> 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<List<Note>> 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);
|
||||
}
|
||||
}
|
||||
@ -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<List<Statistic>> getStatistic(@Valid StatisticQueryParam queryParam) {
|
||||
return statisticService.getStatistic(queryParam);
|
||||
}
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
@ -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<ImageVO> uploadImage(@RequestParam("file") MultipartFile file) {
|
||||
return uploadService.uploadImage(file);
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ import java.util.List;
|
||||
|
||||
@Transactional
|
||||
public interface CollectionService {
|
||||
ApiResponse<List<CollectionVO>> getCollection(CollectionQueryParams queryParams);
|
||||
ApiResponse<List<CollectionVO>> getCollections(CollectionQueryParams queryParams);
|
||||
|
||||
ApiResponse<CreateCollectionVO> createCollection(CreateCollectionBody createCollectionBody);
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ public interface NoteService {
|
||||
|
||||
ApiResponse<EmptyVO> deleteNote(Integer noteId);
|
||||
|
||||
ApiResponse<DownloadNoteVO> downloadNote(Integer noteId);
|
||||
ApiResponse<DownloadNoteVO> downloadNote();
|
||||
|
||||
ApiResponse<List<NoteRankListItem>> submitNoteRank();
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import java.util.List;
|
||||
|
||||
@Transactional
|
||||
public interface QuestionListItemService {
|
||||
ApiResponse<List<QuestionListItemUserVO>> useGetQuestionListItemUserVO(QuestionListItemQueryParams questionListItemQueryParams);
|
||||
ApiResponse<List<QuestionListItemUserVO>> userGetQuestionListItems(QuestionListItemQueryParams questionListItemQueryParams);
|
||||
|
||||
ApiResponse<List<QuestionListItemVO>> getQuestionListItems(Integer questionListId);
|
||||
|
||||
|
||||
@ -35,5 +35,5 @@ public interface QuestionService {
|
||||
|
||||
ApiResponse<QuestionNoteVO> userGetQuestion(Integer questionId);
|
||||
|
||||
ApiResponse<List<QuestionVO>> searchQuestion(SearchQuestionBody body);
|
||||
ApiResponse<List<QuestionVO>> searchQuestions(SearchQuestionBody body);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import com.example.copykamanotes.model.entity.User;
|
||||
import java.util.List;
|
||||
|
||||
public interface SearchService {
|
||||
ApiResponse<List<Note>> searchNote(String keyword, int page, int pageSize);
|
||||
ApiResponse<List<Note>> searchNotes(String keyword, int page, int pageSize);
|
||||
|
||||
ApiResponse<List<User>> searchUsers(String keyword, int page, int pageSize);
|
||||
|
||||
|
||||
@ -10,5 +10,5 @@ import java.util.List;
|
||||
@Transactional
|
||||
public interface StatisticService {
|
||||
|
||||
ApiResponse<List<Statistic>> getStatistics(StatisticQueryParam queryParam);
|
||||
ApiResponse<List<Statistic>> getStatistic(StatisticQueryParam queryParam);
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@ import com.example.copykamanotes.service.CollectionService;
|
||||
import com.example.copykamanotes.utils.ApiResponseUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -36,7 +35,7 @@ public class CollectionServiceImpl implements CollectionService {
|
||||
private final NoteMapper noteMapper;
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<CollectionVO>> getCollection(CollectionQueryParams queryParams) {
|
||||
public ApiResponse<List<CollectionVO>> getCollections(CollectionQueryParams queryParams) {
|
||||
List<Collection> collections = collectionMapper.findByCreatorId(queryParams.getCreatorId());
|
||||
List<Integer> collectionIds = collections.stream().map(Collection::getCollectionId).toList();
|
||||
final Set<Integer> collectionNoteIdCollectionIds;
|
||||
|
||||
@ -185,7 +185,7 @@ public class NoteServiceImpl implements NoteService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<DownloadNoteVO> downloadNote(Integer noteId) {
|
||||
public ApiResponse<DownloadNoteVO> downloadNote() {
|
||||
Long userId = requestScopeData.getUserId();
|
||||
|
||||
List<Note> userNotes = noteMapper.findByAuthorId(userId);
|
||||
|
||||
@ -33,13 +33,13 @@ import java.util.Set;
|
||||
public class QuestionListItemServiceImpl implements QuestionListItemService {
|
||||
|
||||
private final QuestionListItemMapper questionListItemMapper;
|
||||
private final QuestionListMapper questionListMapper;
|
||||
// private final QuestionListMapper questionListMapper;
|
||||
private final RequestScopeData requestScopeData;
|
||||
private final NoteMapper noteMapper;
|
||||
private final UserMapper userMapper;
|
||||
// private final UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<QuestionListItemUserVO>> useGetQuestionListItemUserVO(QuestionListItemQueryParams questionListItemQueryParams) {
|
||||
public ApiResponse<List<QuestionListItemUserVO>> userGetQuestionListItems(QuestionListItemQueryParams questionListItemQueryParams) {
|
||||
|
||||
int offset = questionListItemQueryParams.getPage() * questionListItemQueryParams.getPageSize();
|
||||
int total = questionListItemMapper.countByQuestionListId(questionListItemQueryParams.getQuestionListId());
|
||||
@ -48,7 +48,7 @@ public class QuestionListItemServiceImpl implements QuestionListItemService {
|
||||
|
||||
Integer questionListId = questionListItemQueryParams.getQuestionListId();
|
||||
|
||||
QuestionList questionList = questionListMapper.findById(questionListId);
|
||||
// QuestionList questionList = questionListMapper.findById(questionListId);
|
||||
|
||||
List<QuestionListItemVO> questionListItem = questionListItemMapper.findByQuestionListIdPage(questionListId, questionListItemQueryParams.getPageSize(), offset);
|
||||
List<Integer> questionIds = questionListItem.stream().map(item -> item.getQuestion().getQuestionId()).toList();
|
||||
|
||||
@ -182,7 +182,7 @@ public class QuestionServiceImpl implements QuestionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<QuestionVO>> searchQuestion(SearchQuestionBody body) {
|
||||
public ApiResponse<List<QuestionVO>> searchQuestions(SearchQuestionBody body) {
|
||||
String keyword = body.getKeyword();
|
||||
|
||||
List<Question> questionList = questionMapper.findByKeyword(keyword);
|
||||
|
||||
@ -29,7 +29,7 @@ public class SearchServiceImpl implements SearchService {
|
||||
private static final long CACHE_EXPIRE_TIME = 30; // 分钟
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<Note>> searchNote(String keyword, int page, int pageSize) {
|
||||
public ApiResponse<List<Note>> searchNotes(String keyword, int page, int pageSize) {
|
||||
try {
|
||||
String cacheKey = String.format(NOTE_SEARCH_CACHE_KEY, keyword, page, pageSize);
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ public class StatisticServiceImpl implements StatisticService {
|
||||
private final StatisticMapper statisticMapper;
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<Statistic>> getStatistics(StatisticQueryParam queryParam) {
|
||||
public ApiResponse<List<Statistic>> getStatistic(StatisticQueryParam queryParam) {
|
||||
|
||||
Integer page = queryParam.getPage();
|
||||
Integer pageSize = queryParam.getPageSize();
|
||||
|
||||
@ -43,23 +43,23 @@ public class UserServiceImpl implements UserService {
|
||||
private final JwtUtil jwtUtil;
|
||||
private final RequestScopeData requestScopeData;
|
||||
private final FileService fileService;
|
||||
private final EmailService emailService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiResponse<RegisterVO> register(RegisterRequest registerRequest) {
|
||||
User existingUser = userMapper.findByAccount(registerRequest.getAccount());
|
||||
public ApiResponse<RegisterVO> 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 +70,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) {
|
||||
@ -92,7 +89,7 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public ApiResponse<LoginUserVO> login(LoginRequest loginRequest) {
|
||||
User user = null;
|
||||
User user;
|
||||
|
||||
if (loginRequest.getAccount() != null && !loginRequest.getAccount().isEmpty()) {
|
||||
user = userMapper.findByAccount(loginRequest.getAccount());
|
||||
|
||||
Reference in New Issue
Block a user