feat(service): 添加新服务接口和实现类
- 新增 CollectionNoteService、CollectionService、CommentService等多个服务接口 - 实现 CategoryService、NoteLikeService等多个服务类 - 添加事务注解以确保数据一致性- 新增 StatisticQueryParam 类用于统计查询参数
This commit is contained in:
parent
f08aae0f7b
commit
4260b4e028
@ -0,0 +1,18 @@
|
|||||||
|
package com.example.copykamanotes.model.dto.statistic;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StatisticQueryParam {
|
||||||
|
@NotNull(message = "page 不能为空")
|
||||||
|
@Min(value = 1, message = "page 必须为正整数")
|
||||||
|
private Integer page;
|
||||||
|
|
||||||
|
@NotNull(message = "page 不能为空")
|
||||||
|
@Min(value = 1, message = "page 必须为正整数")
|
||||||
|
private Integer pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
@ -6,9 +6,11 @@ import com.example.copykamanotes.model.dto.category.CreateCategoryBody;
|
|||||||
import com.example.copykamanotes.model.dto.category.UpdateCategoryBody;
|
import com.example.copykamanotes.model.dto.category.UpdateCategoryBody;
|
||||||
import com.example.copykamanotes.model.vo.category.CategoryVO;
|
import com.example.copykamanotes.model.vo.category.CategoryVO;
|
||||||
import com.example.copykamanotes.model.vo.category.CreateCategoryVO;
|
import com.example.copykamanotes.model.vo.category.CreateCategoryVO;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface CategoryService {
|
public interface CategoryService {
|
||||||
/**
|
/**
|
||||||
* 构建分类树
|
* 构建分类树
|
||||||
|
|||||||
@ -1,4 +1,11 @@
|
|||||||
package com.example.copykamanotes.service;
|
package com.example.copykamanotes.service;
|
||||||
|
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface CollectionNoteService {
|
public interface CollectionNoteService {
|
||||||
|
Set<Integer> findUserCollectionNoteIds(Long userId, List<Integer> noteIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,24 @@
|
|||||||
package com.example.copykamanotes.service;
|
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.collection.CollectionQueryParams;
|
||||||
|
import com.example.copykamanotes.model.dto.collection.CreateCollectionBody;
|
||||||
|
import com.example.copykamanotes.model.dto.collection.UpdateCollectionBody;
|
||||||
|
import com.example.copykamanotes.model.entity.Collection;
|
||||||
|
import com.example.copykamanotes.model.vo.collection.CollectionVO;
|
||||||
|
import com.example.copykamanotes.model.vo.collection.CreateCollectionVO;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface CollectionService {
|
public interface CollectionService {
|
||||||
|
ApiResponse<List<CollectionVO>> getCollection(CollectionQueryParams queryParams);
|
||||||
|
|
||||||
|
ApiResponse<CreateCollectionVO> createCollection(CreateCollectionBody createCollectionBody);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> deleteCollection(Integer id);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> batchModifyCollection(UpdateCollectionBody updateCollectionBody);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,26 @@
|
|||||||
package com.example.copykamanotes.service;
|
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.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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface CommentService {
|
public interface CommentService {
|
||||||
|
ApiResponse<Integer> createComment(CreateCommentRequest createCommentRequest);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> updateComment(Integer id, UpdateCommentRequest updateCommentRequest);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> deleteComment(Integer id);
|
||||||
|
|
||||||
|
ApiResponse<List<CommentVO>> getComments(CommentQueryParams params);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> likeComment(Integer commentId);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> unlikeComment(Integer commentId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,17 @@
|
|||||||
package com.example.copykamanotes.service;
|
package com.example.copykamanotes.service;
|
||||||
|
|
||||||
|
import com.example.copykamanotes.model.base.ApiResponse;
|
||||||
|
import com.example.copykamanotes.model.base.EmptyVO;
|
||||||
|
import com.example.copykamanotes.model.vo.message.UnreadCountByType;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface MessageService {
|
public interface MessageService {
|
||||||
|
ApiResponse<EmptyVO> deleteMessage(Integer id);
|
||||||
|
|
||||||
|
ApiResponse<Integer> getUnreadMessageCount();
|
||||||
|
|
||||||
|
ApiResponse<List<UnreadCountByType>> getUnreadMessageCountByType();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,16 @@
|
|||||||
package com.example.copykamanotes.service;
|
package com.example.copykamanotes.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.copykamanotes.model.base.ApiResponse;
|
||||||
|
import com.example.copykamanotes.model.base.EmptyVO;
|
||||||
|
import com.example.copykamanotes.model.entity.NoteComment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface NoteCommentService {
|
public interface NoteCommentService {
|
||||||
|
ApiResponse<EmptyVO> createComment(Integer noteId, String content);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> deleteComment(Integer commentId);
|
||||||
|
|
||||||
|
ApiResponse<List<NoteComment>> getComments(Integer noteId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
package com.example.copykamanotes.service;
|
package com.example.copykamanotes.service;
|
||||||
|
|
||||||
|
import com.example.copykamanotes.model.base.ApiResponse;
|
||||||
|
import com.example.copykamanotes.model.base.EmptyVO;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface NoteLikeService {
|
public interface NoteLikeService {
|
||||||
Set<Integer> findUserLikedNoteIds(Long userId, List<Integer> noteIds);
|
Set<Integer> findUserLikedNoteIds(Long userId, List<Integer> noteIds);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> likeNote(Integer noteId);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> unlikeNote(Integer noteId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,25 @@
|
|||||||
package com.example.copykamanotes.service;
|
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.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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface QuestionListItemService {
|
public interface QuestionListItemService {
|
||||||
|
ApiResponse<List<QuestionListItemUserVO>> useGetQuestionListItemUserVO(QuestionListItemQueryParams questionListItemQueryParams);
|
||||||
|
|
||||||
|
ApiResponse<List<QuestionListItemUserVO>> getQuestionListItem(Integer questionListId);
|
||||||
|
|
||||||
|
ApiResponse<CreateQuestionListItemVO> createQuestionListItem(CreateQuestionListItemBody createQuestionListItemBody);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> deleteQuestionListItem(Integer questionListId, Integer questionId);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> sortQuestionListItem(SortQuestionListItemBody body);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,27 @@
|
|||||||
package com.example.copykamanotes.service;
|
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.questionList.CreateQuestionListBody;
|
||||||
|
import com.example.copykamanotes.model.dto.questionList.UpdateQuestionListBody;
|
||||||
|
import com.example.copykamanotes.model.entity.Question;
|
||||||
|
import com.example.copykamanotes.model.entity.QuestionList;
|
||||||
|
import com.example.copykamanotes.model.vo.questionList.CreateQuestionListVO;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface QuestionListService {
|
public interface QuestionListService {
|
||||||
|
|
||||||
|
ApiResponse<QuestionList> getQuestionList(Integer questionListId);
|
||||||
|
|
||||||
|
ApiResponse<List<QuestionList>> getQuestionLists();
|
||||||
|
|
||||||
|
ApiResponse<CreateQuestionListVO> createQuestionList(CreateQuestionListBody body);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> deleteQuestionList(Integer questionListId);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> updateQuestionList(Integer questionListId, UpdateQuestionListBody body);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,38 @@
|
|||||||
package com.example.copykamanotes.service;
|
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.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.entity.Question;
|
import com.example.copykamanotes.model.entity.Question;
|
||||||
|
import com.example.copykamanotes.model.vo.question.CreateQuestionVO;
|
||||||
|
import com.example.copykamanotes.model.vo.question.QuestionNoteVO;
|
||||||
|
import com.example.copykamanotes.model.vo.question.QuestionVO;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface QuestionService {
|
public interface QuestionService {
|
||||||
|
|
||||||
|
Question findById(Integer questionId);
|
||||||
|
|
||||||
Map<Integer, Question> getQuestionMapByIds(List<Integer> questionIds);
|
Map<Integer, Question> getQuestionMapByIds(List<Integer> questionIds);
|
||||||
|
|
||||||
|
ApiResponse<List<QuestionVO>> getQuestions(QuestionQueryParam queryParam);
|
||||||
|
|
||||||
|
ApiResponse<CreateQuestionVO> createQuestion(CreateQuestionBody body);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> updateQuestion(Integer questionId, UpdateQuestionBody body);
|
||||||
|
|
||||||
|
ApiResponse<EmptyVO> deleteQuestion(Integer questionId);
|
||||||
|
|
||||||
|
ApiResponse<List<QuestionVO>> userGetQuestions(QuestionQueryParam queryParam);
|
||||||
|
|
||||||
|
ApiResponse<QuestionNoteVO> userGetQuestion(Integer questionId);
|
||||||
|
|
||||||
|
ApiResponse<List<QuestionVO>> searchQuestion(SearchQuestionBody body);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,15 @@
|
|||||||
package com.example.copykamanotes.service;
|
package com.example.copykamanotes.service;
|
||||||
|
|
||||||
|
import com.example.copykamanotes.model.base.ApiResponse;
|
||||||
|
import com.example.copykamanotes.model.entity.Note;
|
||||||
|
import com.example.copykamanotes.model.entity.User;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface SearchService {
|
public interface SearchService {
|
||||||
|
ApiResponse<List<Note>> searchNote(String keyword, int page, int pageSize);
|
||||||
|
|
||||||
|
ApiResponse<List<User>> searchUsers(String keyword, int page, int pageSize);
|
||||||
|
|
||||||
|
ApiResponse<List<Note>> searchNotesByTag(String keyword, int page, int pageSize);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,14 @@
|
|||||||
package com.example.copykamanotes.service;
|
package com.example.copykamanotes.service;
|
||||||
|
|
||||||
|
import com.example.copykamanotes.model.base.ApiResponse;
|
||||||
|
import com.example.copykamanotes.model.dto.statistic.StatisticQueryParam;
|
||||||
|
import com.example.copykamanotes.model.entity.Statistic;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public interface StatisticService {
|
public interface StatisticService {
|
||||||
|
|
||||||
|
ApiResponse<List<Statistic>> getStatistics(StatisticQueryParam queryParam);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
package com.example.copykamanotes.service.impl;
|
||||||
|
|
||||||
|
import com.example.copykamanotes.mapper.CollectionNoteMapper;
|
||||||
|
import com.example.copykamanotes.service.CollectionNoteService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CollectionNoteServiceImpl implements CollectionNoteService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CollectionNoteMapper collectionNoteMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Integer> findUserCollectionNoteIds(Long userId, List<Integer> noteIds) {
|
||||||
|
List<Integer> userCollectedNoteIds = collectionNoteMapper.findUserCollectedNoteIds(userId, null);
|
||||||
|
return new HashSet<>(userCollectedNoteIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
package com.example.copykamanotes.service.impl;
|
package com.example.copykamanotes.service.impl;
|
||||||
|
|
||||||
import com.example.copykamanotes.mapper.NoteLikeMapper;
|
import com.example.copykamanotes.mapper.NoteLikeMapper;
|
||||||
|
import com.example.copykamanotes.model.base.ApiResponse;
|
||||||
|
import com.example.copykamanotes.model.base.EmptyVO;
|
||||||
import com.example.copykamanotes.service.NoteLikeService;
|
import com.example.copykamanotes.service.NoteLikeService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -10,9 +12,10 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class NoteLikeServiceImpl implements NoteLikeService {
|
public class NoteLikeServiceImpl implements NoteLikeService {
|
||||||
private final NoteLikeMapper noteLikeMapper;
|
|
||||||
|
@Autowired
|
||||||
|
private NoteLikeMapper noteLikeMapper;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,4 +23,14 @@ public class NoteLikeServiceImpl implements NoteLikeService {
|
|||||||
List<Integer> likedIds = noteLikeMapper.findUserLikedNoteIds(userId, noteIds);
|
List<Integer> likedIds = noteLikeMapper.findUserLikedNoteIds(userId, noteIds);
|
||||||
return new HashSet<>(likedIds);
|
return new HashSet<>(likedIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<EmptyVO> likeNote(Integer noteId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<EmptyVO> unlikeNote(Integer noteId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,15 @@
|
|||||||
package com.example.copykamanotes.service.impl;
|
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.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.entity.Question;
|
import com.example.copykamanotes.model.entity.Question;
|
||||||
|
import com.example.copykamanotes.model.vo.question.CreateQuestionVO;
|
||||||
|
import com.example.copykamanotes.model.vo.question.QuestionNoteVO;
|
||||||
|
import com.example.copykamanotes.model.vo.question.QuestionVO;
|
||||||
import com.example.copykamanotes.service.QuestionService;
|
import com.example.copykamanotes.service.QuestionService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -9,7 +18,47 @@ import java.util.Map;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class QuestionServiceImpl implements QuestionService {
|
public class QuestionServiceImpl implements QuestionService {
|
||||||
|
@Override
|
||||||
|
public Question findById(Integer questionId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Integer, Question> getQuestionMapByIds(List<Integer> questionIds) {
|
public Map<Integer, Question> getQuestionMapByIds(List<Integer> questionIds) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<List<QuestionVO>> getQuestions(QuestionQueryParam queryParam) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<CreateQuestionVO> createQuestion(CreateQuestionBody body) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<EmptyVO> updateQuestion(Integer questionId, UpdateQuestionBody body) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<EmptyVO> deleteQuestion(Integer questionId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<List<QuestionVO>> userGetQuestions(QuestionQueryParam queryParam) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<QuestionNoteVO> userGetQuestion(Integer questionId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiResponse<List<QuestionVO>> searchQuestion(SearchQuestionBody body) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user