parent
627b12f099
commit
2863e90f07
|
@ -10,6 +10,7 @@ public class Result<T> {
|
|||
private Integer code;
|
||||
private String message;
|
||||
private T data;
|
||||
private Long nums;
|
||||
private String time;
|
||||
|
||||
public Result() {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.guwan.backend.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.guwan.backend.Handler.MyMetaObjectHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -20,4 +23,15 @@ public class MybatisPlusConfig {
|
|||
return new MyMetaObjectHandler();
|
||||
}
|
||||
|
||||
//mybatisplus分页流程为:全量查询 =》本地分页
|
||||
// 而如果不对查询结果进行拦截,mybatis将不能执行分页操作,自然也拿不到页数和总数的数据了。
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
//创建拦截器,对执行的sql进行拦截
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
//对Mysql拦截
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,16 +8,13 @@ import java.util.List;
|
|||
public class CacheConstants {
|
||||
|
||||
/**
|
||||
* API接口白名单
|
||||
* 这些路径可以直接访问,不需要认证
|
||||
*
|
||||
* 缓存内容
|
||||
*/
|
||||
public static final List<String> CACHE_LIST = List.of(
|
||||
"userCache"
|
||||
);
|
||||
|
||||
/**
|
||||
* 静态资源白名单
|
||||
* 这些路径用于访问静态资源,不需要认证
|
||||
*/
|
||||
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package com.guwan.backend.controller;
|
||||
|
||||
import com.guwan.backend.common.BusinessException;
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.pojo.entity.BookCategory;
|
||||
import com.guwan.backend.service.BookCategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* (BookCategory)表控制层
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-12-20 17:44:07
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("bookCategory")
|
||||
public class BookCategoryController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
@Autowired
|
||||
private BookCategoryService bookCategoryService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param bookCategory 筛选条件
|
||||
* @param pageRequest 分页对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
@GetMapping
|
||||
public Result<Page<BookCategory>> queryByPage(BookCategory bookCategory, PageRequest pageRequest) {
|
||||
// return Result.success(this.bookCategoryService.queryByPage(bookCategory, pageRequest));
|
||||
|
||||
return Result.success();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 单条数据
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
public Result<BookCategory> queryById(@PathVariable("id") Integer id) {
|
||||
return Result.success(bookCategoryService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param bookCategory 实体
|
||||
* @return 新增结果
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<BookCategory> add(BookCategory bookCategory) {
|
||||
|
||||
if (bookCategoryService.lambdaQuery()
|
||||
.eq(BookCategory::getCategoryName, bookCategory.getCategoryName()).one() != null){
|
||||
throw new BusinessException("该图书种类已经存在");
|
||||
}
|
||||
|
||||
if (bookCategoryService.save(bookCategory)) {
|
||||
return Result.success();
|
||||
}else {
|
||||
return Result.error("保存失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
*
|
||||
* @param bookCategory 实体
|
||||
* @return 编辑结果
|
||||
*/
|
||||
@PutMapping
|
||||
public Result<BookCategory> edit(BookCategory bookCategory) {
|
||||
//return Result.success(this.bookCategoryService.update(bookCategory));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 删除是否成功
|
||||
*/
|
||||
@DeleteMapping
|
||||
public Result<Boolean> deleteById(Integer id) {
|
||||
bookCategoryService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
package com.guwan.backend.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.pojo.entity.ReadingNote;
|
||||
import com.guwan.backend.service.ReadingNoteService;
|
||||
import com.guwan.backend.util.SecurityUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "阅读笔记", description = "阅读笔记相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/reading-notes")
|
||||
@RequiredArgsConstructor
|
||||
public class ReadingNoteController {
|
||||
|
||||
private final ReadingNoteService noteService;
|
||||
private final SecurityUtil securityUtil;
|
||||
|
||||
@Operation(summary = "添加笔记")
|
||||
@PostMapping
|
||||
public Result<ReadingNote> addNote(@RequestBody ReadingNote note) {
|
||||
try {
|
||||
note.setUserId(securityUtil.getCurrentUserId());
|
||||
return Result.success(noteService.addNote(note));
|
||||
} catch (Exception e) {
|
||||
log.error("添加笔记失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "更新笔记")
|
||||
@PutMapping("/{id}")
|
||||
public Result<ReadingNote> updateNote(@PathVariable Long id, @RequestBody ReadingNote note) {
|
||||
try {
|
||||
note.setId(id);
|
||||
note.setUserId(securityUtil.getCurrentUserId());
|
||||
return Result.success(noteService.updateNote(note));
|
||||
} catch (Exception e) {
|
||||
log.error("更新笔记失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除笔记")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deleteNote(@PathVariable Long id) {
|
||||
try {
|
||||
noteService.deleteNote(id);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
log.error("删除笔记失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取笔记详情")
|
||||
@GetMapping("/{id}")
|
||||
public Result<ReadingNote> getNote(@PathVariable Long id) {
|
||||
try {
|
||||
return Result.success(noteService.getNoteById(id));
|
||||
} catch (Exception e) {
|
||||
log.error("获取笔记详情失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户的所有笔记")
|
||||
@GetMapping
|
||||
public Result<IPage<ReadingNote>> getUserNotes(
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
try {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
return Result.success(noteService.getUserNotes(userId, pageNum, pageSize));
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户笔记失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取书籍的所有公开笔记")
|
||||
@GetMapping("/book/{bookId}")
|
||||
public Result<IPage<ReadingNote>> getBookNotes(
|
||||
@PathVariable Long bookId,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
try {
|
||||
return Result.success(noteService.getBookNotes(bookId, pageNum, pageSize));
|
||||
} catch (Exception e) {
|
||||
log.error("获取书籍笔记失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户在特定书籍上的笔记")
|
||||
@GetMapping("/book/{bookId}/my")
|
||||
public Result<IPage<ReadingNote>> getUserBookNotes(
|
||||
@PathVariable Long bookId,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
try {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
return Result.success(noteService.getUserBookNotes(userId, bookId, pageNum, pageSize));
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户书籍笔记失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有公开笔记")
|
||||
@GetMapping("/public")
|
||||
public Result<IPage<ReadingNote>> getPublicNotes(
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
try {
|
||||
return Result.success(noteService.getPublicNotes(pageNum, pageSize));
|
||||
} catch (Exception e) {
|
||||
log.error("获取公开笔记失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package com.guwan.backend.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.pojo.dto.ReadingStatistics;
|
||||
import com.guwan.backend.pojo.entity.ReadingProgress;
|
||||
import com.guwan.backend.service.ReadingProgressService;
|
||||
import com.guwan.backend.util.SecurityUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "阅读进度", description = "阅读进度相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/reading-progress")
|
||||
@RequiredArgsConstructor
|
||||
public class ReadingProgressController {
|
||||
|
||||
private final ReadingProgressService progressService;
|
||||
private final SecurityUtil securityUtil;
|
||||
|
||||
@Operation(summary = "更新阅读进度")
|
||||
@PostMapping
|
||||
public Result<ReadingProgress> updateProgress(@RequestBody ReadingProgress progress) {
|
||||
try {
|
||||
progress.setUserId(securityUtil.getCurrentUserId());
|
||||
return Result.success(progressService.updateProgress(progress));
|
||||
} catch (Exception e) {
|
||||
log.error("更新阅读进度失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取书籍阅读进度")
|
||||
@GetMapping("/book/{bookId}")
|
||||
public Result<ReadingProgress> getProgress(@PathVariable Long bookId) {
|
||||
try {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
return Result.success(progressService.getProgress(userId, bookId));
|
||||
} catch (Exception e) {
|
||||
log.error("获取阅读进度失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户的所有阅读进度")
|
||||
@GetMapping
|
||||
public Result<IPage<ReadingProgress>> getUserProgress(
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
try {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
return Result.success(progressService.getUserProgress(userId, pageNum, pageSize));
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户阅读进度失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取特定状态的书籍")
|
||||
@GetMapping("/status/{status}")
|
||||
public Result<IPage<ReadingProgress>> getProgressByStatus(
|
||||
@PathVariable String status,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
try {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
return Result.success(progressService.getProgressByStatus(userId, status, pageNum, pageSize));
|
||||
} catch (Exception e) {
|
||||
log.error("获取阅读状态失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "更新阅读时长")
|
||||
@PostMapping("/{bookId}/reading-time")
|
||||
public Result<Void> updateReadingTime(
|
||||
@PathVariable Long bookId,
|
||||
@RequestParam Integer minutes) {
|
||||
try {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
progressService.updateReadingTime(userId, bookId, minutes);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
log.error("更新阅读时长失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取阅读统计")
|
||||
@GetMapping("/statistics")
|
||||
public Result<ReadingStatistics> getReadingStatistics() {
|
||||
try {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
return Result.success(progressService.getReadingStatistics(userId));
|
||||
} catch (Exception e) {
|
||||
log.error("获取阅读统计失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.guwan.backend.pojo.entity.BookCategory;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【book_category】的数据库操作Service
|
||||
* @createDate 2024-12-20 17:04:09
|
||||
*/
|
||||
public interface BookCategoryService extends IService<BookCategory> {
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.guwan.backend.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guwan.backend.pojo.entity.BookCategory;
|
||||
import com.guwan.backend.service.BookCategoryService;
|
||||
import com.guwan.backend.mapper.BookCategoryMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【book_category】的数据库操作Service实现
|
||||
* @createDate 2024-12-20 17:04:09
|
||||
*/
|
||||
@Service
|
||||
public class BookCategoryServiceImpl extends ServiceImpl<BookCategoryMapper, BookCategory>
|
||||
implements BookCategoryService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue