Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Fix: Clean and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
lyujp committed Aug 11, 2024
1 parent 1e56d92 commit eaef390
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.luijp.escserver.model.dto.ResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.luijp.escserver.Exception;

public class TooManyRequestException extends RuntimeException{
public class TooManyRequestException extends RuntimeException {
public TooManyRequestException() {
super();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/luijp/escserver/config/AuthInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public AuthInterceptor(AuthControllerService authControllerService) {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (request.getMethod().equals("GET")) {
return true;
}else if (request.getMethod().equals("POST")) {
} else if (request.getMethod().equals("POST")) {
Login auth = authControllerService.auth(request);
if (auth == null) {
throw new AuthForbiddenException();
}
return true;
}else{
} else {
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/cn/luijp/escserver/config/CorsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;
import java.util.Objects;

@Configuration
Expand All @@ -17,11 +16,11 @@ public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {

if(Objects.equals(corsDomain, "")){
if (Objects.equals(corsDomain, "")) {
registry.addMapping("/**")
.allowedMethods("GET", "POST")
.allowedHeaders("*");
}else{
} else {
registry.addMapping("/**")
.allowedMethods("GET", "POST")
.allowCredentials(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void image(HttpServletResponse response, @PathVariable String uuid) {
response.reset();
response.setContentType("image/png");
// response.setHeader("Content-Disposition", "attachment; filename=\"" + attachControllerService.getOriginName(uuid) + "\"");
attachControllerService.get(uuid,response);
attachControllerService.get(uuid, response);
}

@GetMapping("/download/{uuid}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ResponseDto<Object> login(@RequestBody Auth auth, HttpServletResponse res
if (clientIp == null || clientIp.isEmpty()) {
clientIp = request.getRemoteAddr();
}
if(!authControllerService.checkRate(clientIp)){
if (!authControllerService.checkRate(clientIp)) {
throw new TooManyRequestException();
}
Login login = authControllerService.login(auth.getUsername(), auth.getPassword());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.luijp.escserver.model.dto.CategoriesAllDto;
import cn.luijp.escserver.model.dto.ResponseDto;
import cn.luijp.escserver.model.entity.Categories;
import cn.luijp.escserver.model.entity.Tags;
import cn.luijp.escserver.model.vo.PostCategoriesWithCategoriesVo;
import cn.luijp.escserver.service.controller.CategoriesControllerService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -35,7 +34,7 @@ public ResponseDto<List<Categories>> getCategoriesList() {
@GetMapping("/alias/{categoryAlias}")
public ResponseDto<Categories> getCategoriesByTagAlias(@PathVariable String categoryAlias) {
Categories categoryIdByAlias = categoriesControllerService.getCategoryIdByAlias(categoryAlias);
if(categoryIdByAlias == null){
if (categoryIdByAlias == null) {
return ResponseDto.error(-404, "Category not exist");
}
return ResponseDto.successWithData(categoryIdByAlias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ public CommentController(CommentControllerService commentControllerService) {

@GetMapping("/list/{postId}/{pageNum}/{pageSize}")
public ResponseDto<CommentListDto> listVisible(@PathVariable Long postId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize,true);
CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize, true);
return ResponseDto.successWithData(comment);
}

@PostMapping("/listUnVisible/{postId}/{pageNum}/{pageSize}")
public ResponseDto<CommentListDto> listUnVisible(@PathVariable Long postId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize,false);
CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize, false);
return ResponseDto.successWithData(comment);
}

@PostMapping("/listAll/{postId}/{pageNum}/{pageSize}")
public ResponseDto<CommentListDto> listAllByPostId(@PathVariable Long postId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize,null);
CommentListDto comment = commentControllerService.getComment(postId, pageNum, pageSize, null);
return ResponseDto.successWithData(comment);
}

@PostMapping("/listAll/{pageNum}/{pageSize}")
public ResponseDto<CommentListDto> listAll(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
CommentListDto comment = commentControllerService.getComment(null, pageNum, pageSize,null);
CommentListDto comment = commentControllerService.getComment(null, pageNum, pageSize, null);
return ResponseDto.successWithData(comment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public LoginFailedController(LoginFailedControllerService loginFailedControllerS
}

@PostMapping("/list")
public ResponseDto<List<LoginFailed>> list(){
public ResponseDto<List<LoginFailed>> list() {
return ResponseDto.successWithData(loginFailedControllerService.getLoginFailed());
}
}
18 changes: 9 additions & 9 deletions src/main/java/cn/luijp/escserver/controller/PostsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ public ResponseDto<Posts> del(@PathVariable Long id) {
}

@GetMapping("/get/{id}")
public ResponseDto<Posts> get(@PathVariable Long id,HttpServletRequest request) {
public ResponseDto<Posts> get(@PathVariable Long id, HttpServletRequest request) {
Posts post = postsControllerService.getPost(id);
if(post == null){
if (post == null) {
return ResponseDto.error(-404, "Post not found");
}
Login auth = authControllerService.auth(request);
if (auth == null) {
if(post.getVisible() != 1){
if (post.getVisible() != 1) {
return ResponseDto.error(-403, "Auth required");
}
if(post.getEncrypt() != null && !post.getEncrypt().isEmpty()){
if (post.getEncrypt() != null && !post.getEncrypt().isEmpty()) {
return ResponseDto.error(-403, "Auth required");
}
}
Expand All @@ -124,18 +124,18 @@ public ResponseDto<Posts> get(@PathVariable Long id,HttpServletRequest request)

@PostMapping("/get/{id}")
public ResponseDto<Posts> getEncrypt(@PathVariable Long id,
@RequestBody String encrypt,
HttpServletRequest request) {
@RequestBody String encrypt,
HttpServletRequest request) {
Posts post = postsControllerService.getPost(id);
if(post == null){
if (post == null) {
return ResponseDto.error(-404, "Post not found");
}
Login auth = authControllerService.auth(request);
if (auth == null) {
if(post.getVisible() != 1){
if (post.getVisible() != 1) {
return ResponseDto.error(-403, "Auth required");
}
if(!Objects.equals(post.getEncrypt(), encrypt)){
if (!Objects.equals(post.getEncrypt(), encrypt)) {
return ResponseDto.error(-403, "Password not match");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.luijp.escserver.controller;

import cn.luijp.escserver.model.dto.ResponseDto;
import cn.luijp.escserver.model.entity.Categories;
import cn.luijp.escserver.model.entity.Tags;
import cn.luijp.escserver.model.vo.PostTagsWithTagsVo;
import cn.luijp.escserver.service.controller.TagsControllerService;
Expand Down Expand Up @@ -34,7 +33,7 @@ public ResponseDto<List<PostTagsWithTagsVo>> getTagsByPostId(@PathVariable Long
@GetMapping("/alias/{tagAlias}")
public ResponseDto<Tags> getTagsByTagAlias(@PathVariable String tagAlias) {
Tags tagIdByAlias = tagsControllerService.getTagIdByAlias(tagAlias);
if(tagIdByAlias == null){
if (tagIdByAlias == null) {
return ResponseDto.error(-404, "Tag not exist");
}
return ResponseDto.successWithData(tagIdByAlias);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package cn.luijp.escserver.mapper;

import cn.luijp.escserver.model.entity.PostCategories;
import cn.luijp.escserver.model.vo.PostCategoriesWithCategoriesVo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PostCategoriesMapper extends MPJBaseMapper<PostCategories> {
}
7 changes: 0 additions & 7 deletions src/main/java/cn/luijp/escserver/mapper/PostTagsMapper.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package cn.luijp.escserver.mapper;

import cn.luijp.escserver.model.entity.PostTags;
import cn.luijp.escserver.model.vo.PostTagsWithTagsVo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PostTagsMapper extends MPJBaseMapper<PostTags> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
@Data
public class CategoriesAllDto {

List<CategoriesAllDto> children;
private Long id;

private String name;

private String alias;

private Long parentId;

List<CategoriesAllDto> children;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public interface AuthControllerService {

Login auth(HttpServletRequest request);

public void recordFailed(String ip);
void recordFailed(String ip);

public Boolean checkRate(String ip);
Boolean checkRate(String ip);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface CategoriesControllerService {

List<PostCategoriesWithCategoriesVo> getCategoriesByPostId(Long postId);

public List<Categories> getCategoriesList();
List<Categories> getCategoriesList();

public Categories getCategoryIdByAlias(String categoryAlias);
Categories getCategoryIdByAlias(String categoryAlias);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cn.luijp.escserver.service.controller;

import cn.luijp.escserver.model.dto.ResponseDto;
import cn.luijp.escserver.model.entity.Categories;
import cn.luijp.escserver.model.entity.Tags;
import cn.luijp.escserver.model.vo.PostTagsWithTagsVo;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

Expand All @@ -20,5 +17,5 @@ public interface TagsControllerService {

List<PostTagsWithTagsVo> getTagsByPostId(Long postId);

public Tags getTagIdByAlias(String tagAlias);
Tags getTagIdByAlias(String tagAlias);
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void recordFailed(String ip) {
public Boolean checkRate(String ip) {
LocalDateTime oneDayBefore = LocalDateTime.now().minus(Duration.ofDays(1));
LambdaQueryWrapper<LoginFailed> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.gt(LoginFailed::getCreateTime,oneDayBefore).eq(LoginFailed::getIp, ip);
queryWrapper.gt(LoginFailed::getCreateTime, oneDayBefore).eq(LoginFailed::getIp, ip);
List<LoginFailed> loginFailedList = loginFailedService.list(queryWrapper);
return loginFailedList.size() < 30;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import cn.luijp.escserver.model.dto.CategoriesAllDto;
import cn.luijp.escserver.model.entity.Categories;
import cn.luijp.escserver.model.entity.PostCategories;
import cn.luijp.escserver.model.entity.PostTags;
import cn.luijp.escserver.model.entity.Tags;
import cn.luijp.escserver.model.vo.PostCategoriesWithCategoriesVo;
import cn.luijp.escserver.model.vo.PostTagsWithTagsVo;
import cn.luijp.escserver.service.controller.CategoriesControllerService;
import cn.luijp.escserver.service.db.ICategoriesService;
import cn.luijp.escserver.service.db.IPostCategoriesService;
Expand Down Expand Up @@ -42,7 +39,7 @@ public CategoriesControllerServiceImpl(ICategoriesService categoriesService,

public List<CategoriesAllDto> getAllCategories() {
List<Categories> list = categoriesService.list();
return getCategories(list,0L);
return getCategories(list, 0L);
}

public List<Categories> getCategoriesList() {
Expand All @@ -51,22 +48,22 @@ public List<Categories> getCategoriesList() {

public Categories getCategoryIdByAlias(String categoryAlias) {
LambdaQueryWrapper<Categories> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Categories::getAlias,categoryAlias);
queryWrapper.eq(Categories::getAlias, categoryAlias);
return categoriesService.getOne(queryWrapper);
}

private List<CategoriesAllDto> getCategories(List<Categories> categoriesList, Long parentId) {
List<CategoriesAllDto> categoriesAllDtoList = new ArrayList<>();
categoriesList.forEach((item)->{
if(Objects.equals(item.getParentId(), parentId)){
CategoriesAllDto categoriesAllDto =new CategoriesAllDto();
categoriesList.forEach((item) -> {
if (Objects.equals(item.getParentId(), parentId)) {
CategoriesAllDto categoriesAllDto = new CategoriesAllDto();
categoriesAllDto.setId(item.getId());
categoriesAllDto.setName(item.getName());
categoriesAllDto.setParentId(item.getParentId());
categoriesAllDto.setAlias(item.getAlias());

categoriesAllDtoList.add(categoriesAllDto);
List<CategoriesAllDto> childCategories = getCategories(categoriesList,item.getId());
List<CategoriesAllDto> childCategories = getCategories(categoriesList, item.getId());
categoriesAllDto.setChildren(childCategories);
}
});
Expand All @@ -83,7 +80,7 @@ public Long updateCategory(Categories category) {
}
try {
boolean status = categoriesService.saveOrUpdate(category);
if(status){
if (status) {
return category.getId();
}
return null;
Expand Down Expand Up @@ -113,12 +110,12 @@ public Boolean delCategory(Long categoryId) {
public List<PostCategoriesWithCategoriesVo> getCategoriesByPostId(Long postId) {
MPJLambdaWrapper<PostCategories> wrapper = JoinWrappers.lambda(PostCategories.class)
.selectAs(PostCategories::getId, PostCategoriesWithCategoriesVo::getPostCategoriesId)
.selectAs(PostCategories::getPostId,PostCategoriesWithCategoriesVo::getPostId)
.selectAs(PostCategories::getCategoryId,PostCategoriesWithCategoriesVo::getCategoryId)
.selectAs(Categories::getName,PostCategoriesWithCategoriesVo::getCategoryName)
.selectAs(Categories::getAlias,PostCategoriesWithCategoriesVo::getCategoryAlias)
.selectAs(PostCategories::getPostId, PostCategoriesWithCategoriesVo::getPostId)
.selectAs(PostCategories::getCategoryId, PostCategoriesWithCategoriesVo::getCategoryId)
.selectAs(Categories::getName, PostCategoriesWithCategoriesVo::getCategoryName)
.selectAs(Categories::getAlias, PostCategoriesWithCategoriesVo::getCategoryAlias)
.leftJoin(Categories.class, Categories::getId, PostCategories::getCategoryId)
.eq(PostCategories::getPostId, postId);
return postCategoriesMapper.selectJoinList(PostCategoriesWithCategoriesVo.class,wrapper);
return postCategoriesMapper.selectJoinList(PostCategoriesWithCategoriesVo.class, wrapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public CommentControllerServiceImpl(ICommentService commentService) {
public Long addComment(Comment comment) {
comment.setVisible(false);
boolean status = commentService.save(comment);
if(status){
if (status) {
return comment.getId();
}else{
} else {
return null;
}
}
Expand All @@ -36,11 +36,11 @@ public Boolean delComment(Long id) {

public CommentListDto getComment(Long postId, Integer pageNum, Integer pageSize, Boolean visible) {
LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
if(postId != null){
if (postId != null) {
queryWrapper.eq(Comment::getPostId, postId);
}
if (visible != null){
queryWrapper.eq(Comment::getVisible,visible);
if (visible != null) {
queryWrapper.eq(Comment::getVisible, visible);
}
Page<Comment> commentPage = commentService.page(new Page<>(pageNum, pageSize), queryWrapper);
CommentListDto commentListDto = new CommentListDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public LoginFailedControllerServiceImpl(ILoginFailedService loginFailedService)
public List<LoginFailed> getLoginFailed() {
LambdaQueryWrapper<LoginFailed> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(LoginFailed::getId);
IPage<LoginFailed> loginFailedPage = loginFailedService.page(new Page<>(1,10),queryWrapper);
IPage<LoginFailed> loginFailedPage = loginFailedService.page(new Page<>(1, 10), queryWrapper);
List<LoginFailed> records = loginFailedPage.getRecords();
if(records.isEmpty()) {
if (records.isEmpty()) {
return null;
}
return records;
Expand Down
Loading

0 comments on commit eaef390

Please sign in to comment.