feat(service): 新增服务接口和实现类
- 新增 CategoryService、CollectionNoteService、CollectionService、CommentService、MessageService、NoteCommentService、NoteLikeService、QuestionListItemService、QuestionListService、SearchService、StatisticService 服务接口 - 新增 NoteService 接口及其实现类 NoteServiceImpl - 新增 RedisService 接口及其实现类 RedisServiceImpl - 新增 UploadService 接口及其实现
This commit is contained in:
parent
fa92f20aca
commit
e3656d20ec
@ -0,0 +1,27 @@
|
||||
package com.example.copykamanotes.model.dto.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 发布笔记请求DTO
|
||||
*/
|
||||
@Data
|
||||
public class CreateNoteRequest {
|
||||
/*
|
||||
* 问题ID
|
||||
*/
|
||||
@NotNull(message = "问题 ID 不能为空")
|
||||
@Min(value = 1, message = "问题 ID 必须为正整数")
|
||||
private Integer questionId;
|
||||
|
||||
/*
|
||||
* 笔记内容
|
||||
*/
|
||||
@NotBlank(message = "笔记内容不能为空")
|
||||
@NotNull(message = "笔记内容不能为空")
|
||||
private String content;
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package com.example.copykamanotes.model.dto.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class NoteHeatMapItem {
|
||||
private LocalDate data;
|
||||
private Integer count;
|
||||
private Integer rank;
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package com.example.copykamanotes.model.dto.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* 笔记查询参数DTO
|
||||
*/
|
||||
@Data
|
||||
public class NoteQueryParams {
|
||||
/*
|
||||
* 问题ID
|
||||
* 必须是正整数
|
||||
*/
|
||||
@Min(value = 1, message = "问题ID必须是正整数")
|
||||
private Integer questionId;
|
||||
|
||||
/*
|
||||
* 作者ID
|
||||
* 必须是正整数且符合系统生成的范围
|
||||
*/
|
||||
@Min(value = 1, message = "作者ID必须是正整数")
|
||||
private Long authorId;
|
||||
|
||||
/*
|
||||
* 收藏夹ID
|
||||
* 必须是正整数
|
||||
*/
|
||||
@Min(value = 1, message = "收藏夹ID必须是正整数")
|
||||
private Integer collectionId;
|
||||
|
||||
/*
|
||||
* 排序字段
|
||||
* 只能是固定的枚举值(比如 "create", "update")。
|
||||
*/
|
||||
@Pattern(
|
||||
regexp = "create",
|
||||
message = "create"
|
||||
)
|
||||
private String sort;
|
||||
|
||||
/*
|
||||
* 排序方向
|
||||
* 只能是 "asc" 或 "desc",区分大小写。
|
||||
*/
|
||||
@Pattern(
|
||||
regexp = "asc|desc",
|
||||
message = "排序方向必须是 asc 或 desc"
|
||||
)
|
||||
private String order;
|
||||
|
||||
/*
|
||||
* 最近天数
|
||||
* 必须是1到365之间的整数,默认限制为一年内。
|
||||
*/
|
||||
@Min(value = 1, message = "最近天数必须至少为1天")
|
||||
@Max(value = 365, message = "最近天数不能超过365天")
|
||||
private Integer recentDays;
|
||||
|
||||
/*
|
||||
* 当前页码
|
||||
* 必须是正整数,默认为1。
|
||||
*/
|
||||
@NotNull(message = "当前页码不能为空")
|
||||
@Min(value = 1, message = "当前页码必须大于等于1")
|
||||
@Max(value = 10000, message = "当前页码不能超过10,000")
|
||||
private Integer page = 1;
|
||||
|
||||
/*
|
||||
* 每页大小
|
||||
* 必须是正整数,限制范围在 1到100之间。
|
||||
*/
|
||||
@NotNull(message = "每页大小不能为空")
|
||||
@Min(value = 1, message = "每页大小必须大于等于1")
|
||||
@Max(value = 200, message = "每页大小不能超过100")
|
||||
private Integer pageSize = 10;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package com.example.copykamanotes.model.dto.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NoteRankListItem {
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.example.copykamanotes.model.dto.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Top3Count {
|
||||
private Integer lastMonthTop3Count;
|
||||
private Integer thisMonthTop3Count;
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.example.copykamanotes.model.dto.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class UpdateNoteRequest {
|
||||
/*
|
||||
* 笔记内容
|
||||
*/
|
||||
@NotNull(message = "笔记内容不能为空")
|
||||
@NotBlank(message = "笔记内容不能为空")
|
||||
private String content;
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.example.copykamanotes.model.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @ClassName Note
|
||||
* @Description 笔记实体类
|
||||
* @Author Tong
|
||||
* @LastChangeDate 2024-12-16 20:01
|
||||
* @Version v1.0
|
||||
*/
|
||||
@Data
|
||||
public class Note {
|
||||
/**
|
||||
* 笔记ID
|
||||
*/
|
||||
private Integer noteId;
|
||||
|
||||
/**
|
||||
* 作者ID
|
||||
*/
|
||||
private Long authorId;
|
||||
|
||||
/**
|
||||
* 问题ID
|
||||
*/
|
||||
private Integer questionId;
|
||||
|
||||
/**
|
||||
* 笔记内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 点赞数
|
||||
*/
|
||||
private Integer likeCount;
|
||||
|
||||
/**
|
||||
* 评论数
|
||||
*/
|
||||
private Integer commentCount;
|
||||
|
||||
/**
|
||||
* 收藏数
|
||||
*/
|
||||
private Integer collectCount;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.example.copykamanotes.model.vo.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateNoteVO {
|
||||
private Integer noteId;
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
package com.example.copykamanotes.model.vo.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DownloadNoteVO {
|
||||
private String markdown;
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.example.copykamanotes.model.vo.note;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class NoteVO {
|
||||
private Integer noteId;
|
||||
private String content;
|
||||
private Boolean needCollapsed = false;
|
||||
private String displayContent;
|
||||
private Integer likeCount;
|
||||
private Integer commentCount;
|
||||
private Integer collectCount;
|
||||
private LocalDateTime createdAt;
|
||||
private SimpleAuthorVO author;
|
||||
private UserActionsVO userActions;
|
||||
private SimpleQuestionVO question;
|
||||
|
||||
@Data
|
||||
public static class SimpleAuthorVO {
|
||||
private Long userId;
|
||||
private String username;
|
||||
private String avatarUrl;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class UserActionsVO {
|
||||
private Boolean isLiked = false;
|
||||
private Boolean isCollected = false;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SimpleQuestionVO {
|
||||
private Integer questionId;
|
||||
private String title;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface CategoryService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface CollectionNoteService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface CollectionService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface CommentService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface MessageService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface NoteCommentService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface NoteLikeService {
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
import com.example.copykamanotes.model.base.ApiResponse;
|
||||
import com.example.copykamanotes.model.base.EmptyVO;
|
||||
import com.example.copykamanotes.model.dto.note.*;
|
||||
import com.example.copykamanotes.model.vo.note.CreateNoteVO;
|
||||
import com.example.copykamanotes.model.vo.note.DownloadNoteVO;
|
||||
import com.example.copykamanotes.model.vo.note.NoteVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NoteService {
|
||||
ApiResponse<List<NoteVO>> getNotes(NoteQueryParams noteQueryParams);
|
||||
|
||||
ApiResponse<CreateNoteVO> createNote(CreateNoteRequest createNoteRequest);
|
||||
|
||||
ApiResponse<EmptyVO> updateNote(Integer noteId, UpdateNoteRequest updateNoteRequest);
|
||||
|
||||
ApiResponse<EmptyVO> deleteNote(Integer noteId);
|
||||
|
||||
ApiResponse<DownloadNoteVO> downloadNote(Integer noteId);
|
||||
|
||||
ApiResponse<List<NoteRankListItem>> submitNoteRank();
|
||||
|
||||
ApiResponse<List<NoteHeatMapItem>> submitNoteHeatMap();
|
||||
|
||||
ApiResponse<Top3Count> submitNoteTop3Count();
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface QuestionListItemService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface QuestionListService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface QuestionService {
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface RedisService {
|
||||
void set(String key, Object value);
|
||||
|
||||
void setWithExpire(String key, Object value, long expire);
|
||||
|
||||
Object get(String key);
|
||||
|
||||
void delete(String key);
|
||||
|
||||
boolean exists(String key);
|
||||
|
||||
Long increment(String key, long delta);
|
||||
|
||||
Object getHashValue(String hashKey, String key);
|
||||
|
||||
void setHashValue(String hashKey, String key, Object value);
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface SearchService {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
public interface StatisticService {
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.example.copykamanotes.service;
|
||||
|
||||
import com.example.copykamanotes.model.base.ApiResponse;
|
||||
import com.example.copykamanotes.model.vo.upload.ImageVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface UploadService {
|
||||
ApiResponse<ImageVO> uploadImage(MultipartFile file);
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.example.copykamanotes.service.impl;
|
||||
|
||||
import com.example.copykamanotes.model.base.ApiResponse;
|
||||
import com.example.copykamanotes.model.base.EmptyVO;
|
||||
import com.example.copykamanotes.model.dto.note.*;
|
||||
import com.example.copykamanotes.model.vo.note.CreateNoteVO;
|
||||
import com.example.copykamanotes.model.vo.note.DownloadNoteVO;
|
||||
import com.example.copykamanotes.model.vo.note.NoteVO;
|
||||
import com.example.copykamanotes.service.NoteService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class NoteServiceImpl implements NoteService {
|
||||
@Override
|
||||
public ApiResponse<List<NoteVO>> getNotes(NoteQueryParams noteQueryParams) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<CreateNoteVO> createNote(CreateNoteRequest createNoteRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<EmptyVO> updateNote(Integer noteId, UpdateNoteRequest updateNoteRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<EmptyVO> deleteNote(Integer noteId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<DownloadNoteVO> downloadNote(Integer noteId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<NoteRankListItem>> submitNoteRank() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<List<NoteHeatMapItem>> submitNoteHeatMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Top3Count> submitNoteTop3Count() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.example.copykamanotes.service.impl;
|
||||
|
||||
import com.example.copykamanotes.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
public void set(String key, Object value) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWithExpire(String key, Object value, long expire) {
|
||||
redisTemplate.opsForValue().set(key, value, expire);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
return redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String key) {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String key) {
|
||||
return Boolean.TRUE.equals(redisTemplate.hasKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long increment(String key, long delta) {
|
||||
return redisTemplate.opsForValue().increment(key, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHashValue(String hashKey, String key) {
|
||||
return redisTemplate.opsForHash().get(hashKey, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHashValue(String hashKey, String key, Object value) {
|
||||
redisTemplate.opsForHash().put(hashKey, key, value);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.example.copykamanotes.service.impl;
|
||||
|
||||
import com.example.copykamanotes.model.base.ApiResponse;
|
||||
import com.example.copykamanotes.model.vo.upload.ImageVO;
|
||||
import com.example.copykamanotes.service.FileService;
|
||||
import com.example.copykamanotes.service.UploadService;
|
||||
import com.example.copykamanotes.utils.ApiResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
public class UploadServiceImpl implements UploadService {
|
||||
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
|
||||
@Override
|
||||
public ApiResponse<ImageVO> uploadImage(MultipartFile file) {
|
||||
String url = fileService.uploadImage(file);
|
||||
ImageVO imageVO = new ImageVO();
|
||||
imageVO.setUrl(url);
|
||||
return ApiResponseUtil.success("上传成功", imageVO);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user